-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40f90b8
commit 83e8934
Showing
44 changed files
with
1,636 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
AuthenticatorShared/Core/Platform/Models/Domain/ServerConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import Foundation | ||
|
||
// MARK: - ServerConfig | ||
|
||
/// Model that represents the configuration provided by the server at a particular time. | ||
/// | ||
struct ServerConfig: Equatable, Codable, Sendable { | ||
// MARK: Properties | ||
|
||
/// The environment URLs of the server. | ||
let environment: EnvironmentServerConfig? | ||
|
||
/// The particular time of the server configuration. | ||
let date: Date | ||
|
||
/// Feature flags to configure the client. | ||
let featureStates: [FeatureFlag: AnyCodable] | ||
|
||
/// The git hash of the server. | ||
let gitHash: String | ||
|
||
/// Third party server information. | ||
let server: ThirdPartyServerConfig? | ||
|
||
/// The version of the server. | ||
let version: String | ||
|
||
init(date: Date, responseModel: ConfigResponseModel) { | ||
environment = responseModel.environment.map(EnvironmentServerConfig.init) | ||
self.date = date | ||
let features: [(FeatureFlag, AnyCodable)] | ||
features = responseModel.featureStates.compactMap { key, value in | ||
guard let flag = FeatureFlag(rawValue: key) else { return nil } | ||
return (flag, value) | ||
} | ||
featureStates = Dictionary(uniqueKeysWithValues: features) | ||
|
||
gitHash = responseModel.gitHash | ||
server = responseModel.server.map(ThirdPartyServerConfig.init) | ||
version = responseModel.version | ||
} | ||
} | ||
|
||
// MARK: - ThirdPartyServerConfig | ||
|
||
/// Model for third-party configuration of the server. | ||
/// | ||
struct ThirdPartyServerConfig: Equatable, Codable { | ||
/// The name of the third party configuration. | ||
let name: String | ||
|
||
/// The URL of the third party configuration. | ||
let url: String | ||
|
||
init(responseModel: ThirdPartyConfigResponseModel) { | ||
name = responseModel.name | ||
url = responseModel.url | ||
} | ||
} | ||
|
||
// MARK: - EnvironmentServerConfig | ||
|
||
/// Model for the environment URLs in a server configuration. | ||
struct EnvironmentServerConfig: Equatable, Codable { | ||
/// The API URL. | ||
let api: String? | ||
|
||
/// The Cloud Region (e.g. "US") | ||
let cloudRegion: String? | ||
|
||
/// The Identity URL. | ||
let identity: String? | ||
|
||
/// The Notifications URL. | ||
let notifications: String? | ||
|
||
/// The SSO URL. | ||
let sso: String? | ||
|
||
/// The Vault URL. | ||
let vault: String? | ||
|
||
init(responseModel: EnvironmentServerConfigResponseModel) { | ||
api = responseModel.api | ||
cloudRegion = responseModel.cloudRegion | ||
identity = responseModel.identity | ||
notifications = responseModel.notifications | ||
sso = responseModel.sso | ||
vault = responseModel.vault | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
AuthenticatorShared/Core/Platform/Models/Domain/ServerConfigTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
@testable import AuthenticatorShared | ||
|
||
final class ServerConfigTests: AuthenticatorTestCase { | ||
// MARK: Tests | ||
|
||
/// `init` properly converts feature flags | ||
func test_init_featureFlags() { | ||
let model = ConfigResponseModel( | ||
environment: nil, | ||
featureStates: [ | ||
"vault-onboarding": .bool(true), | ||
"test-remote-feature-flag": .bool(false), | ||
"not-a-real-feature-flag": .int(42), | ||
], | ||
gitHash: "123", | ||
server: nil, | ||
version: "1.2.3" | ||
) | ||
|
||
let subject = ServerConfig(date: Date(), responseModel: model) | ||
XCTAssertEqual(subject.featureStates, [.testRemoteFeatureFlag: .bool(false)]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
AuthenticatorShared/Core/Platform/Models/Enum/FeatureFlagTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import XCTest | ||
|
||
@testable import AuthenticatorShared | ||
|
||
final class FeatureFlagTests: AuthenticatorTestCase { | ||
// MARK: Tests | ||
|
||
/// `debugMenuFeatureFlags` does not include any test flags | ||
func test_debugMenu_testFlags() { | ||
let actual = FeatureFlag.debugMenuFeatureFlags.map(\.rawValue) | ||
let filtered = actual.filter { $0.hasPrefix("test-") } | ||
XCTAssertEqual(filtered, []) | ||
} | ||
|
||
/// `name` formats the raw value of a feature flag | ||
func test_name() { | ||
XCTAssertEqual(FeatureFlag.testLocalFeatureFlag.name, "Test Local Feature Flag") | ||
XCTAssertEqual(FeatureFlag.testLocalInitialBoolFlag.name, "Test Local Initial Bool Flag") | ||
XCTAssertEqual(FeatureFlag.testLocalInitialIntFlag.name, "Test Local Initial Int Flag") | ||
XCTAssertEqual(FeatureFlag.testLocalInitialStringFlag.name, "Test Local Initial String Flag") | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
AuthenticatorShared/Core/Platform/Services/API/Response/ConfigResponseModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Foundation | ||
import Networking | ||
|
||
// MARK: - ConfigResponseModel | ||
|
||
/// API response model for the configuration request. | ||
/// | ||
struct ConfigResponseModel: Equatable, JSONResponse { | ||
// MARK: Properties | ||
|
||
/// The environment URLs of the server. | ||
let environment: EnvironmentServerConfigResponseModel? | ||
|
||
/// Feature flags to configure the client. | ||
let featureStates: [String: AnyCodable] | ||
|
||
/// The git hash of the server. | ||
let gitHash: String | ||
|
||
/// Third party server information. | ||
let server: ThirdPartyConfigResponseModel? | ||
|
||
/// The version of the server. | ||
let version: String | ||
} | ||
|
||
/// API response model for third-party configuration in a configuration response. | ||
struct ThirdPartyConfigResponseModel: Equatable, JSONResponse { | ||
/// The name of the third party configuration. | ||
let name: String | ||
|
||
/// The URL of the third party configuration. | ||
let url: String | ||
} | ||
|
||
/// API response model for the environment URLs in a configuration response. | ||
struct EnvironmentServerConfigResponseModel: Equatable, JSONResponse { | ||
/// The API URL. | ||
let api: String? | ||
|
||
/// The Cloud Region (e.g. "US") | ||
let cloudRegion: String? | ||
|
||
/// The Identity URL. | ||
let identity: String? | ||
|
||
/// The Notifications URL. | ||
let notifications: String? | ||
|
||
/// The SSO URL. | ||
let sso: String? | ||
|
||
/// The Vault URL. | ||
let vault: String? | ||
} |
Oops, something went wrong.