Skip to content

Commit

Permalink
[Auth] Make AuthBackend and related types Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Nov 14, 2024
1 parent b91dfda commit 29c35b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AuthRPCRequest>(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))"
}
Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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() {
Expand Down
17 changes: 8 additions & 9 deletions FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -77,8 +76,8 @@ class FakeBackendRPCIssuer: AuthBackendRPCIssuer {
var secureTokenErrorString: String?
var recaptchaSiteKey = "unset recaptcha siteKey"

override func asyncCallToURL<T>(with request: T, body: Data?,
contentType: String) async -> (Data?, Error?)
func asyncCallToURL<T>(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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 29c35b8

Please sign in to comment.