From 29c35b8323788b1d7445a797205287d404b33bea Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Thu, 14 Nov 2024 14:50:08 -0500 Subject: [PATCH] [Auth] Make AuthBackend and related types Sendable --- .../Sources/Swift/Backend/AuthBackend.swift | 4 ++-- .../Swift/Backend/AuthBackendRPCIssuer.swift | 8 ++++---- .../Tests/Unit/Fakes/FakeBackendRPCIssuer.swift | 17 ++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift b/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift index 85802392052..474f665147f 100644 --- a/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift +++ b/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift @@ -22,12 +22,12 @@ import Foundation #endif @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) -protocol AuthBackendProtocol { +protocol AuthBackendProtocol: Sendable { func call(with request: T) async throws -> T.Response } @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) -class AuthBackend: AuthBackendProtocol { +final class AuthBackend: AuthBackendProtocol { static func authUserAgent() -> String { return "FirebaseAuth.iOS/\(FirebaseVersion()) \(GTMFetcherStandardUserAgentString(nil))" } diff --git a/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift b/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift index 01001c5d712..6d2c540ff37 100644 --- a/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift +++ b/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift @@ -16,13 +16,13 @@ import FirebaseCore import FirebaseCoreExtension import Foundation #if COCOAPODS - import GTMSessionFetcher + @preconcurrency import GTMSessionFetcher #else - import GTMSessionFetcherCore + @preconcurrency import GTMSessionFetcherCore #endif @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) -protocol AuthBackendRPCIssuerProtocol { +protocol AuthBackendRPCIssuerProtocol: Sendable { /// Asynchronously send a HTTP request. /// - Parameter request: The request to be made. /// - Parameter body: Request body. @@ -35,7 +35,7 @@ protocol AuthBackendRPCIssuerProtocol { } @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) -class AuthBackendRPCIssuer: AuthBackendRPCIssuerProtocol { +final class AuthBackendRPCIssuer: AuthBackendRPCIssuerProtocol { let fetcherService: GTMSessionFetcherService init() { diff --git a/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift b/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift index e09e8d2106c..3a40aac37d7 100644 --- a/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift +++ b/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift @@ -17,13 +17,12 @@ import XCTest @testable import FirebaseAuth -// TODO: Investigate making this class support generics for the `request`. -/** @class FakeBackendRPCIssuer - @brief An implementation of @c AuthBackendRPCIssuer which is used to test backend request, - response, and glue logic. - */ +// TODO(ncooke3): Investigate making this class support generics for the `request`. +// TODO(ncooke3): Refactor to make checked Sendable. +/// An implementation of `AuthBackendRPCIssuerProtocol` which is used to test +/// backend request, response, and glue logic. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) -class FakeBackendRPCIssuer: AuthBackendRPCIssuer { +final class FakeBackendRPCIssuer: AuthBackendRPCIssuerProtocol, @unchecked Sendable { /** @property requestURL @brief The URL which was requested. */ @@ -77,8 +76,8 @@ class FakeBackendRPCIssuer: AuthBackendRPCIssuer { var secureTokenErrorString: String? var recaptchaSiteKey = "unset recaptcha siteKey" - override func asyncCallToURL(with request: T, body: Data?, - contentType: String) async -> (Data?, Error?) + func asyncCallToURL(with request: T, body: Data?, + contentType: String) async -> (Data?, Error?) where T: FirebaseAuth.AuthRPCRequest { return await withCheckedContinuation { continuation in self.asyncCallToURL(with: request, body: body, contentType: contentType) { data, error in @@ -172,7 +171,7 @@ class FakeBackendRPCIssuer: AuthBackendRPCIssuer { } func respond(serverErrorMessage errorMessage: String, error: NSError) throws { - let _ = try respond(withJSON: ["error": ["message": errorMessage]], error: error) + _ = try respond(withJSON: ["error": ["message": errorMessage]], error: error) } @discardableResult func respond(underlyingErrorMessage errorMessage: String,