Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] Make AuthBackend and related types Sendable #14125

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading