mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add an AccountProvider type and use it within the authentication flow. (#6103)
* Add an AccountProvider type and use it within AppSettings. * Use the AccountProvider type within the Authentication flow too. * Fix unit test compilation with Swift 6.4 * Make sure defaultAccountProvider takes allowOtherAccountProviders into account. * Document a caveat on using AuthenticationService.homeserver.value.accountProvider.
This commit is contained in:
@@ -21,7 +21,7 @@ struct AuthenticationServiceTests {
|
||||
|
||||
@Test
|
||||
mutating func passwordLogin() async throws {
|
||||
try await setup(serverAddress: "example.com")
|
||||
try await setup(serverNameOrBaseURL: "example.com")
|
||||
|
||||
switch await service.configure(for: "example.com", flow: .login) {
|
||||
case .success:
|
||||
@@ -65,21 +65,20 @@ struct AuthenticationServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MainActor
|
||||
mutating func configureRegisterNoSupport() async throws {
|
||||
let homeserverAddress = "example.com"
|
||||
try await setup(serverAddress: homeserverAddress)
|
||||
let serverNameOrBaseURL = "example.com"
|
||||
try await setup(serverNameOrBaseURL: serverNameOrBaseURL)
|
||||
|
||||
try await #require(throws: AuthenticationServiceError.registrationNotSupported) {
|
||||
try await service.configure(for: homeserverAddress, flow: .register).get()
|
||||
try await service.configure(for: serverNameOrBaseURL, flow: .register).get()
|
||||
}
|
||||
|
||||
#expect(service.flow == .login)
|
||||
#expect(service.homeserver.value == .init(address: "matrix.org", loginMode: .unknown))
|
||||
#expect(service.homeserver.value == .init(accountProvider: .managed(serverName: "matrix.org", baseURL: "https://matrix-client.matrix.org"),
|
||||
loginMode: .unknown))
|
||||
}
|
||||
|
||||
@Test
|
||||
@MainActor
|
||||
mutating func classicAppAccountSecretsBundleIsUsed() async throws {
|
||||
// Given an authentication service with an Element Classic account for Alice.
|
||||
try await setup(classicAppAccounts: [.mockAlice])
|
||||
@@ -96,7 +95,6 @@ struct AuthenticationServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MainActor
|
||||
mutating func classicAppAccountSecretsBundleIsIgnoredWhenUnavailable() async throws {
|
||||
// Given an authentication service with an Element Classic account for Alice
|
||||
// which isn't configured with any available secrets.
|
||||
@@ -114,7 +112,6 @@ struct AuthenticationServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MainActor
|
||||
mutating func classicAppAccountSecretsBundleIsIgnoredForDifferentUser() async throws {
|
||||
// Given an authentication service with an Element Classic account for Dan.
|
||||
try await setup(classicAppAccounts: [.mockDan])
|
||||
@@ -132,13 +129,13 @@ struct AuthenticationServiceTests {
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private mutating func setup(serverAddress: String = "matrix.org",
|
||||
private mutating func setup(serverNameOrBaseURL: String = "matrix.org",
|
||||
classicAppAccounts: [ClassicAppAccount] = [],
|
||||
availableSecrets: ClassicAppAccount.AvailableSecrets = .complete) async throws {
|
||||
let configuration: ClientFactoryMock.Configuration = .init()
|
||||
let clientFactory = ClientFactoryMock(configuration)
|
||||
|
||||
client = configuration.homeserverClients[serverAddress]
|
||||
client = configuration.homeserverClients[serverNameOrBaseURL]
|
||||
encryption = EncryptionSDKMock()
|
||||
client.encryptionReturnValue = encryption
|
||||
|
||||
|
||||
Reference in New Issue
Block a user