Skip to content

Commit

Permalink
[PM-8216] Update case of URL in various classes and variables (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
KatherineInCode authored Jan 9, 2025
1 parent e480779 commit f50ef9b
Show file tree
Hide file tree
Showing 47 changed files with 452 additions and 451 deletions.
4 changes: 2 additions & 2 deletions BitwardenShared/Core/Auth/Models/Enum/RegionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions BitwardenShared/Core/Auth/Models/Enum/RegionTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions BitwardenShared/Core/Auth/Repositories/AuthRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
38 changes: 19 additions & 19 deletions BitwardenShared/Core/Auth/Repositories/AuthRepositoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ 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: "[email protected]", userId: "1"))
stateService.environmentUrls["1"] = .defaultUS
stateService.environmentURLs["1"] = .defaultUS
stateService.isAuthenticated["1"] = true
stateService.userIds = ["1"]

Expand All @@ -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 {
environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base)
func test_existingAccountUserId_getEnvironmentURLsError() async throws {
environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base)
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1"))
stateService.environmentUrlsError = StateServiceError.noAccounts
stateService.environmentURLsError = StateServiceError.noAccounts
stateService.isAuthenticated["1"] = true
stateService.userIds = ["1"]

Expand All @@ -320,9 +320,9 @@ 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: "[email protected]", userId: "1"))
stateService.environmentUrls["1"] = .defaultUS
stateService.environmentURLs["1"] = .defaultUS
stateService.isAuthenticatedError = BitwardenTestError.example
stateService.userIds = ["1"]

Expand All @@ -334,10 +334,10 @@ 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)
func test_existingAccountUserId_matchingAccountDifferentBaseURL() async throws {
environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base)
stateService.activeAccount = .fixture(profile: .fixture(email: "[email protected]", userId: "1"))
stateService.environmentUrls["1"] = .defaultUS
stateService.environmentURLs["1"] = .defaultUS
stateService.isAuthenticated["1"] = true
stateService.userIds = ["1"]

Expand All @@ -350,27 +350,27 @@ 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: "[email protected]", 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"]

environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultUS.base)
environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultUS.base)
var userId = await subject.existingAccountUserId(email: "[email protected]")
XCTAssertEqual(userId, "1")

environmentService.baseURL = try XCTUnwrap(EnvironmentUrlData.defaultEU.base)
environmentService.baseURL = try XCTUnwrap(EnvironmentURLData.defaultEU.base)
userId = await subject.existingAccountUserId(email: "[email protected]")
XCTAssertEqual(userId, "2")
}

/// `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: "[email protected]", userId: "1"))
stateService.environmentUrls["1"] = .defaultUS
stateService.environmentURLs["1"] = .defaultUS
stateService.isAuthenticated["1"] = false
stateService.userIds = ["1"]

Expand Down Expand Up @@ -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 {
let urls = EnvironmentUrlData(base: .example)
let account = Account.fixture(settings: .fixture(environmentUrls: urls))
func test_setActiveAccount_loadsEnvironmentURLs() async throws {
let urls = EnvironmentURLData(base: .example)
let account = Account.fixture(settings: .fixture(environmentURLs: urls))
stateService.accounts = [account]
_ = try await subject.setActiveAccount(userId: account.profile.userId)
XCTAssertTrue(environmentService.didLoadURLsForActiveAccount)
Expand Down
4 changes: 2 additions & 2 deletions BitwardenShared/Core/Auth/Services/AuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions BitwardenShared/Core/Auth/Services/AuthServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -597,7 +597,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
appSettingsStore.appId = "App id"
await stateService.setTwoFactorToken("some token", email: "[email protected]")
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.
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -745,7 +745,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
appSettingsStore.appId = "App id"
await stateService.setTwoFactorToken("some token", email: "[email protected]")
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.
Expand Down Expand Up @@ -862,7 +862,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
appSettingsStore.appId = "App id"
await stateService.setTwoFactorToken("some token", email: "[email protected]")
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(
Expand Down Expand Up @@ -926,7 +926,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
appSettingsStore.appId = "App id"
await stateService.setTwoFactorToken("some token", email: "[email protected]")
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(
Expand Down Expand Up @@ -1095,7 +1095,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_
appSettingsStore.appId = "App id"
await stateService.setTwoFactorToken("some token", email: "[email protected]")
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.
Expand Down
9 changes: 5 additions & 4 deletions BitwardenShared/Core/Platform/Models/Domain/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,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(
Expand All @@ -73,7 +73,7 @@ extension Account {
userId: tokenPayload.userId
),
settings: AccountSettings(
environmentUrls: environmentUrls
environmentUrls: environmentURLs
),
_tokens: nil // Tokens have been moved out of `State` to the keychain.
)
Expand Down Expand Up @@ -140,7 +140,8 @@ extension Account {
// MARK: Properties

/// The environment URLs for an account.
var environmentUrls: EnvironmentUrlData?
/// The "URL" acronym in the variable name needs to remain lowercase for backwards compatibility.
var environmentUrls: EnvironmentURLData?
}

/// Domain model for an account's API tokens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit f50ef9b

Please sign in to comment.