mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Make the SessionDirectories type responsible for cleaning up data. (#3261)
This commit is contained in:
@@ -29,9 +29,9 @@ class RestorationTokenTests: XCTestCase {
|
||||
XCTAssertEqual(decodedToken.session, originalToken.session, "The session should not be changed.")
|
||||
XCTAssertNil(decodedToken.passphrase, "There should not be a passphrase.")
|
||||
XCTAssertNil(decodedToken.pusherNotificationClientIdentifier, "There should not be a push notification client ID.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectory, .sessionsBaseDirectory.appending(component: "@user_example.com"),
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.dataDirectory, .sessionsBaseDirectory.appending(component: "@user_example.com"),
|
||||
"The session directory should match the original location set by the Rust SDK from our base directory.")
|
||||
XCTAssertEqual(decodedToken.cacheDirectory, .cachesBaseDirectory.appending(component: "@user_example.com"),
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, .cachesBaseDirectory.appending(component: "@user_example.com"),
|
||||
"The cache directory should be derived from the session directory but in the caches directory.")
|
||||
}
|
||||
|
||||
@@ -58,14 +58,44 @@ class RestorationTokenTests: XCTestCase {
|
||||
XCTAssertEqual(decodedToken.passphrase, originalToken.passphrase, "The passphrase should not be changed.")
|
||||
XCTAssertEqual(decodedToken.pusherNotificationClientIdentifier, originalToken.pusherNotificationClientIdentifier,
|
||||
"The push notification client identifier should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectory, originalToken.sessionDirectory, "The session directory should not be changed.")
|
||||
XCTAssertEqual(decodedToken.cacheDirectory, .cachesBaseDirectory.appending(component: sessionDirectoryName),
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.dataDirectory, originalToken.sessionDirectory,
|
||||
"The session directory should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, .cachesBaseDirectory.appending(component: sessionDirectoryName),
|
||||
"The cache directory should be derived from the session directory but in the caches directory.")
|
||||
}
|
||||
|
||||
func testDecodeFromTokenV5() throws {
|
||||
// Given an encoded restoration token in the 5th format that contains separate directories for session data and caches.
|
||||
let sessionDirectoryName = UUID().uuidString
|
||||
let originalToken = RestorationTokenV5(session: Session(accessToken: "1234",
|
||||
refreshToken: "5678",
|
||||
userId: "@user:example.com",
|
||||
deviceId: "D3V1C3",
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: "data-from-mas",
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectory: .sessionsBaseDirectory.appending(component: sessionDirectoryName),
|
||||
cacheDirectory: .cachesBaseDirectory.appending(component: sessionDirectoryName),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusher-identifier")
|
||||
let data = try JSONEncoder().encode(originalToken)
|
||||
|
||||
// When decoding the data.
|
||||
let decodedToken = try JSONDecoder().decode(RestorationToken.self, from: data)
|
||||
|
||||
// Then the output should be a valid token.
|
||||
XCTAssertEqual(decodedToken.session, originalToken.session, "The session should not be changed.")
|
||||
XCTAssertEqual(decodedToken.passphrase, originalToken.passphrase, "The passphrase should not be changed.")
|
||||
XCTAssertEqual(decodedToken.pusherNotificationClientIdentifier, originalToken.pusherNotificationClientIdentifier,
|
||||
"The push notification client identifier should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.dataDirectory, originalToken.sessionDirectory,
|
||||
"The session directory should not be changed.")
|
||||
XCTAssertEqual(decodedToken.sessionDirectories.cacheDirectory, originalToken.cacheDirectory,
|
||||
"The cache directory should not be changed.")
|
||||
}
|
||||
|
||||
func testDecodeFromCurrentToken() throws {
|
||||
// Given an encoded restoration token in the current format.
|
||||
let sessionDirectoryName = UUID().uuidString
|
||||
let originalToken = RestorationToken(session: Session(accessToken: "1234",
|
||||
refreshToken: "5678",
|
||||
userId: "@user:example.com",
|
||||
@@ -73,8 +103,7 @@ class RestorationTokenTests: XCTestCase {
|
||||
homeserverUrl: "https://matrix.example.com",
|
||||
oidcData: "data-from-mas",
|
||||
slidingSyncVersion: .native),
|
||||
sessionDirectory: .sessionsBaseDirectory.appending(component: sessionDirectoryName),
|
||||
cacheDirectory: .cachesBaseDirectory.appending(component: sessionDirectoryName),
|
||||
sessionDirectories: .init(),
|
||||
passphrase: "passphrase",
|
||||
pusherNotificationClientIdentifier: "pusher-identifier")
|
||||
let data = try JSONEncoder().encode(originalToken)
|
||||
@@ -97,3 +126,11 @@ struct RestorationTokenV4: Equatable, Codable {
|
||||
let passphrase: String?
|
||||
let pusherNotificationClientIdentifier: String?
|
||||
}
|
||||
|
||||
struct RestorationTokenV5: Equatable, Codable {
|
||||
let session: MatrixRustSDK.Session
|
||||
let sessionDirectory: URL
|
||||
let cacheDirectory: URL
|
||||
let passphrase: String?
|
||||
let pusherNotificationClientIdentifier: String?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user