From 4f7000a07beb29855b0f49c4b29c293c8f2c98e7 Mon Sep 17 00:00:00 2001 From: "Mohannad A. Hassan" Date: Sun, 5 Jan 2025 18:41:48 +0200 Subject: [PATCH] Fix typo in Persistence's name --- .../Sources/AuthentincationClientImpl.swift | 14 +++++----- .../{Persistance.swift => Persistence.swift} | 22 +++++++-------- .../Tests/AuthenticationClientTests.swift | 28 +++++++++---------- 3 files changed, 32 insertions(+), 32 deletions(-) rename Data/AuthenticationClient/Sources/{Persistance.swift => Persistence.swift} (82%) diff --git a/Data/AuthenticationClient/Sources/AuthentincationClientImpl.swift b/Data/AuthenticationClient/Sources/AuthentincationClientImpl.swift index 9afa87cf..64a463ef 100644 --- a/Data/AuthenticationClient/Sources/AuthentincationClientImpl.swift +++ b/Data/AuthenticationClient/Sources/AuthentincationClientImpl.swift @@ -14,9 +14,9 @@ import VLogging final class AuthenticationClientImpl: AuthenticationClient { // MARK: Lifecycle - init(configurations: OAuthAppConfiguration?, caller: OAuthCaller, persistance: Persistance) { + init(configurations: OAuthAppConfiguration?, caller: OAuthCaller, persistence: Persistence) { self.caller = caller - self.persistance = persistance + self.persistence = persistence appConfiguration = configurations } @@ -31,7 +31,7 @@ final class AuthenticationClientImpl: AuthenticationClient { public func login(on viewController: UIViewController) async throws { do { - try persistance.clear() + try persistence.clear() logger.info("Cleared previous authentication state before login") } catch { // If persisting the new state works, this error should be of little concern. @@ -54,7 +54,7 @@ final class AuthenticationClientImpl: AuthenticationClient { logger.error("restoreState invoked without OAuth client configurations being set") throw AuthenticationClientError.oauthClientHasNotBeenSet } - guard let state = try persistance.retrieve() else { + guard let state = try persistence.retrieve() else { logger.info("No previous authentication state found") return false } @@ -84,7 +84,7 @@ final class AuthenticationClientImpl: AuthenticationClient { // MARK: Private private let caller: OAuthCaller - private let persistance: Persistance + private let persistence: Persistence private var stateChangedCancellable: AnyCancellable? @@ -101,7 +101,7 @@ final class AuthenticationClientImpl: AuthenticationClient { private func persist(state: AuthenticationData) { do { - try persistance.persist(state: state) + try persistence.persist(state: state) } catch { // If this happens, the state will not nullified so to keep the current session usable // for the user. As for now, no workaround is in hand. @@ -115,7 +115,7 @@ extension AuthenticationClientImpl { self.init( configurations: configurations, caller: AppAuthCaller(), - persistance: KeychainPersistance() + persistence: KeychainPersistence() ) } } diff --git a/Data/AuthenticationClient/Sources/Persistance.swift b/Data/AuthenticationClient/Sources/Persistence.swift similarity index 82% rename from Data/AuthenticationClient/Sources/Persistance.swift rename to Data/AuthenticationClient/Sources/Persistence.swift index b560a790..0c382ded 100644 --- a/Data/AuthenticationClient/Sources/Persistance.swift +++ b/Data/AuthenticationClient/Sources/Persistence.swift @@ -1,5 +1,5 @@ // -// Persistance.swift +// Persistence.swift // QuranEngine // // Created by Mohannad Hassan on 28/12/2024. @@ -8,13 +8,13 @@ import Foundation import VLogging -enum PersistanceError: Error { - case persistanceFailed +enum PersistenceError: Error { + case persistenceFailed case retrievalFailed } -/// An abstraction for secure persistance of the authentication state. -protocol Persistance { +/// An abstraction for secure persistence of the authentication state. +protocol Persistence { func persist(state: AuthenticationData) throws func retrieve() throws -> AuthenticationData? @@ -22,7 +22,7 @@ protocol Persistance { func clear() throws } -final class KeychainPersistance: Persistance { +final class KeychainPersistence: Persistence { private let itemKey = "com.quran.oauth.state" func persist(state: AuthenticationData) throws { @@ -35,7 +35,7 @@ final class KeychainPersistance: Persistance { let status = SecItemAdd(addquery as CFDictionary, nil) if status != errSecSuccess { logger.error("Failed to persist state -- \(status) status") - throw PersistanceError.persistanceFailed + throw PersistenceError.persistenceFailed } logger.info("State persisted successfully") } @@ -54,14 +54,14 @@ final class KeychainPersistance: Persistance { return nil } else if status != errSecSuccess { logger.error("Failed to retrieve state -- \(status) status") - throw PersistanceError.retrievalFailed + throw PersistenceError.retrievalFailed } guard let data = result as? Data else { logger.error("Invalid data type found") - throw PersistanceError.retrievalFailed + throw PersistenceError.retrievalFailed } - // Both AuthenticationData and Persistance are internal types to the package, so it's + // Both AuthenticationData and Persistence are internal types to the package, so it's // good enough to hardcode the type here. No need for the hassle of the extra field. let state = try JSONDecoder().decode(AppAuthAuthenticationData.self, from: data) logger.info("AuthenticationData restored.") @@ -77,7 +77,7 @@ final class KeychainPersistance: Persistance { let status = SecItemDelete(query as CFDictionary) if status != errSecSuccess && status != errSecItemNotFound { logger.error("Failed to clear state -- \(status) status") - throw PersistanceError.persistanceFailed + throw PersistenceError.persistenceFailed } } } diff --git a/Data/AuthenticationClient/Tests/AuthenticationClientTests.swift b/Data/AuthenticationClient/Tests/AuthenticationClientTests.swift index 830937d1..b45656db 100644 --- a/Data/AuthenticationClient/Tests/AuthenticationClientTests.swift +++ b/Data/AuthenticationClient/Tests/AuthenticationClientTests.swift @@ -24,7 +24,7 @@ final class AuthenticationClientTests: XCTestCase { override func setUp() { caller = OAuthCallerMock() - persistance = PersistanceMock() + persistence = PersistenceMock() } func testNoConfigurations() async throws { @@ -39,7 +39,7 @@ final class AuthenticationClientTests: XCTestCase { func testLoginSuccessful() async throws { sut.set(appConfiguration: configuration) - persistance.currentState = AutehenticationDataMock() + persistence.currentState = AutehenticationDataMock() let state = AutehenticationDataMock() state.accessToken = "abcd" @@ -47,8 +47,8 @@ final class AuthenticationClientTests: XCTestCase { try await sut.login(on: UIViewController()) - XCTAssertTrue(persistance.clearCalled, "Expected to clear the persistance first") - XCTAssertEqual((persistance.currentState as? AutehenticationDataMock), state, "Expected to update the new state") + XCTAssertTrue(persistence.clearCalled, "Expected to clear the persistence first") + XCTAssertEqual((persistence.currentState as? AutehenticationDataMock), state, "Expected to update the new state") XCTAssertEqual(sut.authenticationState, .authenticated, "Expected the auth manager to be in authenticated state") } @@ -57,7 +57,7 @@ final class AuthenticationClientTests: XCTestCase { let state = AutehenticationDataMock() state.accessToken = "abcd" - persistance.currentState = state + persistence.currentState = state let result = try await sut.restoreState() XCTAssert(result, "Expected to be signed in successfully") @@ -67,7 +67,7 @@ final class AuthenticationClientTests: XCTestCase { func testRestorationButNotAuthenticated() async throws { sut.set(appConfiguration: configuration) - persistance.currentState = nil + persistence.currentState = nil let result = try await sut.restoreState() XCTAssertFalse(result, "Expected to not be signed in") @@ -79,7 +79,7 @@ final class AuthenticationClientTests: XCTestCase { let state = AutehenticationDataMock() state.accessToken = "abcd" - persistance.currentState = state + persistence.currentState = state _ = try await sut.restoreState() let inputRequest = URLRequest(url: URL(string: "https://example.com")!) @@ -100,19 +100,19 @@ final class AuthenticationClientTests: XCTestCase { let state = AutehenticationDataMock() state.accessToken = "abcd" - persistance.currentState = state + persistence.currentState = state _ = try await sut.restoreState() - // Clear the mock persistance for test's sake - persistance.currentState = nil - persistance.clearCalled = false + // Clear the mock persistence for test's sake + persistence.currentState = nil + persistence.clearCalled = false // Change the state state.accessToken = "xyz" XCTAssertEqual( - (persistance.currentState as? AutehenticationDataMock)?.accessToken, + (persistence.currentState as? AutehenticationDataMock)?.accessToken, "xyz", "Expected to persist the refreshed state" ) @@ -127,7 +127,7 @@ final class AuthenticationClientTests: XCTestCase { private var sut: AuthenticationClientImpl! private var caller: OAuthCallerMock! - private var persistance: PersistanceMock! + private var persistence: PersistenceMock! } private final class OAuthCallerMock: OAuthCaller { @@ -181,7 +181,7 @@ private final class AutehenticationDataMock: Equatable, AuthenticationData { } } -private final class PersistanceMock: Persistance { +private final class PersistenceMock: Persistence { var clearCalled = false var currentState: AuthenticationData?