mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Stop showing the sliding sync proxy alert to any remaining users.
The session will simply fail to restore and the restoration token deleted.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
@testable import ElementX
|
||||
import KeychainAccess
|
||||
import XCTest
|
||||
|
||||
class KeychainControllerTests: XCTestCase {
|
||||
@@ -33,8 +34,7 @@ class KeychainControllerTests: XCTestCase {
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusherClientID",
|
||||
slidingSyncProxyURLString: "https://my.sync.proxy")
|
||||
pusherNotificationClientIdentifier: "pusherClientID")
|
||||
keychain.setRestorationToken(restorationToken, forUsername: username)
|
||||
|
||||
// Then the restoration token should be stored in the keychain.
|
||||
@@ -53,8 +53,7 @@ class KeychainControllerTests: XCTestCase {
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusherClientID",
|
||||
slidingSyncProxyURLString: "https://my.sync.proxy")
|
||||
pusherNotificationClientIdentifier: "pusherClientID")
|
||||
keychain.setRestorationToken(restorationToken, forUsername: username)
|
||||
XCTAssertEqual(keychain.restorationTokens().count, 1, "The keychain should have 1 restoration token.")
|
||||
XCTAssertEqual(keychain.restorationTokenForUsername(username), restorationToken, "The initial restoration token should match the value that was stored.")
|
||||
@@ -79,8 +78,7 @@ class KeychainControllerTests: XCTestCase {
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusherClientID",
|
||||
slidingSyncProxyURLString: "https://my.sync.proxy")
|
||||
pusherNotificationClientIdentifier: "pusherClientID")
|
||||
keychain.setRestorationToken(restorationToken, forUsername: "@test\(index):example.com")
|
||||
}
|
||||
XCTAssertEqual(keychain.restorationTokens().count, 5, "The keychain should have 5 restoration tokens.")
|
||||
@@ -104,8 +102,7 @@ class KeychainControllerTests: XCTestCase {
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusherClientID",
|
||||
slidingSyncProxyURLString: "https://my.sync.proxy")
|
||||
pusherNotificationClientIdentifier: "pusherClientID")
|
||||
keychain.setRestorationToken(restorationToken, forUsername: "@test\(index):example.com")
|
||||
}
|
||||
XCTAssertEqual(keychain.restorationTokens().count, 5, "The keychain should have 5 restoration tokens.")
|
||||
@@ -122,27 +119,34 @@ 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.")
|
||||
func testUnsupportedRestorationToken() {
|
||||
// Given a keychain with an unsupported restoration token with a sliding sync proxy URL value.
|
||||
let underlyingKeychain = Keychain(service: KeychainControllerService.tests.restorationTokenID,
|
||||
accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)
|
||||
// Note: We assert with this underlying keychain's keys as keychain.restorationTokens() triggers the deletion that we're testing.
|
||||
XCTAssertTrue(underlyingKeychain.allKeys().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",
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusherClientID",
|
||||
slidingSyncProxyURLString: nil)
|
||||
keychain.setRestorationToken(restorationToken, forUsername: username)
|
||||
do {
|
||||
let unsupportedToken = RestorationTokenV1(session: SessionV1(accessToken: "1234",
|
||||
refreshToken: nil,
|
||||
userId: "@test:example.com",
|
||||
deviceId: "D3V1C3",
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: nil,
|
||||
slidingSyncVersion: .proxy(url: "https://sync.example.com")))
|
||||
let tokenData = try JSONEncoder().encode(unsupportedToken)
|
||||
try underlyingKeychain.set(tokenData, key: "@test:example.com")
|
||||
XCTAssertEqual(underlyingKeychain.allKeys().count, 1)
|
||||
} catch {
|
||||
XCTFail("Failed storing user restore token with error: \(error)")
|
||||
}
|
||||
|
||||
// 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.")
|
||||
// When attempting to retrieve the unsupported token.
|
||||
let retrievedToken = keychain.restorationTokenForUsername("@test:example.com")
|
||||
|
||||
// Then nothing should be returned and the restoration token should be automatically removed.
|
||||
XCTAssertNil(retrievedToken, "The token should not be decoded.")
|
||||
XCTAssertTrue(underlyingKeychain.allKeys().isEmpty, "The keychain should be empty again.")
|
||||
}
|
||||
|
||||
func testAddPINCode() throws {
|
||||
|
||||
@@ -11,6 +11,31 @@ import XCTest
|
||||
import MatrixRustSDK
|
||||
|
||||
class RestorationTokenTests: XCTestCase {
|
||||
func testDecodeTokenV1WithSlidingSyncProxy() throws {
|
||||
// Given an encoded restoration token that contains a session with a sliding sync proxy.
|
||||
let originalToken = RestorationTokenV1(session: SessionV1(accessToken: "1234",
|
||||
refreshToken: nil,
|
||||
userId: "@user:example.com",
|
||||
deviceId: "D3V1C3",
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: nil,
|
||||
slidingSyncVersion: .proxy(url: "https://sync.example.com")))
|
||||
let data = try JSONEncoder().encode(originalToken)
|
||||
|
||||
// When decoding the data to the current restoration token format.
|
||||
XCTAssertThrowsError(try JSONDecoder().decode(RestorationToken.self, from: data)) { error in
|
||||
// Then an error should be thrown as it is no longer supported.
|
||||
switch error {
|
||||
case RestorationTokenError.slidingSyncProxyNotSupported:
|
||||
break
|
||||
default:
|
||||
XCTFail("Unexpected error thrown: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Honestly not sure if this test is needed or not – it is quite possible that `RestorationTokenV1` was only encoded at a time
|
||||
/// when the sliding sync proxy was the only option. But lets keep the test for completeness of the session directory migration coverage.
|
||||
func testDecodeFromTokenV1() throws {
|
||||
// Given an encoded restoration token in the original format that only contains a Session from the SDK.
|
||||
let originalToken = RestorationTokenV1(session: SessionV1(accessToken: "1234",
|
||||
@@ -19,7 +44,7 @@ class RestorationTokenTests: XCTestCase {
|
||||
deviceId: "D3V1C3",
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: nil,
|
||||
slidingSyncVersion: .proxy(url: "https://sync.example.com")))
|
||||
slidingSyncVersion: .native))
|
||||
let data = try JSONEncoder().encode(originalToken)
|
||||
|
||||
// When decoding the data to the current restoration token format.
|
||||
@@ -33,10 +58,6 @@ class RestorationTokenTests: XCTestCase {
|
||||
"The session directory should match the original location set by the Rust SDK from our base directory.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, .sessionCachesBaseDirectory.appending(component: "@user_example.com"),
|
||||
"The cache directory should be derived from the session directory but in the caches directory.")
|
||||
|
||||
XCTAssertEqual(decodedToken.slidingSyncProxyURLString, "https://sync.example.com",
|
||||
"The original sliding sync URL should be preserved in order to trigger the migration prompt.")
|
||||
XCTAssertTrue(decodedToken.needsSlidingSyncMigration, "The migration flag should be set to true.")
|
||||
}
|
||||
|
||||
func testDecodeFromTokenV4() throws {
|
||||
@@ -48,7 +69,7 @@ class RestorationTokenTests: XCTestCase {
|
||||
deviceId: "D3V1C3",
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: "data-from-mas",
|
||||
slidingSyncVersion: .proxy(url: "https://sync.example.com")),
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectory: .sessionsBaseDirectory.appending(component: sessionDirectoryName),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusher-identifier")
|
||||
@@ -66,10 +87,6 @@ class RestorationTokenTests: XCTestCase {
|
||||
"The session directory should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, .sessionCachesBaseDirectory.appending(component: sessionDirectoryName),
|
||||
"The cache directory should be derived from the session directory but in the caches directory.")
|
||||
|
||||
XCTAssertEqual(decodedToken.slidingSyncProxyURLString, "https://sync.example.com",
|
||||
"The original sliding sync URL should be preserved in order to trigger the migration prompt.")
|
||||
XCTAssertTrue(decodedToken.needsSlidingSyncMigration, "The migration flag should be set to true.")
|
||||
}
|
||||
|
||||
func testDecodeFromTokenV5() throws {
|
||||
@@ -100,9 +117,6 @@ class RestorationTokenTests: XCTestCase {
|
||||
"The session directory should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, originalToken.cacheDirectory,
|
||||
"The cache directory should not be changed.")
|
||||
|
||||
XCTAssertNil(decodedToken.slidingSyncProxyURLString, "No sliding sync proxy URL should be decoded for native sliding sync.")
|
||||
XCTAssertFalse(decodedToken.needsSlidingSyncMigration, "The migration flag should not be set.")
|
||||
}
|
||||
|
||||
func testDecodeFromCurrentToken() throws {
|
||||
@@ -116,8 +130,7 @@ class RestorationTokenTests: XCTestCase {
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusher-identifier",
|
||||
slidingSyncProxyURLString: nil)
|
||||
pusherNotificationClientIdentifier: "pusher-identifier")
|
||||
let data = try JSONEncoder().encode(originalToken)
|
||||
|
||||
// When decoding the data.
|
||||
|
||||
Reference in New Issue
Block a user