Skip to content

Commit

Permalink
Fix recaptcha fall back tests (#11728)
Browse files Browse the repository at this point in the history
  • Loading branch information
renkelvin authored Aug 25, 2023
1 parent 05b088d commit 2e7eecd
Showing 1 changed file with 50 additions and 43 deletions.
93 changes: 50 additions & 43 deletions FirebaseAuth/Tests/Unit/FIRAuthTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ - (void)testSignInWithEmailPasswordWithRecaptchaFallbackSuccess {
id mockVerifier = OCMClassMock([FIRAuthRecaptchaVerifier class]);
OCMStub([mockVerifier sharedRecaptchaVerifier:[FIRAuth auth]]).andReturn(mockVerifier);
OCMExpect([mockVerifier enablementStatusForProvider:FIRAuthRecaptchaProviderPassword])
.andReturn(YES);
.andReturn(NO);
FIRVerifyPasswordRequest *constRequestWithRecaptchaToken =
[[FIRVerifyPasswordRequest alloc] initWithEmail:kEmail
password:kFakePassword
Expand All @@ -714,10 +714,18 @@ - (void)testSignInWithEmailPasswordWithRecaptchaFallbackSuccess {
XCTAssertEqualObjects(request.email, kEmail);
XCTAssertEqualObjects(request.password, kFakePassword);
XCTAssertTrue(request.returnSecureToken);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{
FIRAuthErrorUserInfoDeserializedResponseKey :
@{@"message" : @"MISSING_RECAPTCHA_TOKEN"}
}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
id mockVerifyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]);
[self stubTokensWithMockResponse:mockVerifyPasswordResponse];
callback(mockVerifyPasswordResponse, nil);
callback(nil, error);
});
});
OCMExpect([_mockBackend verifyPassword:[OCMArg any] callback:[OCMArg any]])
Expand All @@ -727,15 +735,10 @@ - (void)testSignInWithEmailPasswordWithRecaptchaFallbackSuccess {
XCTAssertEqualObjects(request.email, kEmail);
XCTAssertEqualObjects(request.password, kFakePassword);
XCTAssertTrue(request.returnSecureToken);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : @"MISSING_RECAPTCHA_TOKEN"}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback(nil, error);
id mockVerifyPasswordResponse = OCMClassMock([FIRVerifyPasswordResponse class]);
[self stubTokensWithMockResponse:mockVerifyPasswordResponse];
callback(mockVerifyPasswordResponse, nil);
});
});
[self expectGetAccountInfo];
Expand Down Expand Up @@ -1852,19 +1855,14 @@ - (void)testCreateUserWithEmailPasswordWithRecaptchaVerificationSuccess {
[self assertUser:[FIRAuth auth].currentUser];
}

/** @fn testCreateUserWithEmailPasswordWithRecaptchaVerificationFallbackSuccess
/** @fn testCreateUserWithEmailPasswordWithRecaptchaFallbackSuccess
@brief Tests the flow of a successful @c createUserWithEmail:password:completion: call.
*/
- (void)testCreateUserWithEmailPasswordWithRecaptchaVerificationFallbackSuccess {
- (void)testCreateUserWithEmailPasswordWithRecaptchaFallbackSuccess {
id mockVerifier = OCMClassMock([FIRAuthRecaptchaVerifier class]);
OCMStub([mockVerifier sharedRecaptchaVerifier:[FIRAuth auth]]).andReturn(mockVerifier);
OCMExpect([mockVerifier enablementStatusForProvider:FIRAuthRecaptchaProviderPassword])
.andReturn(YES);
FIRSignUpNewUserRequest *constRequest =
[[FIRSignUpNewUserRequest alloc] initWithEmail:kEmail
password:kFakePassword
displayName:kDisplayName
requestConfiguration:[FIRAuth auth].requestConfiguration];
.andReturn(NO);
FIRSignUpNewUserRequest *constRequestWithRecaptchaToken =
[[FIRSignUpNewUserRequest alloc] initWithEmail:kEmail
password:kFakePassword
Expand All @@ -1877,7 +1875,7 @@ - (void)testCreateUserWithEmailPasswordWithRecaptchaVerificationFallbackSuccess
provider:FIRAuthRecaptchaProviderPassword
action:FIRAuthRecaptchaActionSignUpPassword
completion:([OCMArg invokeBlockWithArgs:constRequestWithRecaptchaToken, nil])]);
OCMExpect([_mockBackend signUpNewUser:constRequest callback:[OCMArg any]])
OCMExpect([_mockBackend signUpNewUser:[OCMArg any] callback:[OCMArg any]])
.andCallBlock2(^(FIRSignUpNewUserRequest *_Nullable request,
FIRSignupNewUserCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
Expand All @@ -1887,15 +1885,18 @@ - (void)testCreateUserWithEmailPasswordWithRecaptchaVerificationFallbackSuccess
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : @"MISSING_RECAPTCHA_TOKEN"}];
userInfo:@{
FIRAuthErrorUserInfoDeserializedResponseKey :
@{@"message" : @"MISSING_RECAPTCHA_TOKEN"}
}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback(nil, error);
});
});
OCMExpect([_mockBackend signUpNewUser:constRequestWithRecaptchaToken callback:[OCMArg any]])
OCMExpect([_mockBackend signUpNewUser:[OCMArg any] callback:[OCMArg any]])
.andCallBlock2(
^(FIRSignUpNewUserRequest *_Nullable request, FIRSignupNewUserCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
Expand Down Expand Up @@ -2131,7 +2132,7 @@ - (void)testSendPasswordResetEmailWithRecaptchaFallbackSuccess {
id mockVerifier = OCMClassMock([FIRAuthRecaptchaVerifier class]);
OCMStub([mockVerifier sharedRecaptchaVerifier:[FIRAuth auth]]).andReturn(mockVerifier);
OCMExpect([mockVerifier enablementStatusForProvider:FIRAuthRecaptchaProviderPassword])
.andReturn(YES);
.andReturn(NO);
FIRGetOOBConfirmationCodeRequest *constRequestWithRecaptchaToken =
[FIRGetOOBConfirmationCodeRequest
passwordResetRequestWithEmail:kEmail
Expand All @@ -2149,24 +2150,27 @@ - (void)testSendPasswordResetEmailWithRecaptchaFallbackSuccess {
FIRGetOOBConfirmationCodeResponseCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
XCTAssertEqualObjects(request.email, kEmail);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{
FIRAuthErrorUserInfoDeserializedResponseKey :
@{@"message" : @"MISSING_RECAPTCHA_TOKEN"}
}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback([[FIRGetOOBConfirmationCodeResponse alloc] init], nil);
callback(nil, error);
});
});
OCMExpect([_mockBackend getOOBConfirmationCode:[OCMArg any] callback:[OCMArg any]])
.andCallBlock2(^(FIRGetOOBConfirmationCodeRequest *_Nullable request,
FIRGetOOBConfirmationCodeResponseCallback callback) {
XCTAssertEqualObjects(request.APIKey, kAPIKey);
XCTAssertEqualObjects(request.email, kEmail);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : @"MISSING_RECAPTCHA_TOKEN"}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback(nil, error);
callback([[FIRGetOOBConfirmationCodeResponse alloc] init], nil);
});
});
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
Expand Down Expand Up @@ -2274,7 +2278,7 @@ - (void)testSendSignInLinkToEmailWithRecaptchaFallbackSuccess {
id mockVerifier = OCMClassMock([FIRAuthRecaptchaVerifier class]);
OCMStub([mockVerifier sharedRecaptchaVerifier:[FIRAuth auth]]).andReturn(mockVerifier);
OCMExpect([mockVerifier enablementStatusForProvider:FIRAuthRecaptchaProviderPassword])
.andReturn(YES);
.andReturn(NO);
FIRGetOOBConfirmationCodeRequest *constRequestWithRecaptchaToken =
[FIRGetOOBConfirmationCodeRequest
signInWithEmailLinkRequest:kEmail
Expand All @@ -2294,8 +2298,18 @@ - (void)testSendSignInLinkToEmailWithRecaptchaFallbackSuccess {
XCTAssertEqualObjects(request.email, kEmail);
XCTAssertEqualObjects(request.continueURL, kContinueURL);
XCTAssertTrue(request.handleCodeInApp);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{
FIRAuthErrorUserInfoDeserializedResponseKey :
@{@"message" : @"MISSING_RECAPTCHA_TOKEN"}
}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback([[FIRGetOOBConfirmationCodeResponse alloc] init], nil);
callback(nil, error);
});
});
OCMExpect([_mockBackend getOOBConfirmationCode:[OCMArg any] callback:[OCMArg any]])
Expand All @@ -2305,15 +2319,8 @@ - (void)testSendSignInLinkToEmailWithRecaptchaFallbackSuccess {
XCTAssertEqualObjects(request.email, kEmail);
XCTAssertEqualObjects(request.continueURL, kContinueURL);
XCTAssertTrue(request.handleCodeInApp);
NSError *underlyingError =
[[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : @"MISSING_RECAPTCHA_TOKEN"}];
NSError *error = [[NSError alloc] initWithDomain:FIRAuthErrorDomain
code:FIRAuthErrorCodeInternalError
userInfo:@{NSUnderlyingErrorKey : underlyingError}];
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
callback(nil, error);
callback([[FIRGetOOBConfirmationCodeResponse alloc] init], nil);
});
});
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
Expand Down

0 comments on commit 2e7eecd

Please sign in to comment.