From b70885fc2745ff9bfafbec66db5757ea7a62965a Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Mon, 16 Dec 2024 11:47:51 -0600 Subject: [PATCH 1/9] Update casing for EnvironmentURLData --- .../Core/Auth/Models/Enum/RegionType.swift | 2 +- .../Repositories/AuthRepositoryTests.swift | 16 ++-- .../Core/Auth/Services/AuthServiceTests.swift | 22 ++--- .../Core/Platform/Models/Domain/Account.swift | 4 +- ...UrlData.swift => EnvironmentURLData.swift} | 16 ++-- ...ts.swift => EnvironmentURLDataTests.swift} | 82 +++++++++---------- .../Models/Domain/EnvironmentUrls.swift | 6 +- .../Models/Domain/EnvironmentUrlsTests.swift | 16 ++-- .../Domain/Fixtures/Account+Fixtures.swift | 4 +- .../EnvironmentUrlData+Fixtures.swift | 6 +- .../Services/EnvironmentService.swift | 14 ++-- .../Services/EnvironmentServiceTests.swift | 12 +-- .../Core/Platform/Services/StateService.swift | 22 ++--- .../Platform/Services/StateServiceTests.swift | 10 +-- .../Services/Stores/AppSettingsStore.swift | 12 +-- .../Stores/AppSettingsStoreTests.swift | 8 +- .../TestHelpers/MockAppSettingsStore.swift | 8 +- .../TestHelpers/MockEnvironmentService.swift | 8 +- .../TestHelpers/MockStateService.swift | 18 ++-- BitwardenShared/UI/Auth/AuthCoordinator.swift | 4 +- .../UI/Auth/AuthCoordinatorTests.swift | 6 +- .../UI/Auth/Landing/LandingProcessor.swift | 4 +- .../Auth/Landing/LandingProcessorTests.swift | 16 ++-- .../SelfHosted/SelfHostedProcessor.swift | 4 +- .../SelfHosted/SelfHostedProcessorTests.swift | 8 +- .../StartRegistrationProcessor.swift | 4 +- .../StartRegistrationProcessorTests.swift | 8 +- .../UI/Auth/Utilities/RegionHelper.swift | 6 +- .../UI/Auth/Utilities/RegionHelperTests.swift | 8 +- 29 files changed, 177 insertions(+), 177 deletions(-) rename BitwardenShared/Core/Platform/Models/Domain/{EnvironmentUrlData.swift => EnvironmentURLData.swift} (92%) rename BitwardenShared/Core/Platform/Models/Domain/{EnvironmentUrlDataTests.swift => EnvironmentURLDataTests.swift} (79%) diff --git a/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift b/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift index 09ebfebcf..a996ccbb4 100644 --- a/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift +++ b/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift @@ -30,7 +30,7 @@ public enum RegionType: CaseIterable, Sendable { } /// The default URLs for the region. - var defaultURLs: EnvironmentUrlData? { + var defaultURLs: EnvironmentURLData? { switch self { case .europe: return .defaultEU diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift index b5e308c43..4c553fc3f 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift @@ -294,7 +294,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` returns the user ID of the existing account with the same /// email and base URLs. func test_existingAccountUserId() async throws { - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentUrls["1"] = .defaultUS stateService.isAuthenticated["1"] = true @@ -307,7 +307,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` returns `nil` if getting the environment URLs throws an error. func test_existingAccountUserId_getEnvironmentUrlsError() async throws { - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentUrlsError = StateServiceError.noAccounts stateService.isAuthenticated["1"] = true @@ -320,7 +320,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` logs an error if determining whether an account is authenticated fails. func test_existingAccountUserId_isAuthenticatedError() async throws { - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentUrls["1"] = .defaultUS stateService.isAuthenticatedError = BitwardenTestError.example @@ -335,7 +335,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` returns `nil` if there's an existing account with the same /// email but the base URLs are different. func test_existingAccountUserId_matchingAccountDifferentBaseUrl() async throws { - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultEU.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentUrls["1"] = .defaultUS stateService.isAuthenticated["1"] = true @@ -356,11 +356,11 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo stateService.isAuthenticated["2"] = true stateService.userIds = ["1", "2"] - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) var userId = await subject.existingAccountUserId(email: "user@bitwarden.com") XCTAssertEqual(userId, "1") - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultEU.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base) userId = await subject.existingAccountUserId(email: "user@bitwarden.com") XCTAssertEqual(userId, "2") } @@ -368,7 +368,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` returns `nil` if there's an existing matching account, but /// the user isn't authenticated. func test_existingAccountUserId_notAuthenticated() async throws { - environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base) + environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentUrls["1"] = .defaultUS stateService.isAuthenticated["1"] = false @@ -1573,7 +1573,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `setActiveAccount(userId: )` loads the environment URLs for the active account. func test_setActiveAccount_loadsEnvironmentUrls() async throws { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) let account = Account.fixture(settings: .fixture(environmentUrls: urls)) stateService.accounts = [account] _ = try await subject.setActiveAccount(userId: account.profile.userId) diff --git a/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift b/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift index a5707e136..9a62e20da 100644 --- a/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift +++ b/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift @@ -334,7 +334,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ ] appSettingsStore.appId = "App id" clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -407,7 +407,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.importLoginsFlow] = true configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = false - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -481,7 +481,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = true stateService.accountSetupAutofillError = BitwardenTestError.example - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -513,7 +513,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.importLoginsFlow] = true configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = true - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -541,7 +541,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" clientService.mockAuth.hashPasswordResult = .success("hashed password") clientService.mockAuth.satisfiesPolicyResult = false - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -597,7 +597,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -683,7 +683,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ // Set up the mock data. appSettingsStore.appId = "App id" client.result = .httpSuccess(testData: .identityTokenSuccess) - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -745,7 +745,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // First login with the master password so that the request will be saved. @@ -862,7 +862,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" let policy = MasterPasswordPolicyOptions( @@ -926,7 +926,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" let policy = MasterPasswordPolicyOptions( @@ -1095,7 +1095,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // First login with the master password so that the resend email request will be saved. diff --git a/BitwardenShared/Core/Platform/Models/Domain/Account.swift b/BitwardenShared/Core/Platform/Models/Domain/Account.swift index 0fe95bc04..99d899e58 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Account.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Account.swift @@ -49,7 +49,7 @@ extension Account { /// init( identityTokenResponseModel: IdentityTokenResponseModel, - environmentUrls: EnvironmentUrlData? + environmentUrls: EnvironmentURLData? ) throws { let tokenPayload = try TokenParser.parseToken(identityTokenResponseModel.accessToken) self.init( @@ -132,7 +132,7 @@ extension Account { // MARK: Properties /// The environment URLs for an account. - var environmentUrls: EnvironmentUrlData? + var environmentUrls: EnvironmentURLData? } /// Domain model for an account's API tokens. diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlData.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift similarity index 92% rename from BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlData.swift rename to BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift index 2c19567cb..8989b54fa 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlData.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift @@ -2,7 +2,7 @@ import Foundation /// Domain model containing the environment URLs for an account. /// -struct EnvironmentUrlData: Codable, Equatable, Hashable { +struct EnvironmentURLData: Codable, Equatable, Hashable { // MARK: Properties /// The URL for the API. @@ -28,7 +28,7 @@ struct EnvironmentUrlData: Codable, Equatable, Hashable { // MARK: Initialization - /// Initialize `EnvironmentUrlData` with the specified URLs. + /// Initialize `EnvironmentURLData` with the specified URLs. /// /// - Parameters: /// - api: The URL for the API. @@ -58,7 +58,7 @@ struct EnvironmentUrlData: Codable, Equatable, Hashable { } } -extension EnvironmentUrlData { +extension EnvironmentURLData { // MARK: Properties /// The URL for the user to change their email. @@ -90,9 +90,9 @@ extension EnvironmentUrlData { /// Gets the region depending on the base url. var region: RegionType { switch base { - case EnvironmentUrlData.defaultUS.base: + case EnvironmentURLData.defaultUS.base: .unitedStates - case EnvironmentUrlData.defaultEU.base: + case EnvironmentURLData.defaultEU.base: .europe default: .selfHosted @@ -141,9 +141,9 @@ extension EnvironmentUrlData { } } -extension EnvironmentUrlData { +extension EnvironmentURLData { /// The default URLs for the US region. - static let defaultUS = EnvironmentUrlData( + static let defaultUS = EnvironmentURLData( api: URL(string: "https://api.bitwarden.com")!, base: URL(string: "https://vault.bitwarden.com")!, events: URL(string: "https://events.bitwarden.com")!, @@ -154,7 +154,7 @@ extension EnvironmentUrlData { ) /// The default URLs for the EU region. - static let defaultEU = EnvironmentUrlData( + static let defaultEU = EnvironmentURLData( api: URL(string: "https://api.bitwarden.eu")!, base: URL(string: "https://vault.bitwarden.eu")!, events: URL(string: "https://events.bitwarden.eu")!, diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlDataTests.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLDataTests.swift similarity index 79% rename from BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlDataTests.swift rename to BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLDataTests.swift index 820eb34b8..1383cd3d3 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlDataTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLDataTests.swift @@ -2,36 +2,36 @@ import XCTest @testable import BitwardenShared -class EnvironmentUrlDataTests: XCTestCase { +class EnvironmentURLDataTests: XCTestCase { // MARK: Tests /// `changeEmailURL` returns the change email URL for the base URL. func test_changeEmailURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.changeEmailURL?.absoluteString, "https://vault.example.com/#/settings/account") } /// `changeEmailURL` returns the default change email base URL. func test_changeEmailURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.changeEmailURL?.absoluteString) } /// `changeEmailURL` returns the change email URL for the web vault URL. func test_changeEmailURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) XCTAssertEqual(subject.changeEmailURL?.absoluteString, "https://web.vault.example.com/#/settings/account") } - /// `defaultUS` returns the properly configured `EnvironmentUrlData` + /// `defaultUS` returns the properly configured `EnvironmentURLData` /// with the deafult Urls for united states region. func test_defaultUS() { XCTAssertEqual( - EnvironmentUrlData.defaultUS, - EnvironmentUrlData( + EnvironmentURLData.defaultUS, + EnvironmentURLData( api: URL(string: "https://api.bitwarden.com")!, base: URL(string: "https://vault.bitwarden.com")!, events: URL(string: "https://events.bitwarden.com")!, @@ -43,12 +43,12 @@ class EnvironmentUrlDataTests: XCTestCase { ) } - /// `defaultEU` returns the properly configured `EnvironmentUrlData` + /// `defaultEU` returns the properly configured `EnvironmentURLData` /// with the deafult Urls for europe region. func test_defaultEU() { XCTAssertEqual( - EnvironmentUrlData.defaultEU, - EnvironmentUrlData( + EnvironmentURLData.defaultEU, + EnvironmentURLData( api: URL(string: "https://api.bitwarden.eu")!, base: URL(string: "https://vault.bitwarden.eu")!, events: URL(string: "https://events.bitwarden.eu")!, @@ -62,19 +62,19 @@ class EnvironmentUrlDataTests: XCTestCase { /// `importItemsURL` returns the import items URL for the base URL. func test_importItemsURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.importItemsURL?.absoluteString, "https://vault.example.com/#/tools/import") } /// `importItemsURL` returns the default import items base URL. func test_importItemsURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.importItemsURL?.absoluteString) } /// `importItemsURL` returns the import items URL for the web vault URL. func test_importItemsURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) @@ -83,35 +83,35 @@ class EnvironmentUrlDataTests: XCTestCase { /// `isEmpty` is true if none of the URLs are set. func test_isEmpty_empty() { - XCTAssertTrue(EnvironmentUrlData().isEmpty) + XCTAssertTrue(EnvironmentURLData().isEmpty) } /// `isEmpty` is false if any of the URLs are set. func test_isEmpty_withURLs() { - XCTAssertFalse(EnvironmentUrlData(api: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(base: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(events: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(icons: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(identity: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(notifications: .example).isEmpty) - XCTAssertFalse(EnvironmentUrlData(webVault: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(api: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(base: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(events: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(icons: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(identity: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(notifications: .example).isEmpty) + XCTAssertFalse(EnvironmentURLData(webVault: .example).isEmpty) } /// `recoveryCodeURL` returns the recovery code URL for the base URL. func test_recoveryCodeURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.recoveryCodeURL?.absoluteString, "https://vault.example.com/#/recover-2fa") } /// `recoveryCodeURL` returns the default settings base URL. func test_recoveryCodeURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.recoveryCodeURL?.absoluteString) } /// `recoveryCodeURL` returns the settings URL for the web vault URL. func test_recoveryCodeURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) @@ -120,49 +120,49 @@ class EnvironmentUrlDataTests: XCTestCase { /// `region` returns `.unitedStates` if base URL is the same as the default for US. func test_region_unitedStates() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")!) + let subject = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) XCTAssertTrue(subject.region == .unitedStates) } /// `region` returns `.europe` if base URL is the same as the default for EU. func test_region_europe() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.eu")!) + let subject = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) XCTAssertTrue(subject.region == .europe) } /// `region` returns `.selfHosted` if base URL is neither the default for US nor for EU. func test_region_selfHost() { - let subject = EnvironmentUrlData(base: URL(string: "https://example.com")!) + let subject = EnvironmentURLData(base: URL(string: "https://example.com")!) XCTAssertTrue(subject.region == .selfHosted) } /// `sendShareURL` returns the send URL for the united states region. func test_sendShareURL_unitedStates() { - let subject = EnvironmentUrlData.defaultUS + let subject = EnvironmentURLData.defaultUS XCTAssertEqual(subject.sendShareURL?.absoluteString, "https://send.bitwarden.com/#") } /// `sendShareURL` returns the send URL for the europe region. func test_sendShareURL_europe() { - let subject = EnvironmentUrlData.defaultEU + let subject = EnvironmentURLData.defaultEU XCTAssertEqual(subject.sendShareURL?.absoluteString, "https://vault.bitwarden.eu/#/send") } /// `sendShareURL` returns the send URL for the base URL. func test_sendShareURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.sendShareURL?.absoluteString, "https://vault.example.com/#/send") } /// `sendShareURL` returns the default send base URL. func test_sendShareURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.sendShareURL?.absoluteString) } /// `sendShareURL` returns the send URL for the web vault URL. func test_sendShareURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) @@ -171,19 +171,19 @@ class EnvironmentUrlDataTests: XCTestCase { /// `settingsURL` returns the settings URL for the base URL. func test_settingsURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.settingsURL?.absoluteString, "https://vault.example.com/#/settings") } /// `settingsURL` returns the default settings base URL. func test_settingsURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.settingsURL?.absoluteString) } /// `settingsURL` returns the settings URL for the web vault URL. func test_settingsURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) @@ -192,19 +192,19 @@ class EnvironmentUrlDataTests: XCTestCase { /// `setUpTwoFactorURL` returns the change email URL for the base URL. func test_setUpTwoFactorURL_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.setUpTwoFactorURL?.absoluteString, "https://vault.example.com/#/settings/security/two-factor") } /// `setUpTwoFactorURL` returns the default change email base URL. func test_setUpTwoFactorURL_noURLs() { - let subject = EnvironmentUrlData(base: nil, webVault: nil) + let subject = EnvironmentURLData(base: nil, webVault: nil) XCTAssertNil(subject.setUpTwoFactorURL?.absoluteString) } /// `setUpTwoFactorURL` returns the change email URL for the web vault URL. func test_setUpTwoFactorURL_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.example.com"), webVault: URL(string: "https://web.vault.example.com") ) @@ -213,13 +213,13 @@ class EnvironmentUrlDataTests: XCTestCase { /// `webVaultHost` returns the host for the base URL if no web vault URL is set. func test_webVaultHost_baseURL() { - let subject = EnvironmentUrlData(base: URL(string: "https://vault.example.com")) + let subject = EnvironmentURLData(base: URL(string: "https://vault.example.com")) XCTAssertEqual(subject.webVaultHost, "vault.example.com") } /// `webVaultHost` returns the host for the web vault URL. func test_webVaultHost_webVaultURL() { - let subject = EnvironmentUrlData( + let subject = EnvironmentURLData( base: URL(string: "https://vault.bitwarden.com"), webVault: URL(string: "https://web.vault.bitwarden.com") ) @@ -228,7 +228,7 @@ class EnvironmentUrlDataTests: XCTestCase { /// `webVaultHost` returns `nil` if no web vault or base URL is set. func test_webVaultHost_nil() { - let subject = EnvironmentUrlData() + let subject = EnvironmentURLData() XCTAssertNil(subject.webVaultHost) } } diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift index a46acb33d..3965fcd84 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift @@ -43,13 +43,13 @@ struct EnvironmentUrls: Equatable { } extension EnvironmentUrls { - /// Initialize `EnvironmentUrls` from `EnvironmentUrlData`. + /// Initialize `EnvironmentUrls` from `EnvironmentURLData`. /// /// - Parameter environmentUrlData: The environment URLs used to initialize `EnvironmentUrls`. /// - init(environmentUrlData: EnvironmentUrlData) { + init(environmentUrlData: EnvironmentURLData) { // Use the default URLs if the region matches US or EU. - let environmentUrlData: EnvironmentUrlData = switch environmentUrlData.region { + let environmentUrlData: EnvironmentURLData = switch environmentUrlData.region { case .europe: .defaultEU case .unitedStates: .defaultUS case .selfHosted: environmentUrlData diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift index af192d1bf..0d1aae824 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift @@ -8,7 +8,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` sets the URLs from the passed data when such data is the default US. func test_init_environmentUrlData_defaultUS() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData.defaultUS + environmentUrlData: EnvironmentURLData.defaultUS ) XCTAssertEqual( subject, @@ -32,7 +32,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` sets the URLs from the passed data when such data is the default EU. func test_init_environmentUrlData_defaultEU() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData.defaultEU + environmentUrlData: EnvironmentURLData.defaultEU ) XCTAssertEqual( subject, @@ -57,7 +57,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `.unitedStates` nor `.europe` region type. func test_init_environmentUrlData_baseUrl() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData(base: URL(string: "https://example.com")!) + environmentUrlData: EnvironmentURLData(base: URL(string: "https://example.com")!) ) XCTAssertEqual( subject, @@ -81,7 +81,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` defaults to the pre-defined EU URLs if the base URL matches the EU environment. func test_init_environmentUrlData_baseUrl_europe() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.eu")!) + environmentUrlData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) ) XCTAssertEqual( subject, @@ -105,7 +105,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` defaults to the pre-defined US URLs if the base URL matches the US environment. func test_init_environmentUrlData_baseUrl_unitedStates() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")!) + environmentUrlData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ) XCTAssertEqual( subject, @@ -129,7 +129,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` sets the URLs from the base URL which includes a trailing slash. func test_init_environmentUrlData_baseUrlWithTrailingSlash() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData(base: URL(string: "https://example.com/")!) + environmentUrlData: EnvironmentURLData(base: URL(string: "https://example.com/")!) ) XCTAssertEqual( subject, @@ -153,7 +153,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` sets the URLs based on the corresponding URL if there isn't a base URL. func test_init_environmentUrlData_custom() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentUrlData( + environmentUrlData: EnvironmentURLData( api: URL(string: "https://api.example.com")!, events: URL(string: "https://events.example.com")!, icons: URL(string: "https://icons.example.com")!, @@ -182,7 +182,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentUrlData:)` sets the URLs to default values if the URLs are empty. func test_init_environmentUrlData_empty() { - let subject = EnvironmentUrls(environmentUrlData: EnvironmentUrlData()) + let subject = EnvironmentUrls(environmentUrlData: EnvironmentURLData()) XCTAssertEqual( subject, EnvironmentUrls( diff --git a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift index 3d67a6e14..163905475 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift @@ -30,7 +30,7 @@ extension Account { userId: "13512467-9cfe-43b0-969f-07534084764b" ), settings: Account.AccountSettings( - environmentUrls: EnvironmentUrlData(base: URL(string: "https://vault.bitwarden.com")!) + environmentUrls: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ), tokens: nil ) @@ -115,7 +115,7 @@ extension Account.AccountProfile { extension Account.AccountSettings { static func fixture( - environmentUrls: EnvironmentUrlData? = .fixture() + environmentUrls: EnvironmentURLData? = .fixture() ) -> Account.AccountSettings { Account.AccountSettings( environmentUrls: environmentUrls diff --git a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift index f99a2f566..fb89e68bd 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift @@ -2,7 +2,7 @@ import Foundation @testable import BitwardenShared -extension EnvironmentUrlData { +extension EnvironmentURLData { static func fixture( api: URL? = nil, base: URL? = URL(string: "https://vault.bitwarden.com"), @@ -11,8 +11,8 @@ extension EnvironmentUrlData { identity: URL? = nil, notifications: URL? = nil, webVault: URL? = nil - ) -> EnvironmentUrlData { - EnvironmentUrlData( + ) -> EnvironmentURLData { + EnvironmentURLData( api: api, base: base, events: events, diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift index 5298abb56..4336c40d1 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift @@ -56,7 +56,7 @@ protocol EnvironmentService { /// /// - Parameter urls: The URLs to set and use prior to user authentication. /// - func setPreAuthURLs(urls: EnvironmentUrlData) async + func setPreAuthURLs(urls: EnvironmentURLData) async } // MARK: - DefaultEnvironmentService @@ -101,7 +101,7 @@ class DefaultEnvironmentService: EnvironmentService { // MARK: EnvironmentService func loadURLsForActiveAccount() async { - let urls: EnvironmentUrlData + let urls: EnvironmentURLData let managedSettingsUrls = managedSettingsUrls() if let environmentUrls = try? await stateService.getEnvironmentUrls() { urls = environmentUrls @@ -122,7 +122,7 @@ class DefaultEnvironmentService: EnvironmentService { Logger.application.info("Loaded environment URLs: \(String(describing: self.environmentUrls))") } - func setPreAuthURLs(urls: EnvironmentUrlData) async { + func setPreAuthURLs(urls: EnvironmentURLData) async { await stateService.setPreAuthEnvironmentUrls(urls) environmentUrls = EnvironmentUrls(environmentUrlData: urls) @@ -138,14 +138,14 @@ class DefaultEnvironmentService: EnvironmentService { /// /// - Returns: The environment URLs that are specified as part of a managed app configuration. /// - private func managedSettingsUrls() -> EnvironmentUrlData? { + private func managedSettingsUrls() -> EnvironmentURLData? { let managedSettings = standardUserDefaults.dictionary(forKey: "com.apple.configuration.managed") guard let baseUrlString = managedSettings?["baseEnvironmentUrl"] as? String, let baseUrl = URL(string: baseUrlString) else { return nil } - return EnvironmentUrlData(base: baseUrl) + return EnvironmentURLData(base: baseUrl) } } @@ -183,9 +183,9 @@ extension DefaultEnvironmentService { } var region: RegionType { - if environmentUrls.baseURL == EnvironmentUrlData.defaultUS.base { + if environmentUrls.baseURL == EnvironmentURLData.defaultUS.base { return .unitedStates - } else if environmentUrls.baseURL == EnvironmentUrlData.defaultEU.base { + } else if environmentUrls.baseURL == EnvironmentURLData.defaultEU.base { return .europe } else { return .selfHosted diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift b/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift index 07e4a8e3b..5f49c6855 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift @@ -58,7 +58,7 @@ class EnvironmentServiceTests: XCTestCase { /// `loadURLsForActiveAccount()` loads the URLs for the active account. func test_loadURLsForActiveAccount() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) let account = Account.fixture(settings: .fixture(environmentUrls: urls)) stateService.activeAccount = account stateService.environmentUrls = [account.profile.userId: urls] @@ -86,7 +86,7 @@ class EnvironmentServiceTests: XCTestCase { /// `loadURLsForActiveAccount()` handles EU URLs func test_loadURLsForActiveAccount_europe() async { - let urls = EnvironmentUrlData.defaultEU + let urls = EnvironmentURLData.defaultEU let account = Account.fixture(settings: .fixture(environmentUrls: urls)) stateService.activeAccount = account stateService.environmentUrls = [account.profile.userId: urls] @@ -122,7 +122,7 @@ class EnvironmentServiceTests: XCTestCase { await subject.loadURLsForActiveAccount() - let urls = try EnvironmentUrlData(base: XCTUnwrap(URL(string: "https://vault.example.com"))) + let urls = try EnvironmentURLData(base: XCTUnwrap(URL(string: "https://vault.example.com"))) XCTAssertEqual(subject.apiURL, URL(string: "https://vault.example.com/api")) XCTAssertEqual(subject.baseURL, URL(string: "https://vault.example.com")) XCTAssertEqual(subject.changeEmailURL, URL(string: "https://vault.example.com/#/settings/account")) @@ -168,7 +168,7 @@ class EnvironmentServiceTests: XCTestCase { XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://vault.bitwarden.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://vault.bitwarden.com")) - let urls = try EnvironmentUrlData(base: XCTUnwrap(URL(string: "https://vault.example.com"))) + let urls = try EnvironmentURLData(base: XCTUnwrap(URL(string: "https://vault.example.com"))) XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) } @@ -200,7 +200,7 @@ class EnvironmentServiceTests: XCTestCase { /// `loadURLsForActiveAccount()` loads the preAuth URLs if there's no active account /// and there are preauth URLs. func test_loadURLsForActiveAccount_preAuth() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) stateService.preAuthEnvironmentUrls = urls await subject.loadURLsForActiveAccount() @@ -227,7 +227,7 @@ class EnvironmentServiceTests: XCTestCase { /// `setPreAuthURLs(urls:)` sets the pre-auth URLs. func test_setPreAuthURLs() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) await subject.setPreAuthURLs(urls: urls) diff --git a/BitwardenShared/Core/Platform/Services/StateService.swift b/BitwardenShared/Core/Platform/Services/StateService.swift index 904224164..1bed08542 100644 --- a/BitwardenShared/Core/Platform/Services/StateService.swift +++ b/BitwardenShared/Core/Platform/Services/StateService.swift @@ -180,7 +180,7 @@ protocol StateService: AnyObject { /// - Parameter userId: The user ID associated with the environment URLs. /// - Returns: The user's environment URLs. /// - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentUrlData? + func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? /// Gets the events stored to disk to be uploaded in the future. /// @@ -254,14 +254,14 @@ protocol StateService: AnyObject { /// /// - Returns: The environment URLs used prior to user authentication. /// - func getPreAuthEnvironmentUrls() async -> EnvironmentUrlData? + func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? /// Gets the environment URLs for a given email during account creation. /// /// - Parameter email: The email used to start the account creation. /// - Returns: The environment URLs used prior to start the account creation. /// - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentUrlData? + func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? /// Gets the server config used by the app prior to the user authenticating. /// - Returns: The server config used prior to user authentication. @@ -581,14 +581,14 @@ protocol StateService: AnyObject { /// /// - Parameter urls: The environment URLs used prior to user authentication. /// - func setPreAuthEnvironmentUrls(_ urls: EnvironmentUrlData) async + func setPreAuthEnvironmentUrls(_ urls: EnvironmentURLData) async /// Sets the environment URLs for a given email during account creation. /// - Parameters: /// - urls: The environment urls used to start the account creation. /// - email: The email used to start the account creation. /// - func setAccountCreationEnvironmentUrls(urls: EnvironmentUrlData, email: String) async + func setAccountCreationEnvironmentUrls(urls: EnvironmentURLData, email: String) async /// Sets the server config used prior to user authentication /// - Parameter config: The server config to use prior to user authentication. @@ -867,7 +867,7 @@ extension StateService { /// /// - Returns: The environment URLs for the active account. /// - func getEnvironmentUrls() async throws -> EnvironmentUrlData? { + func getEnvironmentUrls() async throws -> EnvironmentURLData? { try await getEnvironmentUrls(userId: nil) } @@ -1450,7 +1450,7 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le return appSettingsStore.encryptedPin(userId: userId) } - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentUrlData? { + func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? { let userId = try userId ?? getActiveAccountUserId() return appSettingsStore.state?.accounts[userId]?.settings.environmentUrls } @@ -1502,11 +1502,11 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le return appSettingsStore.passwordGenerationOptions(userId: userId) } - func getPreAuthEnvironmentUrls() async -> EnvironmentUrlData? { + func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? { appSettingsStore.preAuthEnvironmentUrls } - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentUrlData? { + func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? { appSettingsStore.accountCreationEnvironmentUrls(email: email) } @@ -1786,11 +1786,11 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le ].pinProtectedUserKey = pinProtectedUserKey } - func setPreAuthEnvironmentUrls(_ urls: EnvironmentUrlData) async { + func setPreAuthEnvironmentUrls(_ urls: EnvironmentURLData) async { appSettingsStore.preAuthEnvironmentUrls = urls } - func setAccountCreationEnvironmentUrls(urls: EnvironmentUrlData, email: String) async { + func setAccountCreationEnvironmentUrls(urls: EnvironmentURLData, email: String) async { appSettingsStore.setAccountCreationEnvironmentUrls( environmentUrlData: urls, email: email diff --git a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift index 37e9caa49..52f420410 100644 --- a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift @@ -621,7 +621,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body /// `getEnvironmentUrls()` returns the environment URLs for the active account. func test_getEnvironmentUrls() async throws { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) let account = Account.fixture(settings: .fixture(environmentUrls: urls)) appSettingsStore.state = State( accounts: [account.profile.userId: account], @@ -804,7 +804,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body /// `getPreAuthEnvironmentUrls` returns the saved pre-auth URLs. func test_getPreAuthEnvironmentUrls() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) appSettingsStore.preAuthEnvironmentUrls = urls let preAuthUrls = await subject.getPreAuthEnvironmentUrls() XCTAssertEqual(preAuthUrls, urls) @@ -819,7 +819,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body /// `getAccountCreationEnvironmentUrls` returns the saved pre-auth URLs for a given email. func test_getAccountCreationEnvironmentUrls() async { let email = "example@email.com" - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) appSettingsStore.setAccountCreationEnvironmentUrls(environmentUrlData: urls, email: email) let preAuthUrls = await subject.getAccountCreationEnvironmentUrls(email: email) XCTAssertEqual(preAuthUrls, urls) @@ -1819,7 +1819,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body /// `setPreAuthEnvironmentUrls` saves the pre-auth URLs. func test_setPreAuthEnvironmentUrls() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) await subject.setPreAuthEnvironmentUrls(urls) XCTAssertEqual(appSettingsStore.preAuthEnvironmentUrls, urls) } @@ -1827,7 +1827,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body /// `test_setAccountCreationEnvironmentUrls` saves the pre-auth URLs for email for a given email. func test_setAccountCreationEnvironmentUrls() async { let email = "example@email.com" - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) await subject.setAccountCreationEnvironmentUrls(urls: urls, email: email) XCTAssertEqual(appSettingsStore.accountCreationEnvironmentUrls(email: email), urls) } diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift index 566a11c9b..419db0b5e 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift @@ -43,7 +43,7 @@ protocol AppSettingsStore: AnyObject { var migrationVersion: Int { get set } /// The environment URLs used prior to user authentication. - var preAuthEnvironmentUrls: EnvironmentUrlData? { get set } + var preAuthEnvironmentUrls: EnvironmentURLData? { get set } /// The server config used prior to user authentication. var preAuthServerConfig: ServerConfig? { get set } @@ -238,7 +238,7 @@ protocol AppSettingsStore: AnyObject { /// - email: The email used to start the account creation. /// - Returns: The environment URLs used prior to start the account creation. /// - func accountCreationEnvironmentUrls(email: String) -> EnvironmentUrlData? + func accountCreationEnvironmentUrls(email: String) -> EnvironmentURLData? /// The server configuration. /// @@ -420,7 +420,7 @@ protocol AppSettingsStore: AnyObject { /// - email: The user's email address. /// - environmentUrlData: The environment data to be saved. /// - func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentUrlData, email: String) + func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentURLData, email: String) /// Sets the server config. /// @@ -872,7 +872,7 @@ extension DefaultAppSettingsStore: AppSettingsStore { set { store(newValue, for: .migrationVersion) } } - var preAuthEnvironmentUrls: EnvironmentUrlData? { + var preAuthEnvironmentUrls: EnvironmentURLData? { get { fetch(for: .preAuthEnvironmentUrls) } set { store(newValue, for: .preAuthEnvironmentUrls) } } @@ -1001,7 +1001,7 @@ extension DefaultAppSettingsStore: AppSettingsStore { fetch(for: .pinProtectedUserKey(userId: userId)) } - func accountCreationEnvironmentUrls(email: String) -> EnvironmentUrlData? { + func accountCreationEnvironmentUrls(email: String) -> EnvironmentURLData? { fetch( for: .accountCreationEnvironmentUrls(email: email) ) @@ -1095,7 +1095,7 @@ extension DefaultAppSettingsStore: AppSettingsStore { store(key, for: .pinProtectedUserKey(userId: userId)) } - func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentUrlData, email: String) { + func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentURLData, email: String) { store(environmentUrlData, for: .accountCreationEnvironmentUrls(email: email)) } diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift index 33f2bd95c..c291f6f30 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift @@ -692,7 +692,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(subject.preAuthEnvironmentUrls, .defaultUS) try XCTAssertEqual( JSONDecoder().decode( - EnvironmentUrlData.self, + EnvironmentURLData.self, from: XCTUnwrap( userDefaults .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? @@ -706,7 +706,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(subject.preAuthEnvironmentUrls, .defaultEU) try XCTAssertEqual( JSONDecoder().decode( - EnvironmentUrlData.self, + EnvironmentURLData.self, from: XCTUnwrap( userDefaults .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? @@ -729,7 +729,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultUS) try XCTAssertEqual( JSONDecoder().decode( - EnvironmentUrlData.self, + EnvironmentURLData.self, from: XCTUnwrap( userDefaults .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? @@ -743,7 +743,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultEU) try XCTAssertEqual( JSONDecoder().decode( - EnvironmentUrlData.self, + EnvironmentURLData.self, from: XCTUnwrap( userDefaults .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? diff --git a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift index 2c468ab9f..449a813cc 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift @@ -20,7 +20,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo var loginRequest: LoginRequestNotification? var migrationVersion = 0 var overrideDebugFeatureFlagCalled = false - var preAuthEnvironmentUrls: EnvironmentUrlData? + var preAuthEnvironmentUrls: EnvironmentURLData? var preAuthServerConfig: BitwardenShared.ServerConfig? var rememberedEmail: String? var rememberedOrgIdentifier: String? @@ -43,7 +43,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo var notificationsLastRegistrationDates = [String: Date]() var passwordGenerationOptions = [String: PasswordGenerationOptions]() var pinProtectedUserKey = [String: String]() - var accountCreationEnvironmentUrls = [String: EnvironmentUrlData]() + var accountCreationEnvironmentUrls = [String: EnvironmentURLData]() var serverConfig = [String: ServerConfig]() var shouldTrustDevice = [String: Bool?]() var syncToAuthenticatorByUserId = [String: Bool]() @@ -151,7 +151,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo pinProtectedUserKey[userId] } - func accountCreationEnvironmentUrls(email: String) -> BitwardenShared.EnvironmentUrlData? { + func accountCreationEnvironmentUrls(email: String) -> BitwardenShared.EnvironmentURLData? { accountCreationEnvironmentUrls[email] } @@ -259,7 +259,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo pinProtectedUserKey[userId] = key } - func setAccountCreationEnvironmentUrls(environmentUrlData: BitwardenShared.EnvironmentUrlData, email: String) { + func setAccountCreationEnvironmentUrls(environmentUrlData: BitwardenShared.EnvironmentURLData, email: String) { accountCreationEnvironmentUrls[email] = environmentUrlData } diff --git a/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift b/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift index 2dfc5a3df..3e1be48fe 100644 --- a/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift @@ -4,8 +4,8 @@ import Foundation class MockEnvironmentService: EnvironmentService { var didLoadURLsForActiveAccount = false - var setActiveAccountEnvironmentUrlsData: EnvironmentUrlData? - var setPreAuthEnvironmentUrlsData: EnvironmentUrlData? + var setActiveAccountEnvironmentUrlsData: EnvironmentURLData? + var setPreAuthEnvironmentUrlsData: EnvironmentURLData? var apiURL = URL(string: "https://example.com/api")! var baseURL = URL(string: "https://example.com")! @@ -25,11 +25,11 @@ class MockEnvironmentService: EnvironmentService { didLoadURLsForActiveAccount = true } - func setActiveAccountURLs(urls: EnvironmentUrlData) { + func setActiveAccountURLs(urls: EnvironmentURLData) { setActiveAccountEnvironmentUrlsData = urls } - func setPreAuthURLs(urls: EnvironmentUrlData) async { + func setPreAuthURLs(urls: EnvironmentURLData) async { setPreAuthEnvironmentUrlsData = urls } } diff --git a/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift b/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift index 64aeaf70f..7dbcd6bb9 100644 --- a/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift +++ b/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift @@ -34,7 +34,7 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt var doesActiveAccountHavePremiumCalled = false var doesActiveAccountHavePremiumResult: Result = .success(true) var encryptedPinByUserId = [String: String]() - var environmentUrls = [String: EnvironmentUrlData]() + var environmentUrls = [String: EnvironmentURLData]() var environmentUrlsError: Error? var eventsResult: Result = .success(()) var events = [String: [EventData]]() @@ -58,8 +58,8 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt var notificationsLastRegistrationError: Error? var passwordGenerationOptions = [String: PasswordGenerationOptions]() var pinProtectedUserKeyValue = [String: String]() - var preAuthEnvironmentUrls: EnvironmentUrlData? - var accountCreationEnvironmentUrls = [String: EnvironmentUrlData]() + var preAuthEnvironmentUrls: EnvironmentURLData? + var accountCreationEnvironmentUrls = [String: EnvironmentURLData]() var preAuthServerConfig: ServerConfig? var rememberedOrgIdentifier: String? var reviewPromptData: ReviewPromptData? @@ -229,7 +229,7 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt return encryptedPinByUserId[userId] ?? nil } - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentUrlData? { + func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? { if let environmentUrlsError { throw environmentUrlsError } @@ -284,11 +284,11 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt return passwordGenerationOptions[userId] } - func getPreAuthEnvironmentUrls() async -> EnvironmentUrlData? { + func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? { preAuthEnvironmentUrls } - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentUrlData? { + func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? { accountCreationEnvironmentUrls[email] } @@ -469,7 +469,7 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt accountVolatileData[userId, default: AccountVolatileData()].pinProtectedUserKey = pin } - func setEnvironmentUrls(_ environmentUrls: EnvironmentUrlData, userId: String?) async throws { + func setEnvironmentUrls(_ environmentUrls: EnvironmentURLData, userId: String?) async throws { let userId = try unwrapUserId(userId) self.environmentUrls[userId] = environmentUrls } @@ -557,11 +557,11 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt ].pinProtectedUserKey = pin } - func setPreAuthEnvironmentUrls(_ urls: BitwardenShared.EnvironmentUrlData) async { + func setPreAuthEnvironmentUrls(_ urls: BitwardenShared.EnvironmentURLData) async { preAuthEnvironmentUrls = urls } - func setAccountCreationEnvironmentUrls(urls: BitwardenShared.EnvironmentUrlData, email: String) async { + func setAccountCreationEnvironmentUrls(urls: BitwardenShared.EnvironmentURLData, email: String) async { accountCreationEnvironmentUrls[email] = urls } diff --git a/BitwardenShared/UI/Auth/AuthCoordinator.swift b/BitwardenShared/UI/Auth/AuthCoordinator.swift index 7205bed07..448723b15 100644 --- a/BitwardenShared/UI/Auth/AuthCoordinator.swift +++ b/BitwardenShared/UI/Auth/AuthCoordinator.swift @@ -512,7 +512,7 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt let isPresenting = stackNavigator.rootViewController?.presentedViewController != nil let environmentUrls = EnvironmentUrls( - environmentUrlData: services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentUrlData() + environmentUrlData: services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() ) let state = LoginState( @@ -667,7 +667,7 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt /// - currentRegion: The user's region prior to showing the self-hosted settings view. /// private func showSelfHostedView(delegate: SelfHostedProcessorDelegate?, currentRegion: RegionType) { - let preAuthEnvironmentUrls = services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentUrlData() + let preAuthEnvironmentUrls = services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() var state = SelfHostedState() if currentRegion == .selfHosted { diff --git a/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift b/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift index 360dbbcad..dbd492ea6 100644 --- a/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift +++ b/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift @@ -338,7 +338,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// `navigate(to:)` with `.login` pushes the login view onto the stack navigator and hides the back button. @MainActor func test_navigate_login() throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentUrlData.defaultEU + appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData.defaultEU subject.navigate(to: .login(username: "username")) XCTAssertEqual(stackNavigator.actions.last?.type, .pushed) @@ -356,7 +356,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// `navigate(to:)` with `.login` pushes the login view onto the stack navigator and hides the back button. @MainActor func test_navigate_login_newAccount() throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentUrlData.defaultEU + appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData.defaultEU subject.navigate(to: .login(username: "username", isNewAccount: true)) XCTAssertEqual(stackNavigator.actions.last?.type, .pushed) @@ -377,7 +377,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// It also initializes `LoginState` with the self-hosted URL host. @MainActor func test_navigate_login_selfHosted() async throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentUrlData(webVault: URL(string: "http://www.example.com")!) + appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData(webVault: URL(string: "http://www.example.com")!) subject.navigate(to: .login(username: "username")) let viewController = try XCTUnwrap( diff --git a/BitwardenShared/UI/Auth/Landing/LandingProcessor.swift b/BitwardenShared/UI/Auth/Landing/LandingProcessor.swift index e99195c70..768348153 100644 --- a/BitwardenShared/UI/Auth/Landing/LandingProcessor.swift +++ b/BitwardenShared/UI/Auth/Landing/LandingProcessor.swift @@ -206,7 +206,7 @@ extension LandingProcessor: ProfileSwitcherHandler { // MARK: - SelfHostedProcessorDelegate extension LandingProcessor: SelfHostedProcessorDelegate { - func didSaveEnvironment(urls: EnvironmentUrlData) async { + func didSaveEnvironment(urls: EnvironmentURLData) async { await setRegion(.selfHosted, urls) state.toast = Toast(title: Localizations.environmentSaved) await regionHelper.loadRegion() @@ -236,7 +236,7 @@ extension LandingProcessor: RegionDelegate { /// - region: The region to use. /// - urls: The URLs that the app should use for the region. /// - func setRegion(_ region: RegionType, _ urls: EnvironmentUrlData) async { + func setRegion(_ region: RegionType, _ urls: EnvironmentURLData) async { guard !urls.isEmpty else { return } await services.environmentService.setPreAuthURLs(urls: urls) state.region = region diff --git a/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift b/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift index 96963b1af..5a4d5c7af 100644 --- a/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift +++ b/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift @@ -63,13 +63,13 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// `didChangeRegion(urls:)` update URLs when they change on the StartRegistration modal @MainActor func test_didChangeRegion() async { - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: .example) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: .example) subject.state.region = .unitedStates await subject.didChangeRegion() XCTAssertEqual(subject.state.region, .selfHosted) XCTAssertEqual( environmentService.setPreAuthEnvironmentUrlsData, - EnvironmentUrlData(base: .example) + EnvironmentURLData(base: .example) ) } @@ -77,23 +77,23 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// the environment. @MainActor func test_didSaveEnvironment() async { - stateService.preAuthEnvironmentUrls = EnvironmentUrlData(base: .example) + stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: .example) subject.state.region = .unitedStates - await subject.didSaveEnvironment(urls: EnvironmentUrlData(base: .example)) + await subject.didSaveEnvironment(urls: EnvironmentURLData(base: .example)) XCTAssertEqual(subject.state.region, .selfHosted) XCTAssertEqual(subject.state.toast, Toast(title: Localizations.environmentSaved)) XCTAssertEqual( environmentService.setPreAuthEnvironmentUrlsData, - EnvironmentUrlData(base: .example) + EnvironmentURLData(base: .example) ) } /// `didSaveEnvironment(urls:)` with empty URLs doesn't change the region or the environment URLs. @MainActor func test_didSaveEnvironment_empty() async { - stateService.preAuthEnvironmentUrls = EnvironmentUrlData() + stateService.preAuthEnvironmentUrls = EnvironmentURLData() subject.state.region = .unitedStates - await subject.didSaveEnvironment(urls: EnvironmentUrlData()) + await subject.didSaveEnvironment(urls: EnvironmentURLData()) XCTAssertEqual(subject.state.region, .unitedStates) XCTAssertNil(environmentService.setPreAuthEnvironmentUrlsData) } @@ -120,7 +120,7 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// and sets the URLs to the environment. @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_selfHosted() async { - let urls = EnvironmentUrlData(base: .example) + let urls = EnvironmentURLData(base: .example) stateService.preAuthEnvironmentUrls = urls await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .selfHosted) diff --git a/BitwardenShared/UI/Auth/Landing/SelfHosted/SelfHostedProcessor.swift b/BitwardenShared/UI/Auth/Landing/SelfHosted/SelfHostedProcessor.swift index dd2f17ff0..5f9ae320d 100644 --- a/BitwardenShared/UI/Auth/Landing/SelfHosted/SelfHostedProcessor.swift +++ b/BitwardenShared/UI/Auth/Landing/SelfHosted/SelfHostedProcessor.swift @@ -7,7 +7,7 @@ protocol SelfHostedProcessorDelegate: AnyObject { /// /// - Parameter urls: The URLs that the user specified for their environment. /// - func didSaveEnvironment(urls: EnvironmentUrlData) async + func didSaveEnvironment(urls: EnvironmentURLData) async } // MARK: - SelfHostedProcessor @@ -97,7 +97,7 @@ final class SelfHostedProcessor: StateProcessor Date: Mon, 16 Dec 2024 11:53:38 -0600 Subject: [PATCH 2/9] Update environmentURLData --- .../Models/Domain/EnvironmentUrls.swift | 34 ++++++------- .../Models/Domain/EnvironmentUrlsTests.swift | 48 +++++++++---------- .../Services/EnvironmentService.swift | 6 +-- .../Core/Platform/Services/StateService.swift | 2 +- .../Platform/Services/StateServiceTests.swift | 2 +- .../Services/Stores/AppSettingsStore.swift | 8 ++-- .../Stores/AppSettingsStoreTests.swift | 4 +- .../TestHelpers/MockAppSettingsStore.swift | 4 +- BitwardenShared/UI/Auth/AuthCoordinator.swift | 2 +- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift index 3965fcd84..b48f37243 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift @@ -45,17 +45,17 @@ struct EnvironmentUrls: Equatable { extension EnvironmentUrls { /// Initialize `EnvironmentUrls` from `EnvironmentURLData`. /// - /// - Parameter environmentUrlData: The environment URLs used to initialize `EnvironmentUrls`. + /// - Parameter environmentURLData: The environment URLs used to initialize `EnvironmentUrls`. /// - init(environmentUrlData: EnvironmentURLData) { + init(environmentURLData: EnvironmentURLData) { // Use the default URLs if the region matches US or EU. - let environmentUrlData: EnvironmentURLData = switch environmentUrlData.region { + let environmentURLData: EnvironmentURLData = switch environmentURLData.region { case .europe: .defaultEU case .unitedStates: .defaultUS - case .selfHosted: environmentUrlData + case .selfHosted: environmentURLData } - if environmentUrlData.region == .selfHosted, let base = environmentUrlData.base { + if environmentURLData.region == .selfHosted, let base = environmentURLData.base { apiURL = base.appendingPathComponent("api") baseURL = base eventsURL = base.appendingPathComponent("events") @@ -63,20 +63,20 @@ extension EnvironmentUrls { identityURL = base.appendingPathComponent("identity") webVaultURL = base } else { - apiURL = environmentUrlData.api ?? URL(string: "https://api.bitwarden.com")! - baseURL = environmentUrlData.base ?? URL(string: "https://vault.bitwarden.com")! - eventsURL = environmentUrlData.events ?? URL(string: "https://events.bitwarden.com")! - iconsURL = environmentUrlData.icons ?? URL(string: "https://icons.bitwarden.net")! - identityURL = environmentUrlData.identity ?? URL(string: "https://identity.bitwarden.com")! - webVaultURL = environmentUrlData.webVault ?? URL(string: "https://vault.bitwarden.com")! + apiURL = environmentURLData.api ?? URL(string: "https://api.bitwarden.com")! + baseURL = environmentURLData.base ?? URL(string: "https://vault.bitwarden.com")! + eventsURL = environmentURLData.events ?? URL(string: "https://events.bitwarden.com")! + iconsURL = environmentURLData.icons ?? URL(string: "https://icons.bitwarden.net")! + identityURL = environmentURLData.identity ?? URL(string: "https://identity.bitwarden.com")! + webVaultURL = environmentURLData.webVault ?? URL(string: "https://vault.bitwarden.com")! } - importItemsURL = environmentUrlData.importItemsURL ?? URL(string: "https://vault.bitwarden.com/#/tools/import")! - recoveryCodeURL = environmentUrlData.recoveryCodeURL ?? URL( + importItemsURL = environmentURLData.importItemsURL ?? URL(string: "https://vault.bitwarden.com/#/tools/import")! + recoveryCodeURL = environmentURLData.recoveryCodeURL ?? URL( string: "https://vault.bitwarden.com/#/recover-2fa" )! - sendShareURL = environmentUrlData.sendShareURL ?? URL(string: "https://send.bitwarden.com/#")! - settingsURL = environmentUrlData.settingsURL ?? webVaultURL - changeEmailURL = environmentUrlData.changeEmailURL ?? settingsURL - setUpTwoFactorURL = environmentUrlData.setUpTwoFactorURL ?? settingsURL + sendShareURL = environmentURLData.sendShareURL ?? URL(string: "https://send.bitwarden.com/#")! + settingsURL = environmentURLData.settingsURL ?? webVaultURL + changeEmailURL = environmentURLData.changeEmailURL ?? settingsURL + setUpTwoFactorURL = environmentURLData.setUpTwoFactorURL ?? settingsURL } } diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift index 0d1aae824..3bef41d80 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift @@ -5,10 +5,10 @@ import XCTest class EnvironmentUrlsTests: BitwardenTestCase { // MARK: Tests - /// `init(environmentUrlData:)` sets the URLs from the passed data when such data is the default US. - func test_init_environmentUrlData_defaultUS() { + /// `init(environmentURLData:)` sets the URLs from the passed data when such data is the default US. + func test_init_environmentURLData_defaultUS() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData.defaultUS + environmentURLData: EnvironmentURLData.defaultUS ) XCTAssertEqual( subject, @@ -29,10 +29,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` sets the URLs from the passed data when such data is the default EU. - func test_init_environmentUrlData_defaultEU() { + /// `init(environmentURLData:)` sets the URLs from the passed data when such data is the default EU. + func test_init_environmentURLData_defaultEU() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData.defaultEU + environmentURLData: EnvironmentURLData.defaultEU ) XCTAssertEqual( subject, @@ -53,11 +53,11 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` sets the URLs from the base URL if one is set and is not + /// `init(environmentURLData:)` sets the URLs from the base URL if one is set and is not /// `.unitedStates` nor `.europe` region type. - func test_init_environmentUrlData_baseUrl() { + func test_init_environmentURLData_baseUrl() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData(base: URL(string: "https://example.com")!) + environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com")!) ) XCTAssertEqual( subject, @@ -78,10 +78,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` defaults to the pre-defined EU URLs if the base URL matches the EU environment. - func test_init_environmentUrlData_baseUrl_europe() { + /// `init(environmentURLData:)` defaults to the pre-defined EU URLs if the base URL matches the EU environment. + func test_init_environmentURLData_baseUrl_europe() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) + environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) ) XCTAssertEqual( subject, @@ -102,10 +102,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` defaults to the pre-defined US URLs if the base URL matches the US environment. - func test_init_environmentUrlData_baseUrl_unitedStates() { + /// `init(environmentURLData:)` defaults to the pre-defined US URLs if the base URL matches the US environment. + func test_init_environmentURLData_baseUrl_unitedStates() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) + environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ) XCTAssertEqual( subject, @@ -126,10 +126,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` sets the URLs from the base URL which includes a trailing slash. - func test_init_environmentUrlData_baseUrlWithTrailingSlash() { + /// `init(environmentURLData:)` sets the URLs from the base URL which includes a trailing slash. + func test_init_environmentURLData_baseUrlWithTrailingSlash() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData(base: URL(string: "https://example.com/")!) + environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com/")!) ) XCTAssertEqual( subject, @@ -150,10 +150,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` sets the URLs based on the corresponding URL if there isn't a base URL. - func test_init_environmentUrlData_custom() { + /// `init(environmentURLData:)` sets the URLs based on the corresponding URL if there isn't a base URL. + func test_init_environmentURLData_custom() { let subject = EnvironmentUrls( - environmentUrlData: EnvironmentURLData( + environmentURLData: EnvironmentURLData( api: URL(string: "https://api.example.com")!, events: URL(string: "https://events.example.com")!, icons: URL(string: "https://icons.example.com")!, @@ -180,9 +180,9 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) } - /// `init(environmentUrlData:)` sets the URLs to default values if the URLs are empty. - func test_init_environmentUrlData_empty() { - let subject = EnvironmentUrls(environmentUrlData: EnvironmentURLData()) + /// `init(environmentURLData:)` sets the URLs to default values if the URLs are empty. + func test_init_environmentURLData_empty() { + let subject = EnvironmentUrls(environmentURLData: EnvironmentURLData()) XCTAssertEqual( subject, EnvironmentUrls( diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift index 4336c40d1..8c20ad220 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift @@ -95,7 +95,7 @@ class DefaultEnvironmentService: EnvironmentService { self.stateService = stateService self.standardUserDefaults = standardUserDefaults - environmentUrls = EnvironmentUrls(environmentUrlData: .defaultUS) + environmentUrls = EnvironmentUrls(environmentURLData: .defaultUS) } // MARK: EnvironmentService @@ -114,7 +114,7 @@ class DefaultEnvironmentService: EnvironmentService { } await setPreAuthURLs(urls: managedSettingsUrls ?? urls) - environmentUrls = EnvironmentUrls(environmentUrlData: urls) + environmentUrls = EnvironmentUrls(environmentURLData: urls) errorReporter.setRegion(region.errorReporterName, isPreAuth: false) @@ -124,7 +124,7 @@ class DefaultEnvironmentService: EnvironmentService { func setPreAuthURLs(urls: EnvironmentURLData) async { await stateService.setPreAuthEnvironmentUrls(urls) - environmentUrls = EnvironmentUrls(environmentUrlData: urls) + environmentUrls = EnvironmentUrls(environmentURLData: urls) errorReporter.setRegion(region.errorReporterName, isPreAuth: true) diff --git a/BitwardenShared/Core/Platform/Services/StateService.swift b/BitwardenShared/Core/Platform/Services/StateService.swift index 1bed08542..7712cfdf0 100644 --- a/BitwardenShared/Core/Platform/Services/StateService.swift +++ b/BitwardenShared/Core/Platform/Services/StateService.swift @@ -1792,7 +1792,7 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le func setAccountCreationEnvironmentUrls(urls: EnvironmentURLData, email: String) async { appSettingsStore.setAccountCreationEnvironmentUrls( - environmentUrlData: urls, + environmentURLData: urls, email: email ) } diff --git a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift index 52f420410..225930cc4 100644 --- a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift @@ -820,7 +820,7 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body func test_getAccountCreationEnvironmentUrls() async { let email = "example@email.com" let urls = EnvironmentURLData(base: .example) - appSettingsStore.setAccountCreationEnvironmentUrls(environmentUrlData: urls, email: email) + appSettingsStore.setAccountCreationEnvironmentUrls(environmentURLData: urls, email: email) let preAuthUrls = await subject.getAccountCreationEnvironmentUrls(email: email) XCTAssertEqual(preAuthUrls, urls) } diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift index 419db0b5e..989ec68b8 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift @@ -418,9 +418,9 @@ protocol AppSettingsStore: AnyObject { /// /// - Parameters: /// - email: The user's email address. - /// - environmentUrlData: The environment data to be saved. + /// - environmentURLData: The environment data to be saved. /// - func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentURLData, email: String) + func setAccountCreationEnvironmentUrls(environmentURLData: EnvironmentURLData, email: String) /// Sets the server config. /// @@ -1095,8 +1095,8 @@ extension DefaultAppSettingsStore: AppSettingsStore { store(key, for: .pinProtectedUserKey(userId: userId)) } - func setAccountCreationEnvironmentUrls(environmentUrlData: EnvironmentURLData, email: String) { - store(environmentUrlData, for: .accountCreationEnvironmentUrls(email: email)) + func setAccountCreationEnvironmentUrls(environmentURLData: EnvironmentURLData, email: String) { + store(environmentURLData, for: .accountCreationEnvironmentUrls(email: email)) } func setServerConfig(_ config: ServerConfig?, userId: String) { diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift index c291f6f30..fe7f81c86 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift @@ -725,7 +725,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ /// `accountCreationEnvironmentUrls` can be used to get and set the persisted value in user defaults. func test_accountCreationEnvironmentUrls_withValue() { let email = "example@email.com" - subject.setAccountCreationEnvironmentUrls(environmentUrlData: .defaultUS, email: email) + subject.setAccountCreationEnvironmentUrls(environmentURLData: .defaultUS, email: email) XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultUS) try XCTAssertEqual( JSONDecoder().decode( @@ -739,7 +739,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ .defaultUS ) - subject.setAccountCreationEnvironmentUrls(environmentUrlData: .defaultEU, email: email) + subject.setAccountCreationEnvironmentUrls(environmentURLData: .defaultEU, email: email) XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultEU) try XCTAssertEqual( JSONDecoder().decode( diff --git a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift index 449a813cc..863fc54fc 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift @@ -259,8 +259,8 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo pinProtectedUserKey[userId] = key } - func setAccountCreationEnvironmentUrls(environmentUrlData: BitwardenShared.EnvironmentURLData, email: String) { - accountCreationEnvironmentUrls[email] = environmentUrlData + func setAccountCreationEnvironmentUrls(environmentURLData: BitwardenShared.EnvironmentURLData, email: String) { + accountCreationEnvironmentUrls[email] = environmentURLData } func setServerConfig(_ config: ServerConfig?, userId: String) { diff --git a/BitwardenShared/UI/Auth/AuthCoordinator.swift b/BitwardenShared/UI/Auth/AuthCoordinator.swift index 448723b15..675386818 100644 --- a/BitwardenShared/UI/Auth/AuthCoordinator.swift +++ b/BitwardenShared/UI/Auth/AuthCoordinator.swift @@ -512,7 +512,7 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt let isPresenting = stackNavigator.rootViewController?.presentedViewController != nil let environmentUrls = EnvironmentUrls( - environmentUrlData: services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() + environmentURLData: services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() ) let state = LoginState( From f4d4380c81762ea0119c7e3a565022a88436d2cb Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Mon, 16 Dec 2024 11:55:17 -0600 Subject: [PATCH 3/9] Update environmentURLs --- .../Auth/Repositories/AuthRepository.swift | 4 +- .../Repositories/AuthRepositoryTests.swift | 20 +++--- .../Core/Auth/Services/AuthService.swift | 4 +- .../Core/Auth/Services/AuthServiceTests.swift | 24 +++---- .../Core/Platform/Models/Domain/Account.swift | 8 +-- .../Platform/Models/Domain/AccountTests.swift | 4 +- .../Models/Domain/EnvironmentUrls.swift | 8 +-- .../Models/Domain/EnvironmentUrlsTests.swift | 34 +++++----- .../Domain/Fixtures/Account+Fixtures.swift | 6 +- .../Services/AuthenticatorSyncService.swift | 2 +- .../AuthenticatorSyncServiceTests.swift | 2 +- .../Services/EnvironmentService.swift | 48 +++++++------- .../Services/EnvironmentServiceTests.swift | 26 ++++---- .../Core/Platform/Services/StateService.swift | 34 +++++----- .../Platform/Services/StateServiceTests.swift | 66 +++++++++---------- .../Services/Stores/AppSettingsStore.swift | 32 ++++----- .../Stores/AppSettingsStoreTests.swift | 44 ++++++------- .../TestHelpers/MockAppSettingsStore.swift | 12 ++-- .../TestHelpers/MockEnvironmentService.swift | 8 +-- .../TestHelpers/MockStateService.swift | 36 +++++----- BitwardenShared/UI/Auth/AuthCoordinator.swift | 18 ++--- .../UI/Auth/AuthCoordinatorTests.swift | 6 +- .../CompleteRegistrationProcessor.swift | 2 +- .../CompleteRegistrationProcessorTests.swift | 12 ++-- .../Auth/Landing/LandingProcessorTests.swift | 26 ++++---- .../StartRegistrationProcessor.swift | 4 +- .../StartRegistrationProcessorTests.swift | 36 +++++----- .../UI/Auth/Utilities/RegionHelper.swift | 2 +- .../UI/Auth/Utilities/RegionHelperTests.swift | 8 +-- .../Auth/VaultUnlock/VaultUnlockState.swift | 2 +- .../VaultUnlock/VaultUnlockStateTests.swift | 4 +- .../ImportLogins/ImportLoginsProcessor.swift | 2 +- .../ImportLoginsProcessorTests.swift | 4 +- 33 files changed, 274 insertions(+), 274 deletions(-) diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift index db85a1a6c..c2dbf33f6 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift @@ -625,7 +625,7 @@ extension DefaultAuthRepository: AuthRepository { errorReporter.log(error: error) } - if let baseUrl = try? await stateService.getEnvironmentUrls(userId: userId)?.base, + if let baseUrl = try? await stateService.getEnvironmentURLs(userId: userId)?.base, baseUrl == environmentService.baseURL { return userId } @@ -1053,7 +1053,7 @@ extension DefaultAuthRepository: AuthRepository { isUnlocked: displayAsUnlocked, userId: account.profile.userId, userInitials: account.initials(), - webVault: account.settings.environmentUrls?.webVaultHost ?? "" + webVault: account.settings.environmentURLs?.webVaultHost ?? "" ) } diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift index 4c553fc3f..17795c443 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift @@ -296,7 +296,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo func test_existingAccountUserId() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrls["1"] = .defaultUS + stateService.environmentURLs["1"] = .defaultUS stateService.isAuthenticated["1"] = true stateService.userIds = ["1"] @@ -306,10 +306,10 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo } /// `existingAccountUserId(email:)` returns `nil` if getting the environment URLs throws an error. - func test_existingAccountUserId_getEnvironmentUrlsError() async throws { + func test_existingAccountUserId_getEnvironmentURLsError() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrlsError = StateServiceError.noAccounts + stateService.environmentURLsError = StateServiceError.noAccounts stateService.isAuthenticated["1"] = true stateService.userIds = ["1"] @@ -322,7 +322,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo func test_existingAccountUserId_isAuthenticatedError() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrls["1"] = .defaultUS + stateService.environmentURLs["1"] = .defaultUS stateService.isAuthenticatedError = BitwardenTestError.example stateService.userIds = ["1"] @@ -337,7 +337,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo func test_existingAccountUserId_matchingAccountDifferentBaseUrl() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrls["1"] = .defaultUS + stateService.environmentURLs["1"] = .defaultUS stateService.isAuthenticated["1"] = true stateService.userIds = ["1"] @@ -350,8 +350,8 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// there are multiple matches for the user's email. func test_existingAccountUserId_multipleMatching() async throws { stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrls["1"] = .defaultUS - stateService.environmentUrls["2"] = .defaultEU + stateService.environmentURLs["1"] = .defaultUS + stateService.environmentURLs["2"] = .defaultEU stateService.isAuthenticated["1"] = true stateService.isAuthenticated["2"] = true stateService.userIds = ["1", "2"] @@ -370,7 +370,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo func test_existingAccountUserId_notAuthenticated() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) - stateService.environmentUrls["1"] = .defaultUS + stateService.environmentURLs["1"] = .defaultUS stateService.isAuthenticated["1"] = false stateService.userIds = ["1"] @@ -1572,9 +1572,9 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo } /// `setActiveAccount(userId: )` loads the environment URLs for the active account. - func test_setActiveAccount_loadsEnvironmentUrls() async throws { + func test_setActiveAccount_loadsEnvironmentURLs() async throws { let urls = EnvironmentURLData(base: .example) - let account = Account.fixture(settings: .fixture(environmentUrls: urls)) + let account = Account.fixture(settings: .fixture(environmentURLs: urls)) stateService.accounts = [account] _ = try await subject.setActiveAccount(userId: account.profile.userId) XCTAssertTrue(environmentService.didLoadURLsForActiveAccount) diff --git a/BitwardenShared/Core/Auth/Services/AuthService.swift b/BitwardenShared/Core/Auth/Services/AuthService.swift index ad30ce864..b124e5c79 100644 --- a/BitwardenShared/Core/Auth/Services/AuthService.swift +++ b/BitwardenShared/Core/Auth/Services/AuthService.swift @@ -884,8 +884,8 @@ class DefaultAuthService: AuthService { // swiftlint:disable:this type_body_leng } // Create the account. - let urls = await stateService.getPreAuthEnvironmentUrls() - let account = try Account(identityTokenResponseModel: identityTokenResponse, environmentUrls: urls) + let urls = await stateService.getPreAuthEnvironmentURLs() + let account = try Account(identityTokenResponseModel: identityTokenResponse, environmentURLs: urls) try await saveAccount(account, identityTokenResponse: identityTokenResponse) // Get the config so it gets updated for this particular user. diff --git a/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift b/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift index 9a62e20da..fc05bc508 100644 --- a/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift +++ b/BitwardenShared/Core/Auth/Services/AuthServiceTests.swift @@ -334,7 +334,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ ] appSettingsStore.appId = "App id" clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -407,7 +407,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.importLoginsFlow] = true configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = false - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -481,7 +481,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = true stateService.accountSetupAutofillError = BitwardenTestError.example - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -513,7 +513,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ configService.featureFlagsBool[.importLoginsFlow] = true configService.featureFlagsBool[.nativeCreateAccountFlow] = true credentialIdentityStore.state.mockIsEnabled = true - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -541,7 +541,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" clientService.mockAuth.hashPasswordResult = .success("hashed password") clientService.mockAuth.satisfiesPolicyResult = false - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -597,7 +597,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -659,7 +659,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ IdentityTokenResponseModel.self, from: APITestData.identityTokenKeyConnectorMasterPassword.data ) - let account = try Account(identityTokenResponseModel: response, environmentUrls: nil) + let account = try Account(identityTokenResponseModel: response, environmentURLs: nil) XCTAssertEqual( unlockMethod, @@ -683,7 +683,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ // Set up the mock data. appSettingsStore.appId = "App id" client.result = .httpSuccess(testData: .identityTokenSuccess) - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // Attempt to login. @@ -745,7 +745,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // First login with the master password so that the request will be saved. @@ -862,7 +862,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" let policy = MasterPasswordPolicyOptions( @@ -926,7 +926,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" let policy = MasterPasswordPolicyOptions( @@ -1095,7 +1095,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ appSettingsStore.appId = "App id" await stateService.setTwoFactorToken("some token", email: "email@example.com") clientService.mockAuth.hashPasswordResult = .success("hashed password") - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")) systemDevice.modelIdentifier = "Model id" // First login with the master password so that the resend email request will be saved. diff --git a/BitwardenShared/Core/Platform/Models/Domain/Account.swift b/BitwardenShared/Core/Platform/Models/Domain/Account.swift index 99d899e58..2a2601fb1 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Account.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Account.swift @@ -45,11 +45,11 @@ extension Account { /// /// - Parameters: /// - identityTokenResponseModel: The response model from the identity token request. - /// - environmentUrls: The environment URLs for an account. + /// - environmentURLs: The environment URLs for an account. /// init( identityTokenResponseModel: IdentityTokenResponseModel, - environmentUrls: EnvironmentURLData? + environmentURLs: EnvironmentURLData? ) throws { let tokenPayload = try TokenParser.parseToken(identityTokenResponseModel.accessToken) self.init( @@ -71,7 +71,7 @@ extension Account { userId: tokenPayload.userId ), settings: AccountSettings( - environmentUrls: environmentUrls + environmentURLs: environmentURLs ), _tokens: nil // Tokens have been moved out of `State` to the keychain. ) @@ -132,7 +132,7 @@ extension Account { // MARK: Properties /// The environment URLs for an account. - var environmentUrls: EnvironmentURLData? + var environmentURLs: EnvironmentURLData? } /// Domain model for an account's API tokens. diff --git a/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift b/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift index 1bf7f44a7..2fd25c5e1 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift @@ -30,7 +30,7 @@ class AccountTests: BitwardenTestCase { let accessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTY5MDg4NzksInN1YiI6IjEzNTEyNDY3LTljZmUtNDNiMC05NjlmLTA3NTM0MDg0NzY0YiIsIm5hbWUiOiJCaXR3YXJkZW4gVXNlciIsImVtYWlsIjoidXNlckBiaXR3YXJkZW4uY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImlhdCI6MTUxNjIzOTAyMiwicHJlbWl1bSI6ZmFsc2UsImFtciI6WyJBcHBsaWNhdGlvbiJdfQ.KDqC8kUaOAgBiUY8eeLa0a4xYWN8GmheXTFXmataFwM" let subject = try Account( identityTokenResponseModel: .fixture(accessToken: accessToken), - environmentUrls: nil + environmentURLs: nil ) XCTAssertEqual( @@ -56,7 +56,7 @@ class AccountTests: BitwardenTestCase { ), userId: "13512467-9cfe-43b0-969f-07534084764b" ), - settings: Account.AccountSettings(environmentUrls: nil), + settings: Account.AccountSettings(environmentURLs: nil), _tokens: nil ) ) diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift index b48f37243..f0bce9e23 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrls.swift @@ -2,7 +2,7 @@ import Foundation /// A wrapper around non-optional URLs that the app uses in its environment. /// -struct EnvironmentUrls: Equatable { +struct EnvironmentURLs: Equatable { // MARK: Properties /// The URL for the API. @@ -42,10 +42,10 @@ struct EnvironmentUrls: Equatable { let webVaultURL: URL } -extension EnvironmentUrls { - /// Initialize `EnvironmentUrls` from `EnvironmentURLData`. +extension EnvironmentURLs { + /// Initialize `EnvironmentURLs` from `EnvironmentURLData`. /// - /// - Parameter environmentURLData: The environment URLs used to initialize `EnvironmentUrls`. + /// - Parameter environmentURLData: The environment URLs used to initialize `EnvironmentURLs`. /// init(environmentURLData: EnvironmentURLData) { // Use the default URLs if the region matches US or EU. diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift index 3bef41d80..f7f653884 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift @@ -2,17 +2,17 @@ import XCTest @testable import BitwardenShared -class EnvironmentUrlsTests: BitwardenTestCase { +class EnvironmentURLsTests: BitwardenTestCase { // MARK: Tests /// `init(environmentURLData:)` sets the URLs from the passed data when such data is the default US. func test_init_environmentURLData_defaultUS() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData.defaultUS ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.bitwarden.com")!, baseURL: URL(string: "https://vault.bitwarden.com")!, changeEmailURL: URL(string: "https://vault.bitwarden.com/#/settings/account")!, @@ -31,12 +31,12 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs from the passed data when such data is the default EU. func test_init_environmentURLData_defaultEU() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData.defaultEU ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.bitwarden.eu")!, baseURL: URL(string: "https://vault.bitwarden.eu")!, changeEmailURL: URL(string: "https://vault.bitwarden.eu/#/settings/account")!, @@ -56,12 +56,12 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs from the base URL if one is set and is not /// `.unitedStates` nor `.europe` region type. func test_init_environmentURLData_baseUrl() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com")!) ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://example.com/api")!, baseURL: URL(string: "https://example.com")!, changeEmailURL: URL(string: "https://example.com/#/settings/account")!, @@ -80,12 +80,12 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` defaults to the pre-defined EU URLs if the base URL matches the EU environment. func test_init_environmentURLData_baseUrl_europe() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.bitwarden.eu")!, baseURL: URL(string: "https://vault.bitwarden.eu")!, changeEmailURL: URL(string: "https://vault.bitwarden.eu/#/settings/account")!, @@ -104,12 +104,12 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` defaults to the pre-defined US URLs if the base URL matches the US environment. func test_init_environmentURLData_baseUrl_unitedStates() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.bitwarden.com")!, baseURL: URL(string: "https://vault.bitwarden.com")!, changeEmailURL: URL(string: "https://vault.bitwarden.com/#/settings/account")!, @@ -128,12 +128,12 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs from the base URL which includes a trailing slash. func test_init_environmentURLData_baseUrlWithTrailingSlash() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com/")!) ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://example.com/api")!, baseURL: URL(string: "https://example.com/")!, changeEmailURL: URL(string: "https://example.com/#/settings/account")!, @@ -152,7 +152,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs based on the corresponding URL if there isn't a base URL. func test_init_environmentURLData_custom() { - let subject = EnvironmentUrls( + let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData( api: URL(string: "https://api.example.com")!, events: URL(string: "https://events.example.com")!, @@ -163,7 +163,7 @@ class EnvironmentUrlsTests: BitwardenTestCase { ) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.example.com")!, baseURL: URL(string: "https://vault.bitwarden.com")!, changeEmailURL: URL(string: "https://example.com/#/settings/account")!, @@ -182,10 +182,10 @@ class EnvironmentUrlsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs to default values if the URLs are empty. func test_init_environmentURLData_empty() { - let subject = EnvironmentUrls(environmentURLData: EnvironmentURLData()) + let subject = EnvironmentURLs(environmentURLData: EnvironmentURLData()) XCTAssertEqual( subject, - EnvironmentUrls( + EnvironmentURLs( apiURL: URL(string: "https://api.bitwarden.com")!, baseURL: URL(string: "https://vault.bitwarden.com")!, changeEmailURL: URL(string: "https://vault.bitwarden.com")!, diff --git a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift index 163905475..672b669a6 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift @@ -30,7 +30,7 @@ extension Account { userId: "13512467-9cfe-43b0-969f-07534084764b" ), settings: Account.AccountSettings( - environmentUrls: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) + environmentURLs: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ), tokens: nil ) @@ -115,10 +115,10 @@ extension Account.AccountProfile { extension Account.AccountSettings { static func fixture( - environmentUrls: EnvironmentURLData? = .fixture() + environmentURLs: EnvironmentURLData? = .fixture() ) -> Account.AccountSettings { Account.AccountSettings( - environmentUrls: environmentUrls + environmentURLs: environmentURLs ) } } diff --git a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift index 0742d5f86..e5a9f879d 100644 --- a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift +++ b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift @@ -223,7 +223,7 @@ actor DefaultAuthenticatorSyncService: NSObject, AuthenticatorSyncService { return decryptedCiphers.map { cipher in AuthenticatorBridgeItemDataView( - accountDomain: account.settings.environmentUrls?.webVaultHost ?? Constants.defaultWebVaultHost, + accountDomain: account.settings.environmentURLs?.webVaultHost ?? Constants.defaultWebVaultHost, accountEmail: account.profile.email, favorite: false, id: cipher.id ?? UUID().uuidString, diff --git a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncServiceTests.swift b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncServiceTests.swift index aa6ed9905..ef8a1ca70 100644 --- a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncServiceTests.swift @@ -574,7 +574,7 @@ final class AuthenticatorSyncServiceTests: BitwardenTestCase { // swiftlint:disa await stateService.addAccount(.fixture( profile: .fixture(email: "different@bitwarden.com", userId: "2"), - settings: .fixture(environmentUrls: .fixture(webVault: URL(string: "https://vault.example.com"))) + settings: .fixture(environmentURLs: .fixture(webVault: URL(string: "https://vault.example.com"))) )) stateService.syncToAuthenticatorByUserId["2"] = true vaultTimeoutService.isClientLocked["2"] = false diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift index 8c20ad220..e52a3b101 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift @@ -75,7 +75,7 @@ class DefaultEnvironmentService: EnvironmentService { // MARK: Private Properties /// The app's current environment URLs. - private var environmentUrls: EnvironmentUrls + private var environmentURLs: EnvironmentURLs /// The shared UserDefaults instance (NOTE: this should be the standard one just for the app, /// not one in the app group). @@ -95,7 +95,7 @@ class DefaultEnvironmentService: EnvironmentService { self.stateService = stateService self.standardUserDefaults = standardUserDefaults - environmentUrls = EnvironmentUrls(environmentURLData: .defaultUS) + environmentURLs = EnvironmentURLs(environmentURLData: .defaultUS) } // MARK: EnvironmentService @@ -103,33 +103,33 @@ class DefaultEnvironmentService: EnvironmentService { func loadURLsForActiveAccount() async { let urls: EnvironmentURLData let managedSettingsUrls = managedSettingsUrls() - if let environmentUrls = try? await stateService.getEnvironmentUrls() { - urls = environmentUrls + if let environmentURLs = try? await stateService.getEnvironmentURLs() { + urls = environmentURLs } else if let managedSettingsUrls { urls = managedSettingsUrls - } else if let preAuthUrls = await stateService.getPreAuthEnvironmentUrls() { + } else if let preAuthUrls = await stateService.getPreAuthEnvironmentURLs() { urls = preAuthUrls } else { urls = .defaultUS } await setPreAuthURLs(urls: managedSettingsUrls ?? urls) - environmentUrls = EnvironmentUrls(environmentURLData: urls) + environmentURLs = EnvironmentURLs(environmentURLData: urls) errorReporter.setRegion(region.errorReporterName, isPreAuth: false) // swiftformat:disable:next redundantSelf - Logger.application.info("Loaded environment URLs: \(String(describing: self.environmentUrls))") + Logger.application.info("Loaded environment URLs: \(String(describing: self.environmentURLs))") } func setPreAuthURLs(urls: EnvironmentURLData) async { - await stateService.setPreAuthEnvironmentUrls(urls) - environmentUrls = EnvironmentUrls(environmentURLData: urls) + await stateService.setPreAuthEnvironmentURLs(urls) + environmentURLs = EnvironmentURLs(environmentURLData: urls) errorReporter.setRegion(region.errorReporterName, isPreAuth: true) // swiftformat:disable:next redundantSelf - Logger.application.info("Setting pre-auth URLs: \(String(describing: self.environmentUrls))") + Logger.application.info("Setting pre-auth URLs: \(String(describing: self.environmentURLs))") } // MARK: Private @@ -151,41 +151,41 @@ class DefaultEnvironmentService: EnvironmentService { extension DefaultEnvironmentService { var apiURL: URL { - environmentUrls.apiURL + environmentURLs.apiURL } var baseURL: URL { - environmentUrls.baseURL + environmentURLs.baseURL } var changeEmailURL: URL { - environmentUrls.changeEmailURL + environmentURLs.changeEmailURL } var eventsURL: URL { - environmentUrls.eventsURL + environmentURLs.eventsURL } var iconsURL: URL { - environmentUrls.iconsURL + environmentURLs.iconsURL } var identityURL: URL { - environmentUrls.identityURL + environmentURLs.identityURL } var importItemsURL: URL { - environmentUrls.importItemsURL + environmentURLs.importItemsURL } var recoveryCodeURL: URL { - environmentUrls.recoveryCodeURL + environmentURLs.recoveryCodeURL } var region: RegionType { - if environmentUrls.baseURL == EnvironmentURLData.defaultUS.base { + if environmentURLs.baseURL == EnvironmentURLData.defaultUS.base { return .unitedStates - } else if environmentUrls.baseURL == EnvironmentURLData.defaultEU.base { + } else if environmentURLs.baseURL == EnvironmentURLData.defaultEU.base { return .europe } else { return .selfHosted @@ -193,18 +193,18 @@ extension DefaultEnvironmentService { } var sendShareURL: URL { - environmentUrls.sendShareURL + environmentURLs.sendShareURL } var settingsURL: URL { - environmentUrls.settingsURL + environmentURLs.settingsURL } var setUpTwoFactorURL: URL { - environmentUrls.setUpTwoFactorURL + environmentURLs.setUpTwoFactorURL } var webVaultURL: URL { - environmentUrls.webVaultURL + environmentURLs.webVaultURL } } diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift b/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift index 5f49c6855..8eca11254 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentServiceTests.swift @@ -59,9 +59,9 @@ class EnvironmentServiceTests: XCTestCase { /// `loadURLsForActiveAccount()` loads the URLs for the active account. func test_loadURLsForActiveAccount() async { let urls = EnvironmentURLData(base: .example) - let account = Account.fixture(settings: .fixture(environmentUrls: urls)) + let account = Account.fixture(settings: .fixture(environmentURLs: urls)) stateService.activeAccount = account - stateService.environmentUrls = [account.profile.userId: urls] + stateService.environmentURLs = [account.profile.userId: urls] await subject.loadURLsForActiveAccount() @@ -78,7 +78,7 @@ class EnvironmentServiceTests: XCTestCase { XCTAssertEqual(subject.settingsURL, URL(string: "https://example.com/#/settings")) XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://example.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://example.com")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) XCTAssertEqual(errorReporter.region?.region, "Self-Hosted") XCTAssertEqual(errorReporter.region?.isPreAuth, false) @@ -87,9 +87,9 @@ class EnvironmentServiceTests: XCTestCase { /// `loadURLsForActiveAccount()` handles EU URLs func test_loadURLsForActiveAccount_europe() async { let urls = EnvironmentURLData.defaultEU - let account = Account.fixture(settings: .fixture(environmentUrls: urls)) + let account = Account.fixture(settings: .fixture(environmentURLs: urls)) stateService.activeAccount = account - stateService.environmentUrls = [account.profile.userId: urls] + stateService.environmentURLs = [account.profile.userId: urls] await subject.loadURLsForActiveAccount() @@ -107,7 +107,7 @@ class EnvironmentServiceTests: XCTestCase { // swiftlint:disable:next line_length XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://vault.bitwarden.eu/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://vault.bitwarden.eu")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) XCTAssertEqual(errorReporter.region?.region, "EU") XCTAssertEqual(errorReporter.region?.isPreAuth, false) @@ -137,7 +137,7 @@ class EnvironmentServiceTests: XCTestCase { // swiftlint:disable:next line_length XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://vault.example.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://vault.example.com")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) } /// `loadURLsForActiveAccount()` doesn't load the managed config URLs if there's an active @@ -145,7 +145,7 @@ class EnvironmentServiceTests: XCTestCase { func test_loadURLsForActiveAccount_managedConfigActiveAccount() async throws { let account = Account.fixture() stateService.activeAccount = account - stateService.environmentUrls[account.profile.userId] = .defaultUS + stateService.environmentURLs[account.profile.userId] = .defaultUS standardUserDefaults.setValue( ["baseEnvironmentUrl": "https://vault.example.com"], forKey: "com.apple.configuration.managed" @@ -169,7 +169,7 @@ class EnvironmentServiceTests: XCTestCase { XCTAssertEqual(subject.webVaultURL, URL(string: "https://vault.bitwarden.com")) let urls = try EnvironmentURLData(base: XCTUnwrap(URL(string: "https://vault.example.com"))) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) } /// `loadURLsForActiveAccount()` loads the default URLs if there's no active account @@ -191,7 +191,7 @@ class EnvironmentServiceTests: XCTestCase { // swiftlint:disable:next line_length XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://vault.bitwarden.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://vault.bitwarden.com")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, .defaultUS) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, .defaultUS) XCTAssertEqual(errorReporter.region?.region, "US") XCTAssertEqual(errorReporter.region?.isPreAuth, false) @@ -201,7 +201,7 @@ class EnvironmentServiceTests: XCTestCase { /// and there are preauth URLs. func test_loadURLsForActiveAccount_preAuth() async { let urls = EnvironmentURLData(base: .example) - stateService.preAuthEnvironmentUrls = urls + stateService.preAuthEnvironmentURLs = urls await subject.loadURLsForActiveAccount() @@ -219,7 +219,7 @@ class EnvironmentServiceTests: XCTestCase { // swiftlint:disable:next line_length XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://example.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://example.com")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) XCTAssertEqual(errorReporter.region?.region, "Self-Hosted") XCTAssertEqual(errorReporter.region?.isPreAuth, false) @@ -245,7 +245,7 @@ class EnvironmentServiceTests: XCTestCase { // swiftlint:disable:next line_length XCTAssertEqual(subject.setUpTwoFactorURL, URL(string: "https://example.com/#/settings/security/two-factor")) XCTAssertEqual(subject.webVaultURL, URL(string: "https://example.com")) - XCTAssertEqual(stateService.preAuthEnvironmentUrls, urls) + XCTAssertEqual(stateService.preAuthEnvironmentURLs, urls) XCTAssertEqual(errorReporter.region?.region, "Self-Hosted") XCTAssertEqual(errorReporter.region?.isPreAuth, true) } diff --git a/BitwardenShared/Core/Platform/Services/StateService.swift b/BitwardenShared/Core/Platform/Services/StateService.swift index 7712cfdf0..c4a5b2094 100644 --- a/BitwardenShared/Core/Platform/Services/StateService.swift +++ b/BitwardenShared/Core/Platform/Services/StateService.swift @@ -180,7 +180,7 @@ protocol StateService: AnyObject { /// - Parameter userId: The user ID associated with the environment URLs. /// - Returns: The user's environment URLs. /// - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? + func getEnvironmentURLs(userId: String?) async throws -> EnvironmentURLData? /// Gets the events stored to disk to be uploaded in the future. /// @@ -254,14 +254,14 @@ protocol StateService: AnyObject { /// /// - Returns: The environment URLs used prior to user authentication. /// - func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? + func getPreAuthEnvironmentURLs() async -> EnvironmentURLData? /// Gets the environment URLs for a given email during account creation. /// /// - Parameter email: The email used to start the account creation. /// - Returns: The environment URLs used prior to start the account creation. /// - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? + func getAccountCreationEnvironmentURLs(email: String) async -> EnvironmentURLData? /// Gets the server config used by the app prior to the user authenticating. /// - Returns: The server config used prior to user authentication. @@ -581,14 +581,14 @@ protocol StateService: AnyObject { /// /// - Parameter urls: The environment URLs used prior to user authentication. /// - func setPreAuthEnvironmentUrls(_ urls: EnvironmentURLData) async + func setPreAuthEnvironmentURLs(_ urls: EnvironmentURLData) async /// Sets the environment URLs for a given email during account creation. /// - Parameters: /// - urls: The environment urls used to start the account creation. /// - email: The email used to start the account creation. /// - func setAccountCreationEnvironmentUrls(urls: EnvironmentURLData, email: String) async + func setAccountCreationEnvironmentURLs(urls: EnvironmentURLData, email: String) async /// Sets the server config used prior to user authentication /// - Parameter config: The server config to use prior to user authentication. @@ -867,8 +867,8 @@ extension StateService { /// /// - Returns: The environment URLs for the active account. /// - func getEnvironmentUrls() async throws -> EnvironmentURLData? { - try await getEnvironmentUrls(userId: nil) + func getEnvironmentURLs() async throws -> EnvironmentURLData? { + try await getEnvironmentURLs(userId: nil) } /// Gets the user's last active time within the app. @@ -1450,9 +1450,9 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le return appSettingsStore.encryptedPin(userId: userId) } - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? { + func getEnvironmentURLs(userId: String?) async throws -> EnvironmentURLData? { let userId = try userId ?? getActiveAccountUserId() - return appSettingsStore.state?.accounts[userId]?.settings.environmentUrls + return appSettingsStore.state?.accounts[userId]?.settings.environmentURLs } func getEvents(userId: String?) async throws -> [EventData] { @@ -1502,12 +1502,12 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le return appSettingsStore.passwordGenerationOptions(userId: userId) } - func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? { - appSettingsStore.preAuthEnvironmentUrls + func getPreAuthEnvironmentURLs() async -> EnvironmentURLData? { + appSettingsStore.preAuthEnvironmentURLs } - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? { - appSettingsStore.accountCreationEnvironmentUrls(email: email) + func getAccountCreationEnvironmentURLs(email: String) async -> EnvironmentURLData? { + appSettingsStore.accountCreationEnvironmentURLs(email: email) } func getPreAuthServerConfig() async -> ServerConfig? { @@ -1786,12 +1786,12 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le ].pinProtectedUserKey = pinProtectedUserKey } - func setPreAuthEnvironmentUrls(_ urls: EnvironmentURLData) async { - appSettingsStore.preAuthEnvironmentUrls = urls + func setPreAuthEnvironmentURLs(_ urls: EnvironmentURLData) async { + appSettingsStore.preAuthEnvironmentURLs = urls } - func setAccountCreationEnvironmentUrls(urls: EnvironmentURLData, email: String) async { - appSettingsStore.setAccountCreationEnvironmentUrls( + func setAccountCreationEnvironmentURLs(urls: EnvironmentURLData, email: String) async { + appSettingsStore.setAccountCreationEnvironmentURLs( environmentURLData: urls, email: email ) diff --git a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift index 225930cc4..c8565618e 100644 --- a/BitwardenShared/Core/Platform/Services/StateServiceTests.swift +++ b/BitwardenShared/Core/Platform/Services/StateServiceTests.swift @@ -619,32 +619,32 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body XCTAssertEqual(pinProtectedUserKey, "321") } - /// `getEnvironmentUrls()` returns the environment URLs for the active account. - func test_getEnvironmentUrls() async throws { + /// `getEnvironmentURLs()` returns the environment URLs for the active account. + func test_getEnvironmentURLs() async throws { let urls = EnvironmentURLData(base: .example) - let account = Account.fixture(settings: .fixture(environmentUrls: urls)) + let account = Account.fixture(settings: .fixture(environmentURLs: urls)) appSettingsStore.state = State( accounts: [account.profile.userId: account], activeUserId: account.profile.userId ) - let accountUrls = try await subject.getEnvironmentUrls() + let accountUrls = try await subject.getEnvironmentURLs() XCTAssertEqual(accountUrls, urls) } - /// `getEnvironmentUrls()` returns `nil` if the active account doesn't have URLs set. - func test_getEnvironmentUrls_notSet() async throws { - let account = Account.fixture(settings: .fixture(environmentUrls: nil)) + /// `getEnvironmentURLs()` returns `nil` if the active account doesn't have URLs set. + func test_getEnvironmentURLs_notSet() async throws { + let account = Account.fixture(settings: .fixture(environmentURLs: nil)) appSettingsStore.state = State( accounts: [account.profile.userId: account], activeUserId: account.profile.userId ) - let urls = try await subject.getEnvironmentUrls() + let urls = try await subject.getEnvironmentURLs() XCTAssertNil(urls) } - /// `getEnvironmentUrls()` returns `nil` if the user doesn't exist. - func test_getEnvironmentUrls_noUser() async throws { - let urls = try await subject.getEnvironmentUrls(userId: "-1") + /// `getEnvironmentURLs()` returns `nil` if the user doesn't exist. + func test_getEnvironmentURLs_noUser() async throws { + let urls = try await subject.getEnvironmentURLs(userId: "-1") XCTAssertNil(urls) } @@ -802,32 +802,32 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body XCTAssertNil(fetchedOptionsNoAccount) } - /// `getPreAuthEnvironmentUrls` returns the saved pre-auth URLs. - func test_getPreAuthEnvironmentUrls() async { + /// `getPreAuthEnvironmentURLs` returns the saved pre-auth URLs. + func test_getPreAuthEnvironmentURLs() async { let urls = EnvironmentURLData(base: .example) - appSettingsStore.preAuthEnvironmentUrls = urls - let preAuthUrls = await subject.getPreAuthEnvironmentUrls() + appSettingsStore.preAuthEnvironmentURLs = urls + let preAuthUrls = await subject.getPreAuthEnvironmentURLs() XCTAssertEqual(preAuthUrls, urls) } - /// `getPreAuthEnvironmentUrls` returns `nil` if the URLs haven't been set. - func test_getPreAuthEnvironmentUrls_notSet() async { - let urls = await subject.getPreAuthEnvironmentUrls() + /// `getPreAuthEnvironmentURLs` returns `nil` if the URLs haven't been set. + func test_getPreAuthEnvironmentURLs_notSet() async { + let urls = await subject.getPreAuthEnvironmentURLs() XCTAssertNil(urls) } - /// `getAccountCreationEnvironmentUrls` returns the saved pre-auth URLs for a given email. - func test_getAccountCreationEnvironmentUrls() async { + /// `getAccountCreationEnvironmentURLs` returns the saved pre-auth URLs for a given email. + func test_getAccountCreationEnvironmentURLs() async { let email = "example@email.com" let urls = EnvironmentURLData(base: .example) - appSettingsStore.setAccountCreationEnvironmentUrls(environmentURLData: urls, email: email) - let preAuthUrls = await subject.getAccountCreationEnvironmentUrls(email: email) + appSettingsStore.setAccountCreationEnvironmentURLs(environmentURLData: urls, email: email) + let preAuthUrls = await subject.getAccountCreationEnvironmentURLs(email: email) XCTAssertEqual(preAuthUrls, urls) } - /// `getAccountCreationEnvironmentUrls` returns `nil` if the URLs haven't been set for a given email. - func test_getAccountCreationEnvironmentUrls_notSet() async { - let urls = await subject.getAccountCreationEnvironmentUrls(email: "example@email.com") + /// `getAccountCreationEnvironmentURLs` returns `nil` if the URLs haven't been set for a given email. + func test_getAccountCreationEnvironmentURLs_notSet() async { + let urls = await subject.getAccountCreationEnvironmentURLs(email: "example@email.com") XCTAssertNil(urls) } @@ -1817,19 +1817,19 @@ class StateServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body XCTAssertEqual(appSettingsStore.encryptedPinByUserId["1"], "encryptedPin") } - /// `setPreAuthEnvironmentUrls` saves the pre-auth URLs. - func test_setPreAuthEnvironmentUrls() async { + /// `setPreAuthEnvironmentURLs` saves the pre-auth URLs. + func test_setPreAuthEnvironmentURLs() async { let urls = EnvironmentURLData(base: .example) - await subject.setPreAuthEnvironmentUrls(urls) - XCTAssertEqual(appSettingsStore.preAuthEnvironmentUrls, urls) + await subject.setPreAuthEnvironmentURLs(urls) + XCTAssertEqual(appSettingsStore.preAuthEnvironmentURLs, urls) } - /// `test_setAccountCreationEnvironmentUrls` saves the pre-auth URLs for email for a given email. - func test_setAccountCreationEnvironmentUrls() async { + /// `test_setAccountCreationEnvironmentURLs` saves the pre-auth URLs for email for a given email. + func test_setAccountCreationEnvironmentURLs() async { let email = "example@email.com" let urls = EnvironmentURLData(base: .example) - await subject.setAccountCreationEnvironmentUrls(urls: urls, email: email) - XCTAssertEqual(appSettingsStore.accountCreationEnvironmentUrls(email: email), urls) + await subject.setAccountCreationEnvironmentURLs(urls: urls, email: email) + XCTAssertEqual(appSettingsStore.accountCreationEnvironmentURLs(email: email), urls) } /// `setPreAuthServerConfig(config:)` saves the pre-auth server config. diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift index 989ec68b8..769380522 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift @@ -43,7 +43,7 @@ protocol AppSettingsStore: AnyObject { var migrationVersion: Int { get set } /// The environment URLs used prior to user authentication. - var preAuthEnvironmentUrls: EnvironmentURLData? { get set } + var preAuthEnvironmentURLs: EnvironmentURLData? { get set } /// The server config used prior to user authentication. var preAuthServerConfig: ServerConfig? { get set } @@ -238,7 +238,7 @@ protocol AppSettingsStore: AnyObject { /// - email: The email used to start the account creation. /// - Returns: The environment URLs used prior to start the account creation. /// - func accountCreationEnvironmentUrls(email: String) -> EnvironmentURLData? + func accountCreationEnvironmentURLs(email: String) -> EnvironmentURLData? /// The server configuration. /// @@ -420,7 +420,7 @@ protocol AppSettingsStore: AnyObject { /// - email: The user's email address. /// - environmentURLData: The environment data to be saved. /// - func setAccountCreationEnvironmentUrls(environmentURLData: EnvironmentURLData, email: String) + func setAccountCreationEnvironmentURLs(environmentURLData: EnvironmentURLData, email: String) /// Sets the server config. /// @@ -703,8 +703,8 @@ extension DefaultAppSettingsStore: AppSettingsStore { case notificationsLastRegistrationDate(userId: String) case passwordGenerationOptions(userId: String) case pinProtectedUserKey(userId: String) - case preAuthEnvironmentUrls - case accountCreationEnvironmentUrls(email: String) + case preAuthEnvironmentURLs + case accountCreationEnvironmentURLs(email: String) case preAuthServerConfig case rememberedEmail case rememberedOrgIdentifier @@ -786,10 +786,10 @@ extension DefaultAppSettingsStore: AppSettingsStore { key = "passwordGenerationOptions_\(userId)" case let .pinProtectedUserKey(userId): key = "pinKeyEncryptedUserKey_\(userId)" - case .preAuthEnvironmentUrls: - key = "preAuthEnvironmentUrls" - case let .accountCreationEnvironmentUrls(email): - key = "accountCreationEnvironmentUrls_\(email)" + case .preAuthEnvironmentURLs: + key = "preAuthEnvironmentURLs" + case let .accountCreationEnvironmentURLs(email): + key = "accountCreationEnvironmentURLs_\(email)" case .preAuthServerConfig: key = "preAuthServerConfig" case .rememberedEmail: @@ -872,9 +872,9 @@ extension DefaultAppSettingsStore: AppSettingsStore { set { store(newValue, for: .migrationVersion) } } - var preAuthEnvironmentUrls: EnvironmentURLData? { - get { fetch(for: .preAuthEnvironmentUrls) } - set { store(newValue, for: .preAuthEnvironmentUrls) } + var preAuthEnvironmentURLs: EnvironmentURLData? { + get { fetch(for: .preAuthEnvironmentURLs) } + set { store(newValue, for: .preAuthEnvironmentURLs) } } var preAuthServerConfig: ServerConfig? { @@ -1001,9 +1001,9 @@ extension DefaultAppSettingsStore: AppSettingsStore { fetch(for: .pinProtectedUserKey(userId: userId)) } - func accountCreationEnvironmentUrls(email: String) -> EnvironmentURLData? { + func accountCreationEnvironmentURLs(email: String) -> EnvironmentURLData? { fetch( - for: .accountCreationEnvironmentUrls(email: email) + for: .accountCreationEnvironmentURLs(email: email) ) } @@ -1095,8 +1095,8 @@ extension DefaultAppSettingsStore: AppSettingsStore { store(key, for: .pinProtectedUserKey(userId: userId)) } - func setAccountCreationEnvironmentUrls(environmentURLData: EnvironmentURLData, email: String) { - store(environmentURLData, for: .accountCreationEnvironmentUrls(email: email)) + func setAccountCreationEnvironmentURLs(environmentURLData: EnvironmentURLData, email: String) { + store(environmentURLData, for: .accountCreationEnvironmentURLs(email: email)) } func setServerConfig(_ config: ServerConfig?, userId: String) { diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift index fe7f81c86..92545eafc 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift @@ -681,35 +681,35 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ XCTAssertEqual(userDefaults.string(forKey: "bwPreferencesStorage:pinKeyEncryptedUserKey_1"), pin) } - /// `preAuthEnvironmentUrls` returns `nil` if there isn't a previously stored value. - func test_preAuthEnvironmentUrls_isInitiallyNil() { - XCTAssertNil(subject.preAuthEnvironmentUrls) + /// `preAuthEnvironmentURLs` returns `nil` if there isn't a previously stored value. + func test_preAuthEnvironmentURLs_isInitiallyNil() { + XCTAssertNil(subject.preAuthEnvironmentURLs) } - /// `preAuthEnvironmentUrls` can be used to get and set the persisted value in user defaults. - func test_preAuthEnvironmentUrls_withValue() { - subject.preAuthEnvironmentUrls = .defaultUS - XCTAssertEqual(subject.preAuthEnvironmentUrls, .defaultUS) + /// `preAuthEnvironmentURLs` can be used to get and set the persisted value in user defaults. + func test_preAuthEnvironmentURLs_withValue() { + subject.preAuthEnvironmentURLs = .defaultUS + XCTAssertEqual(subject.preAuthEnvironmentURLs, .defaultUS) try XCTAssertEqual( JSONDecoder().decode( EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? + .string(forKey: "bwPreferencesStorage:preAuthEnvironmentURLs")? .data(using: .utf8) ) ), .defaultUS ) - subject.preAuthEnvironmentUrls = .defaultEU - XCTAssertEqual(subject.preAuthEnvironmentUrls, .defaultEU) + subject.preAuthEnvironmentURLs = .defaultEU + XCTAssertEqual(subject.preAuthEnvironmentURLs, .defaultEU) try XCTAssertEqual( JSONDecoder().decode( EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? + .string(forKey: "bwPreferencesStorage:preAuthEnvironmentURLs")? .data(using: .utf8) ) ), @@ -717,36 +717,36 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ ) } - /// `accountCreationEnvironmentUrls` returns `nil` if there isn't a previously stored value. - func test_accountCreationEnvironmentUrls_isInitiallyNil() { - XCTAssertNil(subject.accountCreationEnvironmentUrls(email: "example@email.com")) + /// `accountCreationEnvironmentURLs` returns `nil` if there isn't a previously stored value. + func test_accountCreationEnvironmentURLs_isInitiallyNil() { + XCTAssertNil(subject.accountCreationEnvironmentURLs(email: "example@email.com")) } - /// `accountCreationEnvironmentUrls` can be used to get and set the persisted value in user defaults. - func test_accountCreationEnvironmentUrls_withValue() { + /// `accountCreationEnvironmentURLs` can be used to get and set the persisted value in user defaults. + func test_accountCreationEnvironmentURLs_withValue() { let email = "example@email.com" - subject.setAccountCreationEnvironmentUrls(environmentURLData: .defaultUS, email: email) - XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultUS) + subject.setAccountCreationEnvironmentURLs(environmentURLData: .defaultUS, email: email) + XCTAssertEqual(subject.accountCreationEnvironmentURLs(email: email), .defaultUS) try XCTAssertEqual( JSONDecoder().decode( EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? + .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentURLs_\(email)")? .data(using: .utf8) ) ), .defaultUS ) - subject.setAccountCreationEnvironmentUrls(environmentURLData: .defaultEU, email: email) - XCTAssertEqual(subject.accountCreationEnvironmentUrls(email: email), .defaultEU) + subject.setAccountCreationEnvironmentURLs(environmentURLData: .defaultEU, email: email) + XCTAssertEqual(subject.accountCreationEnvironmentURLs(email: email), .defaultEU) try XCTAssertEqual( JSONDecoder().decode( EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? + .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentURLs_\(email)")? .data(using: .utf8) ) ), diff --git a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift index 863fc54fc..9e2199553 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/TestHelpers/MockAppSettingsStore.swift @@ -20,7 +20,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo var loginRequest: LoginRequestNotification? var migrationVersion = 0 var overrideDebugFeatureFlagCalled = false - var preAuthEnvironmentUrls: EnvironmentURLData? + var preAuthEnvironmentURLs: EnvironmentURLData? var preAuthServerConfig: BitwardenShared.ServerConfig? var rememberedEmail: String? var rememberedOrgIdentifier: String? @@ -43,7 +43,7 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo var notificationsLastRegistrationDates = [String: Date]() var passwordGenerationOptions = [String: PasswordGenerationOptions]() var pinProtectedUserKey = [String: String]() - var accountCreationEnvironmentUrls = [String: EnvironmentURLData]() + var accountCreationEnvironmentURLs = [String: EnvironmentURLData]() var serverConfig = [String: ServerConfig]() var shouldTrustDevice = [String: Bool?]() var syncToAuthenticatorByUserId = [String: Bool]() @@ -151,8 +151,8 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo pinProtectedUserKey[userId] } - func accountCreationEnvironmentUrls(email: String) -> BitwardenShared.EnvironmentURLData? { - accountCreationEnvironmentUrls[email] + func accountCreationEnvironmentURLs(email: String) -> BitwardenShared.EnvironmentURLData? { + accountCreationEnvironmentURLs[email] } func twoFactorToken(email: String) -> String? { @@ -259,8 +259,8 @@ class MockAppSettingsStore: AppSettingsStore { // swiftlint:disable:this type_bo pinProtectedUserKey[userId] = key } - func setAccountCreationEnvironmentUrls(environmentURLData: BitwardenShared.EnvironmentURLData, email: String) { - accountCreationEnvironmentUrls[email] = environmentURLData + func setAccountCreationEnvironmentURLs(environmentURLData: BitwardenShared.EnvironmentURLData, email: String) { + accountCreationEnvironmentURLs[email] = environmentURLData } func setServerConfig(_ config: ServerConfig?, userId: String) { diff --git a/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift b/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift index 3e1be48fe..ba6dc0c78 100644 --- a/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/TestHelpers/MockEnvironmentService.swift @@ -4,8 +4,8 @@ import Foundation class MockEnvironmentService: EnvironmentService { var didLoadURLsForActiveAccount = false - var setActiveAccountEnvironmentUrlsData: EnvironmentURLData? - var setPreAuthEnvironmentUrlsData: EnvironmentURLData? + var setActiveAccountEnvironmentURLsData: EnvironmentURLData? + var setPreAuthEnvironmentURLsData: EnvironmentURLData? var apiURL = URL(string: "https://example.com/api")! var baseURL = URL(string: "https://example.com")! @@ -26,10 +26,10 @@ class MockEnvironmentService: EnvironmentService { } func setActiveAccountURLs(urls: EnvironmentURLData) { - setActiveAccountEnvironmentUrlsData = urls + setActiveAccountEnvironmentURLsData = urls } func setPreAuthURLs(urls: EnvironmentURLData) async { - setPreAuthEnvironmentUrlsData = urls + setPreAuthEnvironmentURLsData = urls } } diff --git a/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift b/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift index 7dbcd6bb9..25625bb48 100644 --- a/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift +++ b/BitwardenShared/Core/Platform/Services/TestHelpers/MockStateService.swift @@ -34,8 +34,8 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt var doesActiveAccountHavePremiumCalled = false var doesActiveAccountHavePremiumResult: Result = .success(true) var encryptedPinByUserId = [String: String]() - var environmentUrls = [String: EnvironmentURLData]() - var environmentUrlsError: Error? + var environmentURLs = [String: EnvironmentURLData]() + var environmentURLsError: Error? var eventsResult: Result = .success(()) var events = [String: [EventData]]() var forcePasswordResetReason = [String: ForcePasswordResetReason]() @@ -58,8 +58,8 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt var notificationsLastRegistrationError: Error? var passwordGenerationOptions = [String: PasswordGenerationOptions]() var pinProtectedUserKeyValue = [String: String]() - var preAuthEnvironmentUrls: EnvironmentURLData? - var accountCreationEnvironmentUrls = [String: EnvironmentURLData]() + var preAuthEnvironmentURLs: EnvironmentURLData? + var accountCreationEnvironmentURLs = [String: EnvironmentURLData]() var preAuthServerConfig: ServerConfig? var rememberedOrgIdentifier: String? var reviewPromptData: ReviewPromptData? @@ -229,12 +229,12 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt return encryptedPinByUserId[userId] ?? nil } - func getEnvironmentUrls(userId: String?) async throws -> EnvironmentURLData? { - if let environmentUrlsError { - throw environmentUrlsError + func getEnvironmentURLs(userId: String?) async throws -> EnvironmentURLData? { + if let environmentURLsError { + throw environmentURLsError } let userId = try unwrapUserId(userId) - return environmentUrls[userId] + return environmentURLs[userId] } func getEvents(userId: String?) async throws -> [EventData] { @@ -284,12 +284,12 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt return passwordGenerationOptions[userId] } - func getPreAuthEnvironmentUrls() async -> EnvironmentURLData? { - preAuthEnvironmentUrls + func getPreAuthEnvironmentURLs() async -> EnvironmentURLData? { + preAuthEnvironmentURLs } - func getAccountCreationEnvironmentUrls(email: String) async -> EnvironmentURLData? { - accountCreationEnvironmentUrls[email] + func getAccountCreationEnvironmentURLs(email: String) async -> EnvironmentURLData? { + accountCreationEnvironmentURLs[email] } func getPreAuthServerConfig() async -> BitwardenShared.ServerConfig? { @@ -469,9 +469,9 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt accountVolatileData[userId, default: AccountVolatileData()].pinProtectedUserKey = pin } - func setEnvironmentUrls(_ environmentUrls: EnvironmentURLData, userId: String?) async throws { + func setEnvironmentURLs(_ environmentURLs: EnvironmentURLData, userId: String?) async throws { let userId = try unwrapUserId(userId) - self.environmentUrls[userId] = environmentUrls + self.environmentURLs[userId] = environmentURLs } func setEvents(_ events: [EventData], userId: String?) async throws { @@ -557,12 +557,12 @@ class MockStateService: StateService { // swiftlint:disable:this type_body_lengt ].pinProtectedUserKey = pin } - func setPreAuthEnvironmentUrls(_ urls: BitwardenShared.EnvironmentURLData) async { - preAuthEnvironmentUrls = urls + func setPreAuthEnvironmentURLs(_ urls: BitwardenShared.EnvironmentURLData) async { + preAuthEnvironmentURLs = urls } - func setAccountCreationEnvironmentUrls(urls: BitwardenShared.EnvironmentURLData, email: String) async { - accountCreationEnvironmentUrls[email] = urls + func setAccountCreationEnvironmentURLs(urls: BitwardenShared.EnvironmentURLData, email: String) async { + accountCreationEnvironmentURLs[email] = urls } func setPreAuthServerConfig(config: BitwardenShared.ServerConfig) async { diff --git a/BitwardenShared/UI/Auth/AuthCoordinator.swift b/BitwardenShared/UI/Auth/AuthCoordinator.swift index 675386818..6eea1ddfd 100644 --- a/BitwardenShared/UI/Auth/AuthCoordinator.swift +++ b/BitwardenShared/UI/Auth/AuthCoordinator.swift @@ -511,13 +511,13 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt guard let stackNavigator else { return } let isPresenting = stackNavigator.rootViewController?.presentedViewController != nil - let environmentUrls = EnvironmentUrls( - environmentURLData: services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() + let environmentURLs = EnvironmentURLs( + environmentURLData: services.appSettingsStore.preAuthEnvironmentURLs ?? EnvironmentURLData() ) let state = LoginState( isNewAccount: isNewAccount, - serverURLString: environmentUrls.webVaultURL.host ?? "", + serverURLString: environmentURLs.webVaultURL.host ?? "", username: username ) @@ -667,16 +667,16 @@ final class AuthCoordinator: NSObject, // swiftlint:disable:this type_body_lengt /// - currentRegion: The user's region prior to showing the self-hosted settings view. /// private func showSelfHostedView(delegate: SelfHostedProcessorDelegate?, currentRegion: RegionType) { - let preAuthEnvironmentUrls = services.appSettingsStore.preAuthEnvironmentUrls ?? EnvironmentURLData() + let preAuthEnvironmentURLs = services.appSettingsStore.preAuthEnvironmentURLs ?? EnvironmentURLData() var state = SelfHostedState() if currentRegion == .selfHosted { state = SelfHostedState( - apiServerUrl: preAuthEnvironmentUrls.api?.sanitized.description ?? "", - iconsServerUrl: preAuthEnvironmentUrls.icons?.sanitized.description ?? "", - identityServerUrl: preAuthEnvironmentUrls.identity?.sanitized.description ?? "", - serverUrl: preAuthEnvironmentUrls.base?.sanitized.description ?? "", - webVaultServerUrl: preAuthEnvironmentUrls.webVault?.sanitized.description ?? "" + apiServerUrl: preAuthEnvironmentURLs.api?.sanitized.description ?? "", + iconsServerUrl: preAuthEnvironmentURLs.icons?.sanitized.description ?? "", + identityServerUrl: preAuthEnvironmentURLs.identity?.sanitized.description ?? "", + serverUrl: preAuthEnvironmentURLs.base?.sanitized.description ?? "", + webVaultServerUrl: preAuthEnvironmentURLs.webVault?.sanitized.description ?? "" ) } diff --git a/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift b/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift index dbd492ea6..e31f5a12d 100644 --- a/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift +++ b/BitwardenShared/UI/Auth/AuthCoordinatorTests.swift @@ -338,7 +338,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// `navigate(to:)` with `.login` pushes the login view onto the stack navigator and hides the back button. @MainActor func test_navigate_login() throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData.defaultEU + appSettingsStore.preAuthEnvironmentURLs = EnvironmentURLData.defaultEU subject.navigate(to: .login(username: "username")) XCTAssertEqual(stackNavigator.actions.last?.type, .pushed) @@ -356,7 +356,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// `navigate(to:)` with `.login` pushes the login view onto the stack navigator and hides the back button. @MainActor func test_navigate_login_newAccount() throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData.defaultEU + appSettingsStore.preAuthEnvironmentURLs = EnvironmentURLData.defaultEU subject.navigate(to: .login(username: "username", isNewAccount: true)) XCTAssertEqual(stackNavigator.actions.last?.type, .pushed) @@ -377,7 +377,7 @@ class AuthCoordinatorTests: BitwardenTestCase { // swiftlint:disable:this type_b /// It also initializes `LoginState` with the self-hosted URL host. @MainActor func test_navigate_login_selfHosted() async throws { - appSettingsStore.preAuthEnvironmentUrls = EnvironmentURLData(webVault: URL(string: "http://www.example.com")!) + appSettingsStore.preAuthEnvironmentURLs = EnvironmentURLData(webVault: URL(string: "http://www.example.com")!) subject.navigate(to: .login(username: "username")) let viewController = try XCTUnwrap( diff --git a/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessor.swift b/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessor.swift index 8cfe58b1c..9b0ee08d8 100644 --- a/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessor.swift +++ b/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessor.swift @@ -273,7 +273,7 @@ class CompleteRegistrationProcessor: StateProcessor< } guard - let urls = await services.stateService.getAccountCreationEnvironmentUrls(email: state.userEmail) + let urls = await services.stateService.getAccountCreationEnvironmentURLs(email: state.userEmail) else { throw CompleteRegistrationError.preAuthUrlsEmpty } await services.environmentService.setPreAuthURLs(urls: urls) diff --git a/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessorTests.swift b/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessorTests.swift index 840873b5e..a37b2cbc0 100644 --- a/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessorTests.swift +++ b/BitwardenShared/UI/Auth/CompleteRegistration/CompleteRegistrationProcessorTests.swift @@ -74,9 +74,9 @@ class CompleteRegistrationProcessorTests: BitwardenTestCase { let email = "email@example.com" subject.state.userEmail = email subject.state.fromEmail = true - await stateService.setAccountCreationEnvironmentUrls(urls: .defaultEU, email: email) + await stateService.setAccountCreationEnvironmentURLs(urls: .defaultEU, email: email) await subject.perform(.appeared) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultEU) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultEU) } /// `perform(.appeared)` fromEmail false returns. @@ -85,10 +85,10 @@ class CompleteRegistrationProcessorTests: BitwardenTestCase { let email = "email@example.com" subject.state.userEmail = email subject.state.fromEmail = false - await stateService.setAccountCreationEnvironmentUrls(urls: .defaultEU, email: email) + await stateService.setAccountCreationEnvironmentURLs(urls: .defaultEU, email: email) await subject.perform(.appeared) XCTAssertNil(coordinator.alertShown.last) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, nil) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, nil) } /// `perform(.appeared)` fromEmail true and no saved region for given email shows alert. @@ -97,7 +97,7 @@ class CompleteRegistrationProcessorTests: BitwardenTestCase { let email = "email@example.com" subject.state.userEmail = email subject.state.fromEmail = true - await stateService.setAccountCreationEnvironmentUrls(urls: .defaultEU, email: "another_email@example.com") + await stateService.setAccountCreationEnvironmentURLs(urls: .defaultEU, email: "another_email@example.com") await subject.perform(.appeared) XCTAssertEqual( coordinator.alertShown[0], @@ -106,7 +106,7 @@ class CompleteRegistrationProcessorTests: BitwardenTestCase { message: Localizations.theRegionForTheGivenEmailCouldNotBeLoaded ) ) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, nil) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, nil) } /// `perform(.appeared)` verify user email show toast on success. diff --git a/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift b/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift index 5a4d5c7af..8a46212be 100644 --- a/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift +++ b/BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift @@ -63,12 +63,12 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// `didChangeRegion(urls:)` update URLs when they change on the StartRegistration modal @MainActor func test_didChangeRegion() async { - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: .example) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: .example) subject.state.region = .unitedStates await subject.didChangeRegion() XCTAssertEqual(subject.state.region, .selfHosted) XCTAssertEqual( - environmentService.setPreAuthEnvironmentUrlsData, + environmentService.setPreAuthEnvironmentURLsData, EnvironmentURLData(base: .example) ) } @@ -77,13 +77,13 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// the environment. @MainActor func test_didSaveEnvironment() async { - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: .example) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: .example) subject.state.region = .unitedStates await subject.didSaveEnvironment(urls: EnvironmentURLData(base: .example)) XCTAssertEqual(subject.state.region, .selfHosted) XCTAssertEqual(subject.state.toast, Toast(title: Localizations.environmentSaved)) XCTAssertEqual( - environmentService.setPreAuthEnvironmentUrlsData, + environmentService.setPreAuthEnvironmentURLsData, EnvironmentURLData(base: .example) ) } @@ -91,11 +91,11 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ /// `didSaveEnvironment(urls:)` with empty URLs doesn't change the region or the environment URLs. @MainActor func test_didSaveEnvironment_empty() async { - stateService.preAuthEnvironmentUrls = EnvironmentURLData() + stateService.preAuthEnvironmentURLs = EnvironmentURLData() subject.state.region = .unitedStates await subject.didSaveEnvironment(urls: EnvironmentURLData()) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertNil(environmentService.setPreAuthEnvironmentUrlsData) + XCTAssertNil(environmentService.setPreAuthEnvironmentURLsData) } /// `perform(.appeared)` with no pre-auth URLs defaults the region and URLs to the US environment. @@ -103,17 +103,17 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ func test_perform_appeared_loadsRegion_noPreAuthUrls() async { await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultUS) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultUS) } /// `perform(.appeared)` with EU pre-auth URLs sets the state to the EU region and sets the /// environment URLs. @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_europe() async { - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .europe) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultEU) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultEU) } /// `perform(.appeared)` with self-hosted pre-auth URLs sets the state to the self-hosted region @@ -121,20 +121,20 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_ @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_selfHosted() async { let urls = EnvironmentURLData(base: .example) - stateService.preAuthEnvironmentUrls = urls + stateService.preAuthEnvironmentURLs = urls await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .selfHosted) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, urls) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, urls) } /// `perform(.appeared)` with US pre-auth URLs sets the state to the US region and sets the /// environment URLs. @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_unitedStates() async { - stateService.preAuthEnvironmentUrls = .defaultUS + stateService.preAuthEnvironmentURLs = .defaultUS await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultUS) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultUS) } /// `perform(.appeared)` with feature flag for .emailVerification set to true diff --git a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessor.swift b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessor.swift index 47765195e..873721fc2 100644 --- a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessor.swift +++ b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessor.swift @@ -179,11 +179,11 @@ class StartRegistrationProcessor: StateProcessor< userEmail: email )) } else { - guard let preAuthUrls = await services.stateService.getPreAuthEnvironmentUrls() else { + guard let preAuthUrls = await services.stateService.getPreAuthEnvironmentURLs() else { throw StartRegistrationError.preAuthUrlsEmpty } - await services.stateService.setAccountCreationEnvironmentUrls(urls: preAuthUrls, email: email) + await services.stateService.setAccountCreationEnvironmentURLs(urls: preAuthUrls, email: email) coordinator.navigate(to: .checkEmail(email: email)) } } catch let error as StartRegistrationError { diff --git a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessorTests.swift b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessorTests.swift index 088f2d5d4..cd35e3a6d 100644 --- a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessorTests.swift +++ b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationProcessorTests.swift @@ -101,7 +101,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: func test_perform_startRegistration_setPreAuthUrls_checkEmail() async throws { subject.state = .fixture() client.result = .httpSuccess(testData: .nilResponse) - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.perform(.startRegistration) @@ -121,7 +121,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: LoadingOverlayState(title: Localizations.creatingAccount), ] ) - XCTAssertEqual(stateService.accountCreationEnvironmentUrls["example@email.com"], .defaultEU) + XCTAssertEqual(stateService.accountCreationEnvironmentURLs["example@email.com"], .defaultEU) } /// `perform(_:)` with `.startRegistration` sets preAuthUrls for the given email and navigates to check email. @@ -129,7 +129,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: func test_perform_startRegistration_setPreAuthUrls_checkEmail_emailWithSpaceAndCapitals() async throws { subject.state = .fixture(emailText: " example@EMAIL.com ") client.result = .httpSuccess(testData: .nilResponse) - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.perform(.startRegistration) @@ -149,7 +149,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: LoadingOverlayState(title: Localizations.creatingAccount), ] ) - XCTAssertEqual(stateService.accountCreationEnvironmentUrls["example@email.com"], .defaultEU) + XCTAssertEqual(stateService.accountCreationEnvironmentURLs["example@email.com"], .defaultEU) } /// `perform(_:)` with `.startRegistration` fails if preAuthUrls cannot be loaded. @@ -157,7 +157,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: func test_perform_startRegistration_setPreAuthUrls_checkEmail_noUrls() async throws { subject.state = .fixture() client.result = .httpSuccess(testData: .nilResponse) - stateService.preAuthEnvironmentUrls = nil + stateService.preAuthEnvironmentURLs = nil await subject.perform(.startRegistration) @@ -540,7 +540,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: XCTAssertEqual(subject.state.region, .selfHosted) XCTAssertEqual(subject.state.toast, Toast(title: Localizations.environmentSaved)) XCTAssertEqual( - environmentService.setPreAuthEnvironmentUrlsData, + environmentService.setPreAuthEnvironmentURLsData, EnvironmentURLData(base: .example) ) } @@ -551,7 +551,7 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: subject.state.region = .unitedStates await subject.didSaveEnvironment(urls: EnvironmentURLData()) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertNil(environmentService.setPreAuthEnvironmentUrlsData) + XCTAssertNil(environmentService.setPreAuthEnvironmentURLsData) } /// `perform(.appeared)` loads the feature flags needed by the processor. @@ -573,17 +573,17 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: func test_perform_appeared_loadsRegion_noPreAuthUrls() async { await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultUS) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultUS) } /// `perform(.appeared)` with EU pre-auth URLs sets the state to the EU region and sets the /// environment URLs. @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_europe() async { - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .europe) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultEU) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultEU) } /// `perform(.appeared)` with self-hosted pre-auth URLs sets the state to the self-hosted region @@ -591,20 +591,20 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_selfHosted() async { let urls = EnvironmentURLData(base: .example) - stateService.preAuthEnvironmentUrls = urls + stateService.preAuthEnvironmentURLs = urls await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .selfHosted) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, urls) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, urls) } /// `perform(.appeared)` with US pre-auth URLs sets the state to the US region and sets the /// environment URLs. @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_unitedStates() async { - stateService.preAuthEnvironmentUrls = .defaultUS + stateService.preAuthEnvironmentURLs = .defaultUS await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultUS) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultUS) } /// `perform(.appeared)` with US pre-auth URLs sets the state to the US region and sets the @@ -612,10 +612,10 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: /// Test if isReceiveMarketingToggle is On @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_unitedStates_isReceiveMarketingToggle_on() async { - stateService.preAuthEnvironmentUrls = .defaultUS + stateService.preAuthEnvironmentURLs = .defaultUS await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .unitedStates) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultUS) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultUS) XCTAssertTrue(subject.state.isReceiveMarketingToggleOn) } @@ -624,10 +624,10 @@ class StartRegistrationProcessorTests: BitwardenTestCase { // swiftlint:disable: /// Test if isReceiveMarketingToggle is Off @MainActor func test_perform_appeared_loadsRegion_withPreAuthUrls_europe_isReceiveMarketingToggle_off() async { - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.perform(.appeared) XCTAssertEqual(subject.state.region, .europe) - XCTAssertEqual(environmentService.setPreAuthEnvironmentUrlsData, .defaultEU) + XCTAssertEqual(environmentService.setPreAuthEnvironmentURLsData, .defaultEU) XCTAssertFalse(subject.state.isReceiveMarketingToggleOn) } diff --git a/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift b/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift index a66d0b6df..5307ec556 100644 --- a/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift +++ b/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift @@ -59,7 +59,7 @@ class RegionHelper { /// Sets the region to the last used region. /// func loadRegion() async { - guard let urls = await stateService.getPreAuthEnvironmentUrls() else { + guard let urls = await stateService.getPreAuthEnvironmentURLs() else { await delegate?.setRegion(.unitedStates, .defaultUS) return } diff --git a/BitwardenShared/UI/Auth/Utilities/RegionHelperTests.swift b/BitwardenShared/UI/Auth/Utilities/RegionHelperTests.swift index 198c3e024..7f8b4ed6d 100644 --- a/BitwardenShared/UI/Auth/Utilities/RegionHelperTests.swift +++ b/BitwardenShared/UI/Auth/Utilities/RegionHelperTests.swift @@ -102,7 +102,7 @@ class RegionHelperTests: BitwardenTestCase { /// `loadRegion()` with pre auth region as nil default to us func test_loadRegion_nil() async throws { - stateService.preAuthEnvironmentUrls = nil + stateService.preAuthEnvironmentURLs = nil await subject.loadRegion() XCTAssertTrue(regionDelegate.setRegionCalled) XCTAssertEqual(regionDelegate.setRegionType, .unitedStates) @@ -111,7 +111,7 @@ class RegionHelperTests: BitwardenTestCase { /// `loadRegion()` with pre auth region func test_loadRegion_us() async throws { - stateService.preAuthEnvironmentUrls = .defaultUS + stateService.preAuthEnvironmentURLs = .defaultUS await subject.loadRegion() XCTAssertTrue(regionDelegate.setRegionCalled) XCTAssertEqual(regionDelegate.setRegionType, .unitedStates) @@ -120,7 +120,7 @@ class RegionHelperTests: BitwardenTestCase { /// `loadRegion()` with pre auth region func test_loadRegion_eu() async throws { - stateService.preAuthEnvironmentUrls = .defaultEU + stateService.preAuthEnvironmentURLs = .defaultEU await subject.loadRegion() XCTAssertTrue(regionDelegate.setRegionCalled) XCTAssertEqual(regionDelegate.setRegionType, .europe) @@ -129,7 +129,7 @@ class RegionHelperTests: BitwardenTestCase { /// `loadRegion()` with pre auth region func test_loadRegion_selfHosted() async throws { - stateService.preAuthEnvironmentUrls = EnvironmentURLData(base: URL(string: "https://selfhosted.com")) + stateService.preAuthEnvironmentURLs = EnvironmentURLData(base: URL(string: "https://selfhosted.com")) await subject.loadRegion() XCTAssertTrue(regionDelegate.setRegionCalled) XCTAssertEqual(regionDelegate.setRegionType, .selfHosted) diff --git a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift index 9e0dc1cd4..42fb86ebc 100644 --- a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift +++ b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift @@ -73,7 +73,7 @@ extension VaultUnlockState { self.init( email: account.profile.email, profileSwitcherState: profileSwitcherState, - webVaultHost: account.settings.environmentUrls?.webVaultHost ?? Constants.defaultWebVaultHost + webVaultHost: account.settings.environmentURLs?.webVaultHost ?? Constants.defaultWebVaultHost ) } } diff --git a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockStateTests.swift b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockStateTests.swift index b10feab03..0582e282a 100644 --- a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockStateTests.swift +++ b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockStateTests.swift @@ -10,7 +10,7 @@ class VaultUnlockStateTests: BitwardenTestCase { let subject = VaultUnlockState( account: .fixture( settings: .fixture( - environmentUrls: .fixture( + environmentURLs: .fixture( webVault: URL(string: "https://test.bitwarden.com") ) ) @@ -27,7 +27,7 @@ class VaultUnlockStateTests: BitwardenTestCase { let subject = VaultUnlockState( account: .fixture( settings: .fixture( - environmentUrls: .fixture( + environmentURLs: .fixture( base: nil, webVault: nil ) diff --git a/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift b/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift index 43907a306..82d6747bd 100644 --- a/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift +++ b/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift @@ -86,7 +86,7 @@ class ImportLoginsProcessor: StateProcessor Date: Mon, 16 Dec 2024 12:00:02 -0600 Subject: [PATCH 4/9] Update baseURL --- .../Core/Auth/Models/Enum/RegionType.swift | 2 +- .../Core/Auth/Models/Enum/RegionTypeTests.swift | 10 +++++----- .../Core/Auth/Repositories/AuthRepository.swift | 4 ++-- .../Core/Auth/Repositories/AuthRepositoryTests.swift | 2 +- .../Platform/Models/Domain/EnvironmentURLData.swift | 4 ++-- .../Models/Domain/EnvironmentUrlsTests.swift | 8 ++++---- .../Core/Platform/Services/API/APIService.swift | 10 +++++----- .../Core/Platform/Services/EnvironmentService.swift | 6 +++--- BitwardenShared/UI/Auth/Landing/LandingView.swift | 2 +- .../UI/Auth/Landing/LandingViewTests.swift | 2 +- .../Login/TwoFactorAuth/TwoFactorAuthProcessor.swift | 6 +++--- .../StartRegistration/StartRegistrationView.swift | 2 +- .../StartRegistrationViewTests.swift | 2 +- BitwardenShared/UI/Auth/Utilities/RegionHelper.swift | 2 +- .../Generator/GeneratorState+UsernameState.swift | 2 +- .../Generator/Generator/GeneratorStateTests.swift | 2 +- BitwardenWatchApp/Services/EnvironmentService.swift | 6 +++--- BitwardenWatchApp/WatchConnectivityManager.swift | 2 +- Networking/Sources/Networking/HTTPService.swift | 12 ++++++------ 19 files changed, 43 insertions(+), 43 deletions(-) diff --git a/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift b/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift index a996ccbb4..f49b64b3e 100644 --- a/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift +++ b/BitwardenShared/Core/Auth/Models/Enum/RegionType.swift @@ -21,7 +21,7 @@ public enum RegionType: CaseIterable, Sendable { } /// A description of the base url for this region. - var baseUrlDescription: String { + var baseURLDescription: String { switch self { case .europe: return "bitwarden.eu" case .selfHosted: return Localizations.selfHosted diff --git a/BitwardenShared/Core/Auth/Models/Enum/RegionTypeTests.swift b/BitwardenShared/Core/Auth/Models/Enum/RegionTypeTests.swift index 7efab8120..12a2692f1 100644 --- a/BitwardenShared/Core/Auth/Models/Enum/RegionTypeTests.swift +++ b/BitwardenShared/Core/Auth/Models/Enum/RegionTypeTests.swift @@ -12,11 +12,11 @@ class RegionTypeTests: BitwardenTestCase { XCTAssertEqual(RegionType.unitedStates.localizedName, Localizations.us) } - /// `getter:baseUrlDescription` returns the correct values. - func test_baseUrlDescription() { - XCTAssertEqual(RegionType.europe.baseUrlDescription, "bitwarden.eu") - XCTAssertEqual(RegionType.selfHosted.baseUrlDescription, Localizations.selfHosted) - XCTAssertEqual(RegionType.unitedStates.baseUrlDescription, "bitwarden.com") + /// `getter:baseURLDescription` returns the correct values. + func test_baseURLDescription() { + XCTAssertEqual(RegionType.europe.baseURLDescription, "bitwarden.eu") + XCTAssertEqual(RegionType.selfHosted.baseURLDescription, Localizations.selfHosted) + XCTAssertEqual(RegionType.unitedStates.baseURLDescription, "bitwarden.com") } /// `getter:defaultURLs` returns the correct values. diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift index c2dbf33f6..3d99813e5 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift @@ -625,8 +625,8 @@ extension DefaultAuthRepository: AuthRepository { errorReporter.log(error: error) } - if let baseUrl = try? await stateService.getEnvironmentURLs(userId: userId)?.base, - baseUrl == environmentService.baseURL { + if let baseURL = try? await stateService.getEnvironmentURLs(userId: userId)?.base, + baseURL == environmentService.baseURL { return userId } } diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift index 17795c443..6e9d490a5 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift @@ -334,7 +334,7 @@ class AuthRepositoryTests: BitwardenTestCase { // swiftlint:disable:this type_bo /// `existingAccountUserId(email:)` returns `nil` if there's an existing account with the same /// email but the base URLs are different. - func test_existingAccountUserId_matchingAccountDifferentBaseUrl() async throws { + func test_existingAccountUserId_matchingAccountDifferentBaseURL() async throws { environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base) stateService.activeAccount = .fixture(profile: .fixture(email: "user@bitwarden.com", userId: "1")) stateService.environmentURLs["1"] = .defaultUS diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift index 8989b54fa..63902887e 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentURLData.swift @@ -133,8 +133,8 @@ extension EnvironmentURLData { // Foundation's URL appending methods percent encode the path component that is passed into the method, // which includes the `#` symbol. Since the `#` character is a critical portion of these urls, we use String // concatenation to get around this limitation. - if let baseUrl = webVault ?? base, - let url = URL(string: baseUrl.sanitized.absoluteString.appending("/#/\(additionalPath)")) { + if let baseURL = webVault ?? base, + let url = URL(string: baseURL.sanitized.absoluteString.appending("/#/\(additionalPath)")) { return url } return nil diff --git a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift index f7f653884..3ac6d36ce 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/EnvironmentUrlsTests.swift @@ -55,7 +55,7 @@ class EnvironmentURLsTests: BitwardenTestCase { /// `init(environmentURLData:)` sets the URLs from the base URL if one is set and is not /// `.unitedStates` nor `.europe` region type. - func test_init_environmentURLData_baseUrl() { + func test_init_environmentURLData_baseURL() { let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com")!) ) @@ -79,7 +79,7 @@ class EnvironmentURLsTests: BitwardenTestCase { } /// `init(environmentURLData:)` defaults to the pre-defined EU URLs if the base URL matches the EU environment. - func test_init_environmentURLData_baseUrl_europe() { + func test_init_environmentURLData_baseURL_europe() { let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.eu")!) ) @@ -103,7 +103,7 @@ class EnvironmentURLsTests: BitwardenTestCase { } /// `init(environmentURLData:)` defaults to the pre-defined US URLs if the base URL matches the US environment. - func test_init_environmentURLData_baseUrl_unitedStates() { + func test_init_environmentURLData_baseURL_unitedStates() { let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ) @@ -127,7 +127,7 @@ class EnvironmentURLsTests: BitwardenTestCase { } /// `init(environmentURLData:)` sets the URLs from the base URL which includes a trailing slash. - func test_init_environmentURLData_baseUrlWithTrailingSlash() { + func test_init_environmentURLData_baseURLWithTrailingSlash() { let subject = EnvironmentURLs( environmentURLData: EnvironmentURLData(base: URL(string: "https://example.com/")!) ) diff --git a/BitwardenShared/Core/Platform/Services/API/APIService.swift b/BitwardenShared/Core/Platform/Services/API/APIService.swift index bfb5866c7..47120ea6d 100644 --- a/BitwardenShared/Core/Platform/Services/API/APIService.swift +++ b/BitwardenShared/Core/Platform/Services/API/APIService.swift @@ -70,7 +70,7 @@ class APIService { accountTokenProvider = AccountTokenProvider( httpService: HTTPService( - baseUrlGetter: { environmentService.identityURL }, + baseURLGetter: { environmentService.identityURL }, client: client, requestHandlers: [defaultHeadersRequestHandler], responseHandlers: [responseValidationHandler] @@ -79,20 +79,20 @@ class APIService { ) apiService = HTTPService( - baseUrlGetter: { environmentService.apiURL }, + baseURLGetter: { environmentService.apiURL }, client: client, requestHandlers: [defaultHeadersRequestHandler], responseHandlers: [responseValidationHandler], tokenProvider: accountTokenProvider ) apiUnauthenticatedService = HTTPService( - baseUrlGetter: { environmentService.apiURL }, + baseURLGetter: { environmentService.apiURL }, client: client, requestHandlers: [defaultHeadersRequestHandler], responseHandlers: [responseValidationHandler] ) eventsService = HTTPService( - baseUrlGetter: { environmentService.eventsURL }, + baseURLGetter: { environmentService.eventsURL }, client: client, requestHandlers: [defaultHeadersRequestHandler], responseHandlers: [responseValidationHandler], @@ -105,7 +105,7 @@ class APIService { responseHandlers: [responseValidationHandler] ) identityService = HTTPService( - baseUrlGetter: { environmentService.identityURL }, + baseURLGetter: { environmentService.identityURL }, client: client, requestHandlers: [defaultHeadersRequestHandler], responseHandlers: [responseValidationHandler] diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift index e52a3b101..c731419e4 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift @@ -140,12 +140,12 @@ class DefaultEnvironmentService: EnvironmentService { /// private func managedSettingsUrls() -> EnvironmentURLData? { let managedSettings = standardUserDefaults.dictionary(forKey: "com.apple.configuration.managed") - guard let baseUrlString = managedSettings?["baseEnvironmentUrl"] as? String, - let baseUrl = URL(string: baseUrlString) + guard let baseURLString = managedSettings?["baseEnvironmentUrl"] as? String, + let baseURL = URL(string: baseURLString) else { return nil } - return EnvironmentURLData(base: baseUrl) + return EnvironmentURLData(base: baseURL) } } diff --git a/BitwardenShared/UI/Auth/Landing/LandingView.swift b/BitwardenShared/UI/Auth/Landing/LandingView.swift index 8fb1b1dbd..938b92416 100644 --- a/BitwardenShared/UI/Auth/Landing/LandingView.swift +++ b/BitwardenShared/UI/Auth/Landing/LandingView.swift @@ -115,7 +115,7 @@ struct LandingView: View { RegionSelector( selectorLabel: Localizations.loggingInOn, - regionName: store.state.region.baseUrlDescription + regionName: store.state.region.baseURLDescription ) { await store.perform(.regionPressed) } diff --git a/BitwardenShared/UI/Auth/Landing/LandingViewTests.swift b/BitwardenShared/UI/Auth/Landing/LandingViewTests.swift index 3d32ad96f..b51bf4d9a 100644 --- a/BitwardenShared/UI/Auth/Landing/LandingViewTests.swift +++ b/BitwardenShared/UI/Auth/Landing/LandingViewTests.swift @@ -75,7 +75,7 @@ class LandingViewTests: BitwardenTestCase { @MainActor func test_regionButton_tap() throws { let button = try subject.inspect().find( - button: "\(Localizations.loggingInOn): \(RegionType.unitedStates.baseUrlDescription)" + button: "\(Localizations.loggingInOn): \(RegionType.unitedStates.baseURLDescription)" ) try button.tap() waitFor(processor.effects.last != nil) diff --git a/BitwardenShared/UI/Auth/Login/TwoFactorAuth/TwoFactorAuthProcessor.swift b/BitwardenShared/UI/Auth/Login/TwoFactorAuth/TwoFactorAuthProcessor.swift index 8fd1ef69d..62482666e 100644 --- a/BitwardenShared/UI/Auth/Login/TwoFactorAuth/TwoFactorAuthProcessor.swift +++ b/BitwardenShared/UI/Auth/Login/TwoFactorAuth/TwoFactorAuthProcessor.swift @@ -472,7 +472,7 @@ extension TwoFactorAuthProcessor: WebAuthnFlowDelegate { try coordinator.navigate( to: .webAuthnSelfHosted( webAuthnUrl( - baseUrl: services.environmentService.webVaultURL, + baseURL: services.environmentService.webVaultURL, data: webAuthnProvider, headerText: Localizations.fido2Title, buttonText: Localizations.fido2AuthenticateWebAuthn, @@ -512,7 +512,7 @@ extension TwoFactorAuthProcessor: WebAuthnFlowDelegate { /// Generates a URL to display a WebAuthn challenge for Self-Hosted vault authentication. /// private func webAuthnUrl( - baseUrl: URL, + baseURL: URL, data: WebAuthn, headerText: String, buttonText: String, @@ -532,7 +532,7 @@ extension TwoFactorAuthProcessor: WebAuthnFlowDelegate { let jsonData = try encoder.encode(connectorData) let base64string = jsonData.base64EncodedString() - guard let url = baseUrl + guard let url = baseURL .appendingPathComponent("/webauthn-mobile-connector.html") .appending(queryItems: [ URLQueryItem(name: "data", value: base64string), diff --git a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationView.swift b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationView.swift index eb5203bff..7df1aba1c 100644 --- a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationView.swift +++ b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationView.swift @@ -137,7 +137,7 @@ struct StartRegistrationView: View { RegionSelector( selectorLabel: Localizations.creatingOn, - regionName: store.state.region.baseUrlDescription + regionName: store.state.region.baseURLDescription ) { await store.perform(.regionTapped) } diff --git a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationViewTests.swift b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationViewTests.swift index 99009a510..e13a36fd3 100644 --- a/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationViewTests.swift +++ b/BitwardenShared/UI/Auth/StartRegistration/StartRegistrationViewTests.swift @@ -69,7 +69,7 @@ class StartRegistrationViewTests: BitwardenTestCase { @MainActor func test_regionButton_tap() throws { let button = try subject.inspect().find( - button: "\(Localizations.creatingOn): \(subject.store.state.region.baseUrlDescription)" + button: "\(Localizations.creatingOn): \(subject.store.state.region.baseURLDescription)" ) try button.tap() waitFor(!processor.effects.isEmpty) diff --git a/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift b/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift index 5307ec556..1eb46f768 100644 --- a/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift +++ b/BitwardenShared/UI/Auth/Utilities/RegionHelper.swift @@ -35,7 +35,7 @@ class RegionHelper { /// func presentRegionSelectorAlert(title: String, currentRegion: RegionType?) async { let actions = RegionType.allCases.map { region in - AlertAction(title: region.baseUrlDescription, style: .default) { _ in + AlertAction(title: region.baseURLDescription, style: .default) { _ in if let urls = region.defaultURLs { await self.delegate?.setRegion(region, urls) } else { diff --git a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift index c3144cf2b..90faa50f9 100644 --- a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift +++ b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift @@ -221,7 +221,7 @@ extension GeneratorState.UsernameState { ForwarderServiceType.addyIo( apiToken: addyIOAPIAccessToken, domain: addyIODomainName, - baseUrl: "https://app.addy.io" + baseURL: "https://app.addy.io" ) case .duckDuckGo: ForwarderServiceType.duckDuckGo(token: duckDuckGoAPIKey) diff --git a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift index 5d3c3abda..2e8a7a40b 100644 --- a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift +++ b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift @@ -742,7 +742,7 @@ class GeneratorStateTests: BitwardenTestCase { // swiftlint:disable:this type_bo service: .addyIo( apiToken: "ADDY IO TOKEN", domain: "addy-example.com", - baseUrl: "https://app.addy.io" + baseURL: "https://app.addy.io" ), website: "example.com" ) diff --git a/BitwardenWatchApp/Services/EnvironmentService.swift b/BitwardenWatchApp/Services/EnvironmentService.swift index 2c4c01100..9d7e032d3 100644 --- a/BitwardenWatchApp/Services/EnvironmentService.swift +++ b/BitwardenWatchApp/Services/EnvironmentService.swift @@ -9,7 +9,7 @@ class EnvironmentService { private init() {} - var baseUrl: String? { + var baseURL: String? { get { guard let urlData = KeychainHelper.standard.read(BASE_URL_KEY) else { return nil @@ -28,7 +28,7 @@ class EnvironmentService { var iconsUrl: String { guard let urlData = KeychainHelper.standard.read(ICONS_URL_KEY) else { - return baseUrl == nil ? DEFAULT_ICONS_URL : "\(baseUrl!)/icons" + return baseURL == nil ? DEFAULT_ICONS_URL : "\(baseURL!)/icons" } return String(decoding: urlData, as: UTF8.self) @@ -43,7 +43,7 @@ class EnvironmentService { } func clear() { - baseUrl = nil + baseURL = nil setIconsUrl(url: nil) } } diff --git a/BitwardenWatchApp/WatchConnectivityManager.swift b/BitwardenWatchApp/WatchConnectivityManager.swift index 40c676ee4..a538e2b9d 100644 --- a/BitwardenWatchApp/WatchConnectivityManager.swift +++ b/BitwardenWatchApp/WatchConnectivityManager.swift @@ -98,7 +98,7 @@ extension WatchConnectivityManager: WCSessionDelegate { StateService.shared.setUser(user: watchDTO.userData) // StateService.shared.setVaultTimeout(watchDTO.settingsData?.vaultTimeoutInMinutes, // watchDTO.settingsData?.vaultTimeoutAction ?? .lock) - EnvironmentService.shared.baseUrl = watchDTO.environmentData?.base + EnvironmentService.shared.baseURL = watchDTO.environmentData?.base EnvironmentService.shared.setIconsUrl(url: watchDTO.environmentData?.icons) if watchDTO.state.isDestructive { diff --git a/Networking/Sources/Networking/HTTPService.swift b/Networking/Sources/Networking/HTTPService.swift index b29c7b059..ca68876b6 100644 --- a/Networking/Sources/Networking/HTTPService.swift +++ b/Networking/Sources/Networking/HTTPService.swift @@ -6,10 +6,10 @@ public class HTTPService { // MARK: Properties /// The URL against which requests are resolved. - var baseURL: URL { baseUrlGetter() } + var baseURL: URL { baseURLGetter() } /// A getter function for dynamically retrieving the base url against which requests are resolved. - let baseUrlGetter: () -> URL + let baseURLGetter: () -> URL /// The underlying `HTTPClient` that performs the network request. let client: HTTPClient @@ -49,7 +49,7 @@ public class HTTPService { responseHandlers: [ResponseHandler] = [], tokenProvider: TokenProvider? = nil ) { - baseUrlGetter = { baseURL } + baseURLGetter = { baseURL } self.client = client self.requestHandlers = requestHandlers self.responseHandlers = responseHandlers @@ -59,7 +59,7 @@ public class HTTPService { /// Initialize a `HTTPService`. /// /// - Parameters: - /// - baseUrlGetter: A getter function for dynamically retrieving the base url against which + /// - baseURLGetter: A getter function for dynamically retrieving the base url against which /// requests are resolved. /// - client: The underlying `HTTPClient` that performs the network request. /// - requestHandlers: A list of `RequestHandler`s that have the option to view or modify the @@ -69,13 +69,13 @@ public class HTTPService { /// - tokenProvider: An object used to get an access token and refresh it when necessary. /// public init( - baseUrlGetter: @escaping () -> URL, + baseURLGetter: @escaping () -> URL, client: HTTPClient = URLSession.shared, requestHandlers: [RequestHandler] = [], responseHandlers: [ResponseHandler] = [], tokenProvider: TokenProvider? = nil ) { - self.baseUrlGetter = baseUrlGetter + self.baseURLGetter = baseURLGetter self.client = client self.requestHandlers = requestHandlers self.responseHandlers = responseHandlers From 6a315f07c5548d5fa15a55b893d37f24a9127f1f Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Mon, 16 Dec 2024 12:13:51 -0600 Subject: [PATCH 5/9] Little fixes --- ...UrlData+Fixtures.swift => EnvironmentURLData+Fixtures.swift} | 0 .../Generator/Generator/GeneratorState+UsernameState.swift | 2 +- .../UI/Tools/Generator/Generator/GeneratorStateTests.swift | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename BitwardenShared/Core/Platform/Models/Domain/Fixtures/{EnvironmentUrlData+Fixtures.swift => EnvironmentURLData+Fixtures.swift} (100%) diff --git a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentURLData+Fixtures.swift similarity index 100% rename from BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentUrlData+Fixtures.swift rename to BitwardenShared/Core/Platform/Models/Domain/Fixtures/EnvironmentURLData+Fixtures.swift diff --git a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift index 90faa50f9..c3144cf2b 100644 --- a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift +++ b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorState+UsernameState.swift @@ -221,7 +221,7 @@ extension GeneratorState.UsernameState { ForwarderServiceType.addyIo( apiToken: addyIOAPIAccessToken, domain: addyIODomainName, - baseURL: "https://app.addy.io" + baseUrl: "https://app.addy.io" ) case .duckDuckGo: ForwarderServiceType.duckDuckGo(token: duckDuckGoAPIKey) diff --git a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift index 2e8a7a40b..5d3c3abda 100644 --- a/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift +++ b/BitwardenShared/UI/Tools/Generator/Generator/GeneratorStateTests.swift @@ -742,7 +742,7 @@ class GeneratorStateTests: BitwardenTestCase { // swiftlint:disable:this type_bo service: .addyIo( apiToken: "ADDY IO TOKEN", domain: "addy-example.com", - baseURL: "https://app.addy.io" + baseUrl: "https://app.addy.io" ), website: "example.com" ) From 82c196210c78bc5f1e163b60d4e7290a52302fc5 Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Mon, 16 Dec 2024 12:30:12 -0600 Subject: [PATCH 6/9] Environment service --- .../Platform/Services/EnvironmentService.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift index c731419e4..7c6f3c567 100644 --- a/BitwardenShared/Core/Platform/Services/EnvironmentService.swift +++ b/BitwardenShared/Core/Platform/Services/EnvironmentService.swift @@ -102,18 +102,18 @@ class DefaultEnvironmentService: EnvironmentService { func loadURLsForActiveAccount() async { let urls: EnvironmentURLData - let managedSettingsUrls = managedSettingsUrls() + let managedSettingsURLs = managedSettingsURLs() if let environmentURLs = try? await stateService.getEnvironmentURLs() { urls = environmentURLs - } else if let managedSettingsUrls { - urls = managedSettingsUrls - } else if let preAuthUrls = await stateService.getPreAuthEnvironmentURLs() { - urls = preAuthUrls + } else if let managedSettingsURLs { + urls = managedSettingsURLs + } else if let preAuthURLs = await stateService.getPreAuthEnvironmentURLs() { + urls = preAuthURLs } else { urls = .defaultUS } - await setPreAuthURLs(urls: managedSettingsUrls ?? urls) + await setPreAuthURLs(urls: managedSettingsURLs ?? urls) environmentURLs = EnvironmentURLs(environmentURLData: urls) errorReporter.setRegion(region.errorReporterName, isPreAuth: false) @@ -138,7 +138,7 @@ class DefaultEnvironmentService: EnvironmentService { /// /// - Returns: The environment URLs that are specified as part of a managed app configuration. /// - private func managedSettingsUrls() -> EnvironmentURLData? { + private func managedSettingsURLs() -> EnvironmentURLData? { let managedSettings = standardUserDefaults.dictionary(forKey: "com.apple.configuration.managed") guard let baseURLString = managedSettings?["baseEnvironmentUrl"] as? String, let baseURL = URL(string: baseURLString) From 64cc690586238f4aa11e17731f495a9dc42789d6 Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Thu, 19 Dec 2024 15:09:55 -0600 Subject: [PATCH 7/9] Revert key casing --- .../Core/Platform/Services/Stores/AppSettingsStore.swift | 4 ++-- .../Platform/Services/Stores/AppSettingsStoreTests.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift index 769380522..974771361 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStore.swift @@ -787,9 +787,9 @@ extension DefaultAppSettingsStore: AppSettingsStore { case let .pinProtectedUserKey(userId): key = "pinKeyEncryptedUserKey_\(userId)" case .preAuthEnvironmentURLs: - key = "preAuthEnvironmentURLs" + key = "preAuthEnvironmentUrls" case let .accountCreationEnvironmentURLs(email): - key = "accountCreationEnvironmentURLs_\(email)" + key = "accountCreationEnvironmentUrls_\(email)" case .preAuthServerConfig: key = "preAuthServerConfig" case .rememberedEmail: diff --git a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift index 92545eafc..03fbeb1f8 100644 --- a/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift +++ b/BitwardenShared/Core/Platform/Services/Stores/AppSettingsStoreTests.swift @@ -695,7 +695,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:preAuthEnvironmentURLs")? + .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? .data(using: .utf8) ) ), @@ -709,7 +709,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:preAuthEnvironmentURLs")? + .string(forKey: "bwPreferencesStorage:preAuthEnvironmentUrls")? .data(using: .utf8) ) ), @@ -732,7 +732,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentURLs_\(email)")? + .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? .data(using: .utf8) ) ), @@ -746,7 +746,7 @@ class AppSettingsStoreTests: BitwardenTestCase { // swiftlint:disable:this type_ EnvironmentURLData.self, from: XCTUnwrap( userDefaults - .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentURLs_\(email)")? + .string(forKey: "bwPreferencesStorage:accountCreationEnvironmentUrls_\(email)")? .data(using: .utf8) ) ), From 8e1aea2d25cf94792b87a4e85941c12b25b6c8a4 Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Thu, 19 Dec 2024 16:34:25 -0600 Subject: [PATCH 8/9] Revert casing --- BitwardenShared/Core/Auth/Repositories/AuthRepository.swift | 2 +- BitwardenShared/Core/Platform/Models/Domain/Account.swift | 4 ++-- .../Core/Platform/Models/Domain/AccountTests.swift | 2 +- .../Platform/Models/Domain/Fixtures/Account+Fixtures.swift | 4 ++-- .../Core/Platform/Services/AuthenticatorSyncService.swift | 2 +- BitwardenShared/Core/Platform/Services/StateService.swift | 2 +- BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift | 2 +- .../ImportLogins/ImportLogins/ImportLoginsProcessor.swift | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift index 3d99813e5..60d8f11eb 100644 --- a/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift +++ b/BitwardenShared/Core/Auth/Repositories/AuthRepository.swift @@ -1053,7 +1053,7 @@ extension DefaultAuthRepository: AuthRepository { isUnlocked: displayAsUnlocked, userId: account.profile.userId, userInitials: account.initials(), - webVault: account.settings.environmentURLs?.webVaultHost ?? "" + webVault: account.settings.environmentUrls?.webVaultHost ?? "" ) } diff --git a/BitwardenShared/Core/Platform/Models/Domain/Account.swift b/BitwardenShared/Core/Platform/Models/Domain/Account.swift index 2a2601fb1..c509ff4a4 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Account.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Account.swift @@ -71,7 +71,7 @@ extension Account { userId: tokenPayload.userId ), settings: AccountSettings( - environmentURLs: environmentURLs + environmentUrls: environmentURLs ), _tokens: nil // Tokens have been moved out of `State` to the keychain. ) @@ -132,7 +132,7 @@ extension Account { // MARK: Properties /// The environment URLs for an account. - var environmentURLs: EnvironmentURLData? + var environmentUrls: EnvironmentURLData? } /// Domain model for an account's API tokens. diff --git a/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift b/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift index 2fd25c5e1..13fc118a6 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/AccountTests.swift @@ -56,7 +56,7 @@ class AccountTests: BitwardenTestCase { ), userId: "13512467-9cfe-43b0-969f-07534084764b" ), - settings: Account.AccountSettings(environmentURLs: nil), + settings: Account.AccountSettings(environmentUrls: nil), _tokens: nil ) ) diff --git a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift index 672b669a6..b2c9614a0 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Fixtures/Account+Fixtures.swift @@ -30,7 +30,7 @@ extension Account { userId: "13512467-9cfe-43b0-969f-07534084764b" ), settings: Account.AccountSettings( - environmentURLs: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) + environmentUrls: EnvironmentURLData(base: URL(string: "https://vault.bitwarden.com")!) ), tokens: nil ) @@ -118,7 +118,7 @@ extension Account.AccountSettings { environmentURLs: EnvironmentURLData? = .fixture() ) -> Account.AccountSettings { Account.AccountSettings( - environmentURLs: environmentURLs + environmentUrls: environmentURLs ) } } diff --git a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift index e5a9f879d..0742d5f86 100644 --- a/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift +++ b/BitwardenShared/Core/Platform/Services/AuthenticatorSyncService.swift @@ -223,7 +223,7 @@ actor DefaultAuthenticatorSyncService: NSObject, AuthenticatorSyncService { return decryptedCiphers.map { cipher in AuthenticatorBridgeItemDataView( - accountDomain: account.settings.environmentURLs?.webVaultHost ?? Constants.defaultWebVaultHost, + accountDomain: account.settings.environmentUrls?.webVaultHost ?? Constants.defaultWebVaultHost, accountEmail: account.profile.email, favorite: false, id: cipher.id ?? UUID().uuidString, diff --git a/BitwardenShared/Core/Platform/Services/StateService.swift b/BitwardenShared/Core/Platform/Services/StateService.swift index c4a5b2094..63baf9f39 100644 --- a/BitwardenShared/Core/Platform/Services/StateService.swift +++ b/BitwardenShared/Core/Platform/Services/StateService.swift @@ -1452,7 +1452,7 @@ actor DefaultStateService: StateService { // swiftlint:disable:this type_body_le func getEnvironmentURLs(userId: String?) async throws -> EnvironmentURLData? { let userId = try userId ?? getActiveAccountUserId() - return appSettingsStore.state?.accounts[userId]?.settings.environmentURLs + return appSettingsStore.state?.accounts[userId]?.settings.environmentUrls } func getEvents(userId: String?) async throws -> [EventData] { diff --git a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift index 42fb86ebc..9e0dc1cd4 100644 --- a/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift +++ b/BitwardenShared/UI/Auth/VaultUnlock/VaultUnlockState.swift @@ -73,7 +73,7 @@ extension VaultUnlockState { self.init( email: account.profile.email, profileSwitcherState: profileSwitcherState, - webVaultHost: account.settings.environmentURLs?.webVaultHost ?? Constants.defaultWebVaultHost + webVaultHost: account.settings.environmentUrls?.webVaultHost ?? Constants.defaultWebVaultHost ) } } diff --git a/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift b/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift index 82d6747bd..43907a306 100644 --- a/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift +++ b/BitwardenShared/UI/Vault/ImportLogins/ImportLogins/ImportLoginsProcessor.swift @@ -86,7 +86,7 @@ class ImportLoginsProcessor: StateProcessor Date: Tue, 31 Dec 2024 09:41:27 -0600 Subject: [PATCH 9/9] Add clarifying comment --- BitwardenShared/Core/Platform/Models/Domain/Account.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/BitwardenShared/Core/Platform/Models/Domain/Account.swift b/BitwardenShared/Core/Platform/Models/Domain/Account.swift index 27dfa4c26..beb21dd6c 100644 --- a/BitwardenShared/Core/Platform/Models/Domain/Account.swift +++ b/BitwardenShared/Core/Platform/Models/Domain/Account.swift @@ -140,6 +140,7 @@ extension Account { // MARK: Properties /// The environment URLs for an account. + /// The "URL" acronym in the variable name needs to remain lowercase for backwards compatibility. var environmentUrls: EnvironmentURLData? }