import XCTest @testable import MultiSimAdmin final class FileCredentialStoreTests: XCTestCase { func testSavesReadsAndRemovesPasswordInSandboxFile() throws { let location = FileManager.default.temporaryDirectory .appendingPathComponent("credential-store-\(UUID().uuidString).json") let store = FileCredentialStore(location: location) let instanceID = UUID() XCTAssertNil(try store.get(instanceID: instanceID)) try store.set(instanceID: instanceID, password: "sandbox-secret") XCTAssertEqual(try store.get(instanceID: instanceID), "sandbox-secret") XCTAssertTrue(FileManager.default.fileExists(atPath: location.path)) try store.remove(instanceID: instanceID) XCTAssertNil(try store.get(instanceID: instanceID)) } func testCredentialFileIsPrivate() throws { let location = FileManager.default.temporaryDirectory .appendingPathComponent("credential-store-\(UUID().uuidString).json") let store = FileCredentialStore(location: location) try store.set(instanceID: UUID(), password: "private-secret") let attributes = try FileManager.default.attributesOfItem(atPath: location.path) XCTAssertEqual(attributes[.posixPermissions] as? Int, 0o600) } }