Skip to content

Commit

Permalink
RCE Unit Tests :Audit
Browse files Browse the repository at this point in the history
  • Loading branch information
srushtisv committed Sep 13, 2024
1 parent 2639bcb commit 400957c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions FirebaseAuth/Tests/Unit/PhoneAuthProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,53 @@
await fulfillment(of: [requestExpectation], timeout: 5.0)
}

/**
@fn testVerifyPhoneNumberWithRceAuditInvalidRecaptchaAndAPNFallbackSuccess
@brief Tests a successful invocation of @c verifyPhoneNumber with recaptcha enterprise in audit mode
*/
func testVerifyPhoneNumberWithRceAuditFallbackToAPNs() async throws {
initApp(#function)
let auth = try XCTUnwrap(PhoneAuthProviderTests.auth)
let provider = PhoneAuthProvider.provider(auth: auth)
let mockVerifier = FakeAuthRecaptchaVerifier()
AuthRecaptchaVerifier.setShared(mockVerifier, auth: auth)
rpcIssuer.rceMode = "AUDIT"
let invalidRecaptchaExpectation =
expectation(description: "verifyRequesterInvalidRecaptcha")
rpcIssuer?.verifyRequester = { request in
XCTAssertEqual(request.phoneNumber, self.kTestPhoneNumber)
XCTAssertEqual(request.captchaResponse, "NO_RECAPTCHA")
XCTAssertEqual(request.recaptchaVersion, "RECAPTCHA_ENTERPRISE")
XCTAssertEqual(request.codeIdentity, CodeIdentity.empty)
invalidRecaptchaExpectation.fulfill()
do {
try self.rpcIssuer?.respond(
serverErrorMessage: "INVALID_RECAPTCHA_TOKEN",
error: AuthErrorUtils.invalidRecaptchaTokenError() as NSError
)
} catch {
XCTFail("Failure sending response: \(error)")
}
}

do {
_ = try await provider.verifyClAndSendVerificationCodeWithRecaptcha(
toPhoneNumber: kTestPhoneNumber,
retryOnInvalidAppCredential: false,
uiDelegate: nil,
recaptchaVerifier: mockVerifier
)
} catch {
// Check for the correct error
let underlyingError = (error as NSError).userInfo[NSUnderlyingErrorKey] as? NSError
let rootError = underlyingError?.userInfo[NSUnderlyingErrorKey] as? NSError
XCTAssertEqual(rootError?.code, AuthErrorCode.invalidRecaptchaToken.code.rawValue)
}

await fulfillment(of: [invalidRecaptchaExpectation], timeout: 5.0)
try internalFlowRetry(function: #function, goodRetry: true)
}

/** @fn testVerifyPhoneNumberInTestMode
@brief Tests a successful invocation of @c verifyPhoneNumber:completion: when app verification
is disabled.
Expand Down

0 comments on commit 400957c

Please sign in to comment.