Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions BitwardenShared/Core/Auth/Services/AuthServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
loginRequestId: "1"
)
XCTAssertEqual(client.requests.last?.body, try tokenRequest.encode())
assertGetConfig()
await assertGetConfig()
}

/// `loginWithDevice(_:email:captchaToken:)` throws an error if there's no cached data.
Expand All @@ -320,6 +320,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
}

/// `loginWithMasterPassword(_:username:captchaToken:)` logs in with the password.
@MainActor
func test_loginWithMasterPassword() async throws { // swiftlint:disable:this function_body_length
// Set up the mock data.
client.results = [
Expand Down Expand Up @@ -389,6 +390,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_

/// `loginWithMasterPassword(_:username:captchaToken:)` logs the user in with the password for
/// a newly created account.
@MainActor
func test_loginWithMasterPassword_isNewAccount() async throws { // swiftlint:disable:this function_body_length
client.results = [
.httpSuccess(testData: .preLoginSuccess),
Expand Down Expand Up @@ -460,6 +462,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
/// `loginWithMasterPassword(_:username:captchaToken:)` logs the user in with the password for
/// a newly created account and sets their autofill account setup progress to complete if
/// autofill is already enabled.
@MainActor
func test_loginWithMasterPassword_isNewAccount_autofillEnabled() async throws {
client.results = [
.httpSuccess(testData: .preLoginSuccess),
Expand All @@ -486,6 +489,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_

/// `loginWithMasterPassword(_:username:captchaToken:)` logs in with the password updates AccountProfile's
/// `.forcePasswordResetReason` value if policy requires user to update password.
@MainActor
func test_loginWithMasterPassword_updatesAccountProfile() async throws {
// Set up the mock data.
client.results = [
Expand Down Expand Up @@ -584,7 +588,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
let unlockMethod = try await subject.loginWithSingleSignOn(code: "super_cool_secret_code", email: "")

XCTAssertEqual(unlockMethod, .deviceKey)
assertGetConfig()
await assertGetConfig()
}

/// `loginWithSingleSignOn(code:email:)` returns the key connector unlock method if the user
Expand All @@ -598,7 +602,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
unlockMethod,
.keyConnector(keyConnectorURL: URL(string: "https://vault.bitwarden.com/key-connector")!)
)
assertGetConfig()
await assertGetConfig()
}

// `loginWithSingleSignOn(code:email:)` returns the master password unlock method if the user
Expand All @@ -618,7 +622,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
unlockMethod,
.masterPassword(account)
)
assertGetConfig()
await assertGetConfig()
}

/// `loginWithSingleSignOn(code:email:)` throws an error if the user doesn't have a master password set.
Expand All @@ -628,7 +632,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
await assertAsyncThrows(error: AuthError.requireSetPassword) {
_ = try await subject.loginWithSingleSignOn(code: "super_cool_secret_code", email: "")
}
assertGetConfig()
await assertGetConfig()
}

/// `loginWithSingleSignOn(code:email:)` returns an account if the vault is still locked after authenticating.
Expand Down Expand Up @@ -679,7 +683,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
)

XCTAssertEqual(unlockMethod, .masterPassword(.fixtureAccountLogin()))
assertGetConfig()
await assertGetConfig()
}

/// `loginWithTwoFactorCode(email:code:method:remember:captchaToken:)` uses the cached request but with two factor
Expand Down Expand Up @@ -754,7 +758,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
)

XCTAssertEqual(unlockMethod, .masterPassword(.fixtureAccountLogin()))
assertGetConfig()
await assertGetConfig()
}

/// `loginWithTwoFactorCode()` returns the device key unlock method if the user uses trusted
Expand Down Expand Up @@ -794,7 +798,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
remember: true
)
XCTAssertEqual(unlockMethod, .deviceKey)
assertGetConfig()
await assertGetConfig()
}

/// `loginWithTwoFactorCode()` returns the key connector unlock method if the user uses key connector.
Expand Down Expand Up @@ -836,7 +840,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
unlockMethod,
.keyConnector(keyConnectorURL: URL(string: "https://vault.bitwarden.com/key-connector")!)
)
assertGetConfig()
await assertGetConfig()
}

/// `requirePasswordChange(email:masterPassword:policy)` returns `false` if there
Expand Down Expand Up @@ -944,6 +948,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
// MARK: Private

/// Asserts that `getConfig` is called with the proper parameters
@MainActor
private func assertGetConfig() {
configService.configMocker.assertUnwrapping { forceRefresh, isPreAuth in
forceRefresh && !isPreAuth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `client(for:)` loads flags into the SDK.
@MainActor
func test_client_loadFlags() async throws {
configService.configMocker.withResult(ServerConfig(
date: Date(year: 2024, month: 2, day: 14, hour: 7, minute: 50, second: 0),
Expand All @@ -123,6 +124,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `client(for:)` loads `enableCipherKeyEncryption` flag as `false` into the SDK.
@MainActor
func test_client_loadFlagsEnableCipherKeyEncryptionFalse() async throws {
configService.configMocker.withResult(ServerConfig(
date: Date(year: 2024, month: 2, day: 14, hour: 7, minute: 50, second: 0),
Expand All @@ -145,6 +147,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `client(for:)` loading flags throws.
@MainActor
func test_client_loadFlagsThrows() async throws {
configService.configMocker.withResult(ServerConfig(
date: Date(year: 2024, month: 2, day: 14, hour: 7, minute: 50, second: 0),
Expand All @@ -166,6 +169,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `client(for:)` does not load flags when config is `nil`.
@MainActor
func test_client_doesNotloadFlags() async throws {
configService.configMocker.withResult(nil)

Expand All @@ -179,6 +183,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `configPublisher` loads flags into the SDK.
@MainActor
func test_configPublisher_loadFlags() async throws {
configService.configSubject.send(
MetaServerConfig(
Expand Down Expand Up @@ -207,6 +212,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `configPublisher` loads flags into the SDK on a already created client.
@MainActor
func test_configPublisher_loadFlagsOverride() async throws {
configService.configMocker.withResult(ServerConfig(
date: Date(year: 2024, month: 2, day: 14, hour: 7, minute: 50, second: 0),
Expand Down Expand Up @@ -251,6 +257,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `configPublisher` does not load flags into the SDK when the config sent is pre authentication.
@MainActor
func test_configPublisher_doesNotloadFlagsWhenIsPreAuth() async throws {
configService.configSubject.send(
MetaServerConfig(
Expand All @@ -273,6 +280,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `configPublisher` does not load flags into the SDK when the config sent doesn't have a user id.
@MainActor
func test_configPublisher_doesNotloadFlagsWhenUserIdIsNil() async throws {
configService.configSubject.send(
MetaServerConfig(
Expand All @@ -295,6 +303,7 @@ final class ClientServiceTests: BitwardenTestCase { // swiftlint:disable:this ty
}

/// `configPublisher` does not load flags into the SDK when the config sent doesn't have a server config.
@MainActor
func test_configPublisher_doesNotloadFlagsWhenServerConfigIsNil() async throws {
configService.configSubject.send(
MetaServerConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation

@testable import BitwardenShared

@MainActor
class MockConfigService: ConfigService {
// MARK: Properties

Expand All @@ -16,6 +17,8 @@ class MockConfigService: ConfigService {
var refreshDebugFeatureFlagsCalled = false
var toggleDebugFeatureFlagCalled = false

nonisolated init() {}

// MARK: Methods

func configPublisher(
Expand Down
8 changes: 7 additions & 1 deletion BitwardenShared/UI/Auth/AuthRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_

/// `handleAndRoute(_ :)` redirects `.didCompleteAuth` to `.landing` and doesn't set the
/// carousel shown flag if the carousel feature flag is off.
@MainActor
func test_handleAndRoute_didCompleteAuth_carouselNotShown() async {
authRepository.activeAccount = .fixture()
configService.featureFlagsBool[.nativeCarouselFlow] = false
Expand All @@ -236,6 +237,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_

/// `handleAndRoute(_ :)` redirects `.didCompleteAuth` to `.landing` and sets the carousel shown
/// flag if the carousel feature flag is on and the carousel hasn't been shown yet.
@MainActor
func test_handleAndRoute_didCompleteAuth_carouselShown() async {
authRepository.activeAccount = .fixture()
configService.featureFlagsBool[.nativeCarouselFlow] = true
Expand Down Expand Up @@ -878,6 +880,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_

/// `handleAndRoute(_ :)` redirects `.didStart` to `.introCarousel` if there's no accounts and
/// the carousel flow is enabled.
@MainActor
func test_handleAndRoute_didStart_carouselFlow() async {
configService.featureFlagsBool[.nativeCarouselFlow] = true

Expand All @@ -888,6 +891,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_

/// `handleAndRoute(_ :)` redirects `.didStart` to `.landing` if there's no accounts, the
/// carousel flow is enabled, but the carousel has already been shown.
@MainActor
func test_handleAndRoute_didStart_carouselFlow_carouselShown() async {
configService.featureFlagsBool[.nativeCarouselFlow] = true
stateService.introCarouselShown = true
Expand All @@ -898,10 +902,11 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_
}

/// `handleAndRoute(_ :)` redirects `.didStart` to `.landing` if it's running in an extension.
@MainActor
func test_handleAndRoute_didStart_carouselFlow_extension() async {
configService.featureFlagsBool[.nativeCarouselFlow] = true

subject = await AuthRouter(
subject = AuthRouter(
isInAppExtension: true,
services: ServiceContainer.withMocks(
authRepository: authRepository,
Expand All @@ -919,6 +924,7 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_

/// `handleAndRoute(_ :)` redirects `.didStart` to `.completeWithNeverUnlockKey` if there's an
/// existing account with never lock enabled and sets the intro carousel as shown.
@MainActor
func test_handleAndRoute_didStart_carouselFlow_existingAccountNeverLock() async {
let account = Account.fixture()
authRepository.activeAccount = .fixture()
Expand Down