Expose the store passphrase as Data instead of a base64 string.

This commit is contained in:
Stefan Ceriu
2026-09-22 20:20:18 +03:00
parent 18201ac248
commit b1923b418f
11 changed files with 47 additions and 42 deletions
@@ -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)")
}
@@ -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")
@@ -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)
@@ -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)
}