Fix the restoration of a SSS session. (#3081)

This commit is contained in:
Doug 2024-07-24 10:55:40 +01:00 committed by GitHub
parent bf22250b45
commit 013240e9b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -47,7 +47,8 @@ extension MatrixRustSDK.Session: Codable {
deviceId: container.decode(String.self, forKey: .deviceId),
homeserverUrl: container.decode(String.self, forKey: .homeserverUrl),
oidcData: container.decodeIfPresent(String.self, forKey: .oidcData),
slidingSyncProxy: container.decode(String.self, forKey: .slidingSyncProxy))
// Note: the proxy is optional now that we support Simplified Sliding Sync.
slidingSyncProxy: container.decodeIfPresent(String.self, forKey: .slidingSyncProxy))
}
public func encode(to encoder: Encoder) throws {

View File

@ -127,6 +127,28 @@ class KeychainControllerTests: XCTestCase {
XCTAssertNotNil(keychain.restorationTokenForUsername("@test4:example.com"), "The restoration token should not have been deleted.")
}
func testSimplifiedSlidingSyncRestorationToken() {
// Given an empty keychain.
XCTAssertTrue(keychain.restorationTokens().isEmpty, "The keychain should be empty to begin with.")
// When adding an restoration token that doesn't contain a sliding sync proxy (e.g. for SSS).
let username = "@test:example.com"
let restorationToken = RestorationToken(session: .init(accessToken: "accessToken",
refreshToken: "refreshToken",
userId: "userId",
deviceId: "deviceId",
homeserverUrl: "homeserverUrl",
oidcData: "oidcData",
slidingSyncProxy: nil),
sessionDirectory: .homeDirectory.appending(component: UUID().uuidString),
passphrase: "passphrase",
pusherNotificationClientIdentifier: "pusherClientID")
keychain.setRestorationToken(restorationToken, forUsername: username)
// Then decoding the restoration token from the keychain should still work.
XCTAssertEqual(keychain.restorationTokenForUsername(username), restorationToken, "The retrieved restoration token should match the value that was stored.")
}
func testAddPINCode() throws {
// Given a keychain without a PIN code set.
try XCTAssertFalse(keychain.containsPINCode(), "A new keychain shouldn't contain a PIN code.")