diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index b0c4aa654..9eb3f99bb 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -2219,14 +2219,14 @@ nonisolated class ClientFactoryMock: ClientFactoryProtocol, @unchecked Sendable return makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksCallsCount > 0 } private let makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedArgumentsLock = NSLock() - private nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedArguments: (serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: String, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)? - var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedArguments: (serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: String, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)? { + private nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedArguments: (serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)? + var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedArguments: (serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)? { get { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedArgumentsLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedArguments } } set { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedArgumentsLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedArguments = newValue } } } private let makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedInvocationsLock = NSLock() - private nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedInvocations: [(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: String, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)] = [] - var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedInvocations: [(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: String, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)] { + private nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedInvocations: [(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)] = [] + var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedInvocations: [(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks)] { get { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedInvocationsLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedInvocations } } set { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReceivedInvocationsLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReceivedInvocations = newValue } } } @@ -2237,9 +2237,9 @@ nonisolated class ClientFactoryMock: ClientFactoryProtocol, @unchecked Sendable get { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReturnValueLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReturnValue } } set { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksReturnValueLock.withLock { makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksUnderlyingReturnValue = newValue } } } - nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksClosure: ((String, SessionDirectories, String, ClientSessionDelegate, AppSettings, AppHooks) async throws -> ClientProtocol)? + nonisolated(unsafe) var makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksClosure: ((String, SessionDirectories, Data, ClientSessionDelegate, AppSettings, AppHooks) async throws -> ClientProtocol)? - @concurrent func makeAuthenticationClient(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: String, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks) async throws -> ClientProtocol { + @concurrent func makeAuthenticationClient(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks) async throws -> ClientProtocol { if let error = makeAuthenticationClientServerNameOrBaseURLSessionDirectoriesPassphraseClientSessionDelegateAppSettingsAppHooksThrowableError { throw error } @@ -14631,14 +14631,14 @@ nonisolated class UserSessionStoreMock: UserSessionStoreProtocol, @unchecked Sen return userSessionForSessionDirectoriesPassphraseCallsCount > 0 } private let userSessionForSessionDirectoriesPassphraseReceivedArgumentsLock = NSLock() - private nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseUnderlyingReceivedArguments: (client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String)? - var userSessionForSessionDirectoriesPassphraseReceivedArguments: (client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String)? { + private nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseUnderlyingReceivedArguments: (client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data)? + var userSessionForSessionDirectoriesPassphraseReceivedArguments: (client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data)? { get { userSessionForSessionDirectoriesPassphraseReceivedArgumentsLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReceivedArguments } } set { userSessionForSessionDirectoriesPassphraseReceivedArgumentsLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReceivedArguments = newValue } } } private let userSessionForSessionDirectoriesPassphraseReceivedInvocationsLock = NSLock() - private nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseUnderlyingReceivedInvocations: [(client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String)] = [] - var userSessionForSessionDirectoriesPassphraseReceivedInvocations: [(client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String)] { + private nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseUnderlyingReceivedInvocations: [(client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data)] = [] + var userSessionForSessionDirectoriesPassphraseReceivedInvocations: [(client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data)] { get { userSessionForSessionDirectoriesPassphraseReceivedInvocationsLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReceivedInvocations } } set { userSessionForSessionDirectoriesPassphraseReceivedInvocationsLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReceivedInvocations = newValue } } } @@ -14649,9 +14649,9 @@ nonisolated class UserSessionStoreMock: UserSessionStoreProtocol, @unchecked Sen get { userSessionForSessionDirectoriesPassphraseReturnValueLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReturnValue } } set { userSessionForSessionDirectoriesPassphraseReturnValueLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReturnValue = newValue } } } - nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseClosure: ((ClientProtocol, SessionDirectories, String) async -> Result)? + nonisolated(unsafe) var userSessionForSessionDirectoriesPassphraseClosure: ((ClientProtocol, SessionDirectories, Data) async -> Result)? - @concurrent func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String) async -> Result { + @concurrent func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data) async -> Result { userSessionForSessionDirectoriesPassphraseCallsCountLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingCallsCount += 1 } userSessionForSessionDirectoriesPassphraseReceivedArguments = (client: client, sessionDirectories: sessionDirectories, passphrase: passphrase) userSessionForSessionDirectoriesPassphraseReceivedInvocationsLock.withLock { userSessionForSessionDirectoriesPassphraseUnderlyingReceivedInvocations.append((client: client, sessionDirectories: sessionDirectories, passphrase: passphrase)) } diff --git a/ElementX/Sources/Services/Authentication/AuthenticationService.swift b/ElementX/Sources/Services/Authentication/AuthenticationService.swift index 871e44b6b..81ea92bc7 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationService.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationService.swift @@ -13,7 +13,7 @@ import MatrixRustSDK class AuthenticationService: AuthenticationServiceProtocol { private var client: ClientProtocol? private var sessionDirectories: SessionDirectories - private let passphrase: String + private let passphrase: Data private let userSessionStore: UserSessionStoreProtocol private let classicAppManager: ClassicAppManagerProtocol? @@ -40,7 +40,7 @@ class AuthenticationService: AuthenticationServiceProtocol { appSettings: AppSettings, appHooks: AppHooks) { sessionDirectories = .init() - passphrase = encryptionKeyProvider.generateKey().base64EncodedString() + passphrase = encryptionKeyProvider.generateKey() self.userSessionStore = userSessionStore self.classicAppManager = classicAppManager diff --git a/ElementX/Sources/Services/Client/ClientFactory.swift b/ElementX/Sources/Services/Client/ClientFactory.swift index 5b804c3e9..0160aff40 100644 --- a/ElementX/Sources/Services/Client/ClientFactory.swift +++ b/ElementX/Sources/Services/Client/ClientFactory.swift @@ -16,7 +16,7 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { #if IS_MAIN_APP func makeAuthenticationClient(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, - passphrase: String, + passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks) async throws -> ClientProtocol { @@ -28,7 +28,7 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { threadsEnabled: appSettings.threadsEnabled) .enableAutomaticBackPagination(enableAutomaticBackPagination: true) .sqliteStore(config: .init(dataPath: sessionDirectories.dataPath, cachePath: sessionDirectories.cachePath) - .highEntropyPassphrase(passphrase: Data(base64Encoded: passphrase), base64Variant: .padded)) + .highEntropyPassphrase(passphrase: passphrase, base64Variant: .padded)) .serverNameOrHomeserverUrl(serverNameOrUrl: serverNameOrBaseURL) return try await build(builder, for: .authentication, appHooks: appHooks) @@ -67,9 +67,9 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { .enableAutomaticBackPagination(enableAutomaticBackPagination: true) .sqliteStore(config: .init(dataPath: credentials.restorationToken.sessionDirectories.dataPath, cachePath: credentials.restorationToken.sessionDirectories.cachePath) - .highEntropyPassphrase(passphrase: Data(base64Encoded: credentials.restorationToken.passphrase), base64Variant: .padded)) + .highEntropyPassphrase(passphrase: credentials.restorationToken.passphrase, base64Variant: .padded)) .withSearchIndexStore(path: credentials.restorationToken.sessionDirectories.dataPath, - password: credentials.restorationToken.passphrase) + password: credentials.restorationToken.passphrase.base64EncodedString()) .homeserverUrl(url: homeserverURL) return try await build(builder, for: .restoration(credentials.restorationToken.session, .all), appHooks: appHooks) @@ -95,7 +95,7 @@ nonisolated struct ClientFactory: ClientFactoryProtocol { .systemIsMemoryConstrained() .sqliteStore(config: .init(dataPath: credentials.restorationToken.sessionDirectories.dataPath, cachePath: credentials.restorationToken.sessionDirectories.cachePath) - .highEntropyPassphrase(passphrase: Data(base64Encoded: credentials.restorationToken.passphrase), base64Variant: .padded)) + .highEntropyPassphrase(passphrase: credentials.restorationToken.passphrase, base64Variant: .padded)) .homeserverUrl(url: homeserverURL) return try await build(builder, for: .restoration(credentials.restorationToken.session, .one(roomId: roomID)), appHooks: appHooks) diff --git a/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift b/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift index 85d4ae1ee..b539ace42 100644 --- a/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientFactoryProtocol.swift @@ -5,6 +5,7 @@ // Please see LICENSE files in the repository root for full details. // +import Foundation import MatrixRustSDK // sourcery: AutoMockable @@ -14,7 +15,7 @@ nonisolated protocol ClientFactoryProtocol { #if IS_MAIN_APP func makeAuthenticationClient(serverNameOrBaseURL: String, sessionDirectories: SessionDirectories, - passphrase: String, + passphrase: Data, clientSessionDelegate: ClientSessionDelegate, appSettings: AppSettings, appHooks: AppHooks) async throws -> ClientProtocol diff --git a/ElementX/Sources/Services/UserSession/RestorationToken.swift b/ElementX/Sources/Services/UserSession/RestorationToken.swift index 6c4248c38..f41acdd65 100644 --- a/ElementX/Sources/Services/UserSession/RestorationToken.swift +++ b/ElementX/Sources/Services/UserSession/RestorationToken.swift @@ -16,7 +16,7 @@ enum RestorationTokenError: Error { nonisolated struct RestorationToken: Equatable { let session: MatrixRustSDK.Session let sessionDirectories: SessionDirectories - let passphrase: String + let passphrase: Data let pusherNotificationClientIdentifier: String? enum CodingKeys: CodingKey { @@ -42,9 +42,14 @@ nonisolated extension RestorationToken: Codable { SessionDirectories(dataDirectory: dataDirectory) } + let base64Passphrase = try container.decode(String.self, forKey: .passphrase) + guard let passphrase = Data(base64Encoded: base64Passphrase) else { + throw DecodingError.dataCorruptedError(forKey: .passphrase, in: container, debugDescription: "The passphrase isn't valid base64.") + } + self = try .init(session: session, sessionDirectories: sessionDirectories, - passphrase: container.decode(String.self, forKey: .passphrase), + passphrase: passphrase, pusherNotificationClientIdentifier: container.decodeIfPresent(String.self, forKey: .pusherNotificationClientIdentifier)) } @@ -53,7 +58,7 @@ nonisolated extension RestorationToken: Codable { try container.encode(session, forKey: .session) try container.encode(sessionDirectories.dataDirectory, forKey: .sessionDirectory) try container.encode(sessionDirectories.cacheDirectory, forKey: .cacheDirectory) - try container.encode(passphrase, forKey: .passphrase) + try container.encode(passphrase.base64EncodedString(), forKey: .passphrase) try container.encode(pusherNotificationClientIdentifier, forKey: .pusherNotificationClientIdentifier) } } diff --git a/ElementX/Sources/Services/UserSession/UserSessionStore.swift b/ElementX/Sources/Services/UserSession/UserSessionStore.swift index 2f2cd6324..2c75656ad 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStore.swift @@ -73,7 +73,7 @@ class UserSessionStore: UserSessionStoreProtocol { } } - func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String) async -> Result { + func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data) async -> Result { do { let session = try client.session() let userID = try client.userId() diff --git a/ElementX/Sources/Services/UserSession/UserSessionStoreProtocol.swift b/ElementX/Sources/Services/UserSession/UserSessionStoreProtocol.swift index fdf22f75f..1b5d06a70 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStoreProtocol.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStoreProtocol.swift @@ -34,7 +34,7 @@ protocol UserSessionStoreProtocol { func restoreUserSession() async -> Result /// Creates a user session for a new client from the SDK along with the passphrase used for the data stores. - func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: String) async -> Result + func userSession(for client: ClientProtocol, sessionDirectories: SessionDirectories, passphrase: Data) async -> Result /// Logs out of the specified session. func logout(userSession: UserSessionProtocol) diff --git a/UnitTests/Sources/AuthenticationServiceTests.swift b/UnitTests/Sources/AuthenticationServiceTests.swift index a12688feb..271aed79d 100644 --- a/UnitTests/Sources/AuthenticationServiceTests.swift +++ b/UnitTests/Sources/AuthenticationServiceTests.swift @@ -37,8 +37,7 @@ struct AuthenticationServiceTests { case .success: #expect(client.loginUsernamePasswordInitialDeviceNameDeviceIdCallsCount == 1) #expect(userSessionStore.userSessionForSessionDirectoriesPassphraseCallsCount == 1) - #expect(userSessionStore.userSessionForSessionDirectoriesPassphraseReceivedArguments?.passphrase == - encryptionKeyProvider.generateKey().base64EncodedString()) + #expect(userSessionStore.userSessionForSessionDirectoriesPassphraseReceivedArguments?.passphrase == encryptionKeyProvider.generateKey()) case .failure(let error): Issue.record("Unexpected failure: \(error)") } diff --git a/UnitTests/Sources/KeychainControllerTests.swift b/UnitTests/Sources/KeychainControllerTests.swift index 7e2643eec..65fba15e8 100644 --- a/UnitTests/Sources/KeychainControllerTests.swift +++ b/UnitTests/Sources/KeychainControllerTests.swift @@ -36,7 +36,7 @@ struct KeychainControllerTests { oauthData: "oauthData", slidingSyncVersion: .native), sessionDirectories: .init(), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: "pusherClientID") keychain.setRestorationToken(restorationToken, forUsername: username) @@ -56,7 +56,7 @@ struct KeychainControllerTests { oauthData: "oauthData", slidingSyncVersion: .native), sessionDirectories: .init(), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: "pusherClientID") keychain.setRestorationToken(restorationToken, forUsername: username) #expect(keychain.restorationTokens().count == 1, "The keychain should have 1 restoration token.") @@ -82,7 +82,7 @@ struct KeychainControllerTests { oauthData: "oauthData", slidingSyncVersion: .native), sessionDirectories: .init(), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: "pusherClientID") keychain.setRestorationToken(restorationToken, forUsername: "@test\(index):example.com") } @@ -107,7 +107,7 @@ struct KeychainControllerTests { oauthData: "oauthData", slidingSyncVersion: .native), sessionDirectories: .init(), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: "pusherClientID") keychain.setRestorationToken(restorationToken, forUsername: "@test\(index):example.com") } @@ -141,7 +141,7 @@ struct KeychainControllerTests { oidcData: nil, slidingSyncVersion: .proxy(url: "https://sync.example.com")), sessionDirectory: .sessionsBaseDirectory.appending(component: UUID().uuidString), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8).base64EncodedString(), pusherNotificationClientIdentifier: "pusherClientID") let tokenData = try JSONEncoder().encode(unsupportedToken) try underlyingKeychain.set(tokenData, key: "@test:example.com") diff --git a/UnitTests/Sources/RestorationTokenTests.swift b/UnitTests/Sources/RestorationTokenTests.swift index 219e39e1f..c5f2f3d56 100644 --- a/UnitTests/Sources/RestorationTokenTests.swift +++ b/UnitTests/Sources/RestorationTokenTests.swift @@ -23,7 +23,7 @@ struct RestorationTokenTests { oidcData: "data-from-mas", slidingSyncVersion: .proxy(url: "https://sync.example.com")), sessionDirectory: .sessionsBaseDirectory.appending(component: UUID().uuidString), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8).base64EncodedString(), pusherNotificationClientIdentifier: "pusher-identifier") let data = try JSONEncoder().encode(originalToken) @@ -46,7 +46,7 @@ struct RestorationTokenTests { oidcData: "data-from-mas", slidingSyncVersion: .native), sessionDirectory: .sessionsBaseDirectory.appending(component: sessionDirectoryName), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8).base64EncodedString(), pusherNotificationClientIdentifier: "pusher-identifier") let data = try JSONEncoder().encode(originalToken) @@ -55,7 +55,7 @@ struct RestorationTokenTests { // Then the output should be a valid token with the expected store directories. assertEqual(session: decodedToken.session, originalSession: originalToken.session) - #expect(decodedToken.passphrase == originalToken.passphrase, "The passphrase should not be changed.") + #expect(decodedToken.passphrase.base64EncodedString() == originalToken.passphrase, "The passphrase should not be changed.") #expect(decodedToken.pusherNotificationClientIdentifier == originalToken.pusherNotificationClientIdentifier, "The push notification client identifier should not be changed.") #expect(decodedToken.sessionDirectories.dataDirectory == originalToken.sessionDirectory, @@ -77,7 +77,7 @@ struct RestorationTokenTests { slidingSyncVersion: .native), sessionDirectory: .sessionsBaseDirectory.appending(component: sessionDirectoryName), cacheDirectory: .sessionCachesBaseDirectory.appending(component: sessionDirectoryName), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8).base64EncodedString(), pusherNotificationClientIdentifier: "pusher-identifier") let data = try JSONEncoder().encode(originalToken) @@ -86,7 +86,7 @@ struct RestorationTokenTests { // Then the output should be a valid token. assertEqual(session: decodedToken.session, originalSession: originalToken.session) - #expect(decodedToken.passphrase == originalToken.passphrase, "The passphrase should not be changed.") + #expect(decodedToken.passphrase.base64EncodedString() == originalToken.passphrase, "The passphrase should not be changed.") #expect(decodedToken.pusherNotificationClientIdentifier == originalToken.pusherNotificationClientIdentifier, "The push notification client identifier should not be changed.") #expect(decodedToken.sessionDirectories.dataDirectory == originalToken.sessionDirectory, @@ -106,7 +106,7 @@ struct RestorationTokenTests { oauthData: "data-from-mas", slidingSyncVersion: .native), sessionDirectories: .init(), - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: "pusher-identifier") let data = try JSONEncoder().encode(originalToken) diff --git a/UnitTests/Sources/UserSessionStoreTests.swift b/UnitTests/Sources/UserSessionStoreTests.swift index 3d9248c3f..a972fd74f 100644 --- a/UnitTests/Sources/UserSessionStoreTests.swift +++ b/UnitTests/Sources/UserSessionStoreTests.swift @@ -114,7 +114,7 @@ struct UserSessionStoreTests { let sessionDirectories = SessionDirectories() // When creating a user session for it. - guard case .success(let userSession) = await store.userSession(for: client, sessionDirectories: sessionDirectories, passphrase: "passphrase") else { + guard case .success(let userSession) = await store.userSession(for: client, sessionDirectories: sessionDirectories, passphrase: Data("passphrase".utf8)) else { Issue.record("Creating the session should succeed.") return } @@ -122,7 +122,7 @@ struct UserSessionStoreTests { // Then the session should be built and its restoration token persisted. #expect(userSession.clientProxy.userID == "@alice:matrix.org") #expect(keychainController.setRestorationTokenForUsernameReceivedArguments?.forUsername == "@alice:matrix.org") - #expect(keychainController.setRestorationTokenForUsernameReceivedArguments?.restorationToken.passphrase == "passphrase") + #expect(keychainController.setRestorationTokenForUsernameReceivedArguments?.restorationToken.passphrase == Data("passphrase".utf8)) } @Test @@ -132,7 +132,7 @@ struct UserSessionStoreTests { client.sessionThrowableError = TestError.generic // When creating a user session for it. - guard case .failure(.failedSettingUpSession) = await store.userSession(for: client, sessionDirectories: .init(), passphrase: "passphrase") else { + guard case .failure(.failedSettingUpSession) = await store.userSession(for: client, sessionDirectories: .init(), passphrase: Data("passphrase".utf8)) else { Issue.record("Creating the session should fail.") return } @@ -177,7 +177,7 @@ struct UserSessionStoreTests { slidingSyncVersion: .native) let restorationToken = RestorationToken(session: session, sessionDirectories: sessionDirectories, - passphrase: "passphrase", + passphrase: Data("passphrase".utf8), pusherNotificationClientIdentifier: nil) return KeychainCredentials(userID: userID, restorationToken: restorationToken) }