Skip to content

Commit

Permalink
ran check.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoshouzi-gh committed Oct 2, 2023
1 parent a1143f7 commit fc33a81
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 61 deletions.
3 changes: 2 additions & 1 deletion FirebaseAuth/Sources/Backend/FIRAuthBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ typedef void (^FIRFinalizePasskeyEnrollmentResponseCallback)(
callback:(FIRStartPasskeyEnrollmentResponseCallback)callback;

/** @fn finalizePasskeyEnrollment:callback:
@brief Calls the finalizePasskeyEnrollment endpoint, which is responsible for sending the platform credential details to GCIP backend to exchange the access token and refresh token.
@brief Calls the finalizePasskeyEnrollment endpoint, which is responsible for sending the
platform credential details to GCIP backend to exchange the access token and refresh token.
@param request The request parameters.
@param callback The callback.
*/
Expand Down
17 changes: 9 additions & 8 deletions FirebaseAuth/Sources/Backend/FIRAuthBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#import "FirebaseAuth/Sources/Backend/RPC/FIRDeleteAccountResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIREmailLinkSignInResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeyEnrollmentRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeyEnrollmentResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeRequest.h"
Expand Down Expand Up @@ -64,16 +66,12 @@
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyCustomTokenResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPasswordRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPasswordResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPhoneNumberRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyPhoneNumberResponse.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeyEnrollmentRequest.h"
#import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeyEnrollmentResponse.h"
#import "FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h"
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"

Expand Down Expand Up @@ -684,8 +682,9 @@ + (void)startPasskeyEnrollment:(FIRStartPasskeyEnrollmentRequest *)request
callback:(FIRStartPasskeyEnrollmentResponseCallback)callback {
[[self implementation] startPasskeyEnrollment:request callback:callback];
}

+ (void)finalizePasskeyEnrollment:(FIRFinalizePasskeyEnrollmentRequest *)request callback:(FIRFinalizePasskeyEnrollmentResponseCallback)callback {

+ (void)finalizePasskeyEnrollment:(FIRFinalizePasskeyEnrollmentRequest *)request
callback:(FIRFinalizePasskeyEnrollmentResponseCallback)callback {
[[self implementation] finalizePasskeyEnrollment:request callback:callback];
}
#endif
Expand Down Expand Up @@ -1131,8 +1130,10 @@ - (void)startPasskeyEnrollment:(FIRStartPasskeyEnrollmentRequest *)request
}];
}

- (void)finalizePasskeyEnrollment:(FIRFinalizePasskeyEnrollmentRequest *)request callback:(FIRFinalizePasskeyEnrollmentResponseCallback)callback {
FIRFinalizePasskeyEnrollmentResponse *response = [[FIRFinalizePasskeyEnrollmentResponse alloc] init];
- (void)finalizePasskeyEnrollment:(FIRFinalizePasskeyEnrollmentRequest *)request
callback:(FIRFinalizePasskeyEnrollmentResponseCallback)callback {
FIRFinalizePasskeyEnrollmentResponse *response =
[[FIRFinalizePasskeyEnrollmentResponse alloc] init];
[self callWithRequest:request
response:response
callback:^(NSError *error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

#import <AuthenticationServices/ASAuthorizationPlatformPublicKeyCredentialRegistration.h>
#import "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h"
#import "FirebaseAuth/Sources/Backend/FIRIdentityToolkitRequest.h"
#import <AuthenticationServices/ASAuthorizationPlatformPublicKeyCredentialRegistration.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -50,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, readonly) NSString *clientDataJson;

/**
@property attestationObject
@brief The attestation object from the authenticator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
*/
static NSString *const kAttestationObject = @"attestationObject";


@implementation FIRFinalizePasskeyEnrollmentRequest

- (nullable instancetype)initWithIDToken:(NSString *)IDToken
name:(NSString *)name
credentialID:(NSString *)credentialID
clientDataJson:(NSString *)clientDataJson
attestationObject:(NSString *)attestationObject requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
attestationObject:(NSString *)attestationObject
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
self = [super initWithEndpoint:kFinalizePasskeyEnrollmentEndPoint
requestConfiguration:requestConfiguration];
if (self) {
Expand All @@ -96,7 +96,7 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
NSMutableDictionary *authRegistrationResponse = [NSMutableDictionary dictionary];
NSMutableDictionary *authAttestationResponse = [NSMutableDictionary dictionary];

if (_IDToken) {
postBody[kIDTokenKey] = _IDToken;
}
Expand All @@ -115,10 +115,10 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
if (self.tenantID) {
postBody[kTenantIDKey] = self.tenantID;
}

authRegistrationResponse[kAuthAttestationRespKey] = authAttestationResponse;
postBody[kAuthRegistrationRespKey] = authRegistrationResponse;

return [postBody copy];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
*/
static const NSString *kRefreshTokenKey = @"refreshToken";


@implementation FIRFinalizePasskeyEnrollmentResponse

- (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary
Expand All @@ -39,7 +38,7 @@ - (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary
if (dictionary[kRefreshTokenKey] == nil) {
return NO;
}

_idToken = dictionary[kIdTokenKey];
_refreshToken = dictionary[kRefreshTokenKey];
return YES;
Expand Down
30 changes: 22 additions & 8 deletions FirebaseAuth/Tests/Unit/FIRFinalizePasskeyEnrollmentRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,32 @@ - (void)tearDown {

- (void)testFinalizePasskeyEnrollmentRequest {
if (@available(iOS 15.0, *)) {
FIRFinalizePasskeyEnrollmentRequest *request = [[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken name:kName credentialID:kCredentialID clientDataJson:kRawClientDataJSON attestationObject:kRawAttestationObject requestConfiguration:_requestConfiguration];

[FIRAuthBackend finalizePasskeyEnrollment:request callback:^(FIRFinalizePasskeyEnrollmentResponse * _Nullable response, NSError * _Nullable error) {
}];
FIRFinalizePasskeyEnrollmentRequest *request =
[[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken
name:kName
credentialID:kCredentialID
clientDataJson:kRawClientDataJSON
attestationObject:kRawAttestationObject
requestConfiguration:_requestConfiguration];

[FIRAuthBackend
finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error){
}];
XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
XCTAssertNotNil(_RPCIssuer.decodedRequest);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kIDTokenKey], kIDToken);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kNameKey], kName);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAuthRegistrationRespKey][kAuthAttestationRespKey][kRawClientDataJSONKey], kRawClientDataJSON);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAuthRegistrationRespKey][kAuthAttestationRespKey][kRawAttestationObjectKey], kRawAttestationObject);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAuthRegistrationRespKey][kCredentialIDKey], kCredentialID);

XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAuthRegistrationRespKey]
[kAuthAttestationRespKey][kRawClientDataJSONKey],
kRawClientDataJSON);
XCTAssertEqualObjects(
_RPCIssuer.decodedRequest[kAuthRegistrationRespKey][kAuthAttestationRespKey]
[kRawAttestationObjectKey],
kRawAttestationObject);
XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAuthRegistrationRespKey][kCredentialIDKey],
kCredentialID);
}
}

Expand Down
91 changes: 56 additions & 35 deletions FirebaseAuth/Tests/Unit/FIRFinalizePasskeyEnrollmentResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,32 @@ - (void)tearDown {
*/
- (void)testSuccessfulFinalizePasskeyEnrollmentResponse {
if (@available(iOS 15.0, *)) {
FIRFinalizePasskeyEnrollmentRequest *request = [[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken name:kName credentialID:kCredentialID clientDataJson:kRawClientDataJSON attestationObject:kRawAttestationObject requestConfiguration:_requestConfiguration];
FIRFinalizePasskeyEnrollmentRequest *request =
[[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken
name:kName
credentialID:kCredentialID
clientDataJson:kRawClientDataJSON
attestationObject:kRawAttestationObject
requestConfiguration:_requestConfiguration];

__block BOOL callbackInvoked;
__block FIRFinalizePasskeyEnrollmentResponse *RPCResponse;
__block NSError *RPCError;

[FIRAuthBackend finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];


[FIRAuthBackend
finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];

[_RPCIssuer respondWithJSON:@{
@"idToken" : kIDToken,
@"refreshToken": kRefreshToken,
@"refreshToken" : kRefreshToken,
}];

XCTAssert(callbackInvoked);
XCTAssertNil(RPCError);
XCTAssertNotNil(RPCResponse);
Expand All @@ -145,20 +152,27 @@ - (void)testSuccessfulFinalizePasskeyEnrollmentResponse {
*/
- (void)testFinalizePasskeyEnrollmentResponseMissingIDTokenError {
if (@available(iOS 15.0, *)) {
FIRFinalizePasskeyEnrollmentRequest *request = [[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken name:kName credentialID:kCredentialID clientDataJson:kRawClientDataJSON attestationObject:kRawAttestationObject requestConfiguration:_requestConfiguration];

FIRFinalizePasskeyEnrollmentRequest *request =
[[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken
name:kName
credentialID:kCredentialID
clientDataJson:kRawClientDataJSON
attestationObject:kRawAttestationObject
requestConfiguration:_requestConfiguration];

__block BOOL callbackInvoked;
__block FIRFinalizePasskeyEnrollmentResponse *RPCResponse;
__block NSError *RPCError;

[FIRAuthBackend finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];


[FIRAuthBackend
finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];

[_RPCIssuer respondWithJSON:@{
@"wrongkey" : @{},
@"refreshToken" : kRefreshToken,
Expand All @@ -174,20 +188,27 @@ - (void)testFinalizePasskeyEnrollmentResponseMissingIDTokenError {
*/
- (void)testFinalizePasskeyEnrollmentResponseMissingRefreshTokenError {
if (@available(iOS 15.0, *)) {
FIRFinalizePasskeyEnrollmentRequest *request = [[FIRFinalizePasskeyEnrollmentRequest alloc]initWithIDToken:kIDToken name:kName credentialID:kCredentialID clientDataJson:kRawClientDataJSON attestationObject:kRawAttestationObject requestConfiguration:_requestConfiguration];
FIRFinalizePasskeyEnrollmentRequest *request =
[[FIRFinalizePasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken
name:kName
credentialID:kCredentialID
clientDataJson:kRawClientDataJSON
attestationObject:kRawAttestationObject
requestConfiguration:_requestConfiguration];

__block BOOL callbackInvoked;
__block FIRFinalizePasskeyEnrollmentResponse *RPCResponse;
__block NSError *RPCError;

[FIRAuthBackend finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];


[FIRAuthBackend
finalizePasskeyEnrollment:request
callback:^(FIRFinalizePasskeyEnrollmentResponse *_Nullable response,
NSError *_Nullable error) {
callbackInvoked = YES;
RPCResponse = response;
RPCError = error;
}];

[_RPCIssuer respondWithJSON:@{
@"wrongkey" : @{},
@"idToken" : kIDToken,
Expand All @@ -204,7 +225,8 @@ - (void)testFinalizePasskeyEnrollmentResponseMissingRefreshTokenError {
*/
- (void)errorValidationHelperWithCallbackInvoked:(BOOL)callbackInvoked
rpcError:(NSError *)RPCError
rpcResponse:(FIRFinalizePasskeyEnrollmentResponse *)RPCResponse {
rpcResponse:
(FIRFinalizePasskeyEnrollmentResponse *)RPCResponse {
XCTAssert(callbackInvoked);
XCTAssertNotNil(RPCError);
XCTAssertEqualObjects(RPCError.domain, FIRAuthErrorDomain);
Expand All @@ -218,4 +240,3 @@ - (void)errorValidationHelperWithCallbackInvoked:(BOOL)callbackInvoked

@end
#endif

0 comments on commit fc33a81

Please sign in to comment.