Skip to content

Commit

Permalink
write a test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Aug 21, 2024
1 parent da823d9 commit 1448cfb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
17 changes: 8 additions & 9 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,21 +609,20 @@ public final class Client {
throw ClientError.noV3Client("Error: No V3 client initialized")
}

if let signatureRequest = try await client.revokeAllOtherInstallations() {
do {
let signedData = try await signingKey.sign(message: signatureRequest.signatureText())
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
try await client.registerIdentity(signatureRequest: signatureRequest)
} catch {
throw ClientError.creationError("Failed to sign the message: \(error.localizedDescription)")
}
let signatureRequest = try await client.revokeAllOtherInstallations()
do {
let signedData = try await signingKey.sign(message: signatureRequest.signatureText())
signatureRequest.
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
} catch {
throw ClientError.creationError("Failed to sign the message: \(error.localizedDescription)")
}
}

public func inboxState(refreshFromNetwork: Bool) async throws -> InboxState {
guard let client = v3Client else {
throw ClientError.noV3Client("Error: No V3 client initialized")
}
return InboxState(ffiInboxState: client.inboxState(refreshFromNetwork: refreshFromNetwork))
return InboxState(ffiInboxState: try await client.inboxState(refreshFromNetwork: refreshFromNetwork))
}
}
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Mls/InboxState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct InboxState {
}

public var installationIds: [String] {
ffiInboxState.installationIds.map { id in id.toHex}
ffiInboxState.installationIds.map { $0.toHex }
}

public var recoveryAddress: String {
Expand Down
37 changes: 37 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,41 @@ class ClientTests: XCTestCase {

XCTAssertEqual(inboxId, alixClient.inboxID)
}

func testRevokesAllOtherInstallations() async throws {
let key = try Crypto.secureRandomBytes(count: 32)
let alix = try PrivateKey.generate()
let options = ClientOptions.init(
api: .init(env: .local, isSecure: false),
enableV3: true,
encryptionKey: key
)

let alixClient = try await Client.create(
account: alix,
options: options
)
try alixClient.dropLocalDatabaseConnection()
try alixClient.deleteLocalDatabase()

let alixClient2 = try await Client.create(
account: alix,
options: options
)
try alixClient2.dropLocalDatabaseConnection()
try alixClient2.deleteLocalDatabase()

let alixClient3 = try await Client.create(
account: alix,
options: options
)

let state = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(state.installationIds.count, 3)

try await alixClient3.revokeAllOtherInstallations(signingKey: alix)

let newState = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(newState.installationIds.count, 1)
}
}

0 comments on commit 1448cfb

Please sign in to comment.