Skip to content

Commit 400957c

Browse files
committed
RCE Unit Tests :Audit
1 parent 2639bcb commit 400957c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

FirebaseAuth/Tests/Unit/PhoneAuthProviderTests.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,53 @@
247247
await fulfillment(of: [requestExpectation], timeout: 5.0)
248248
}
249249

250+
/**
251+
@fn testVerifyPhoneNumberWithRceAuditInvalidRecaptchaAndAPNFallbackSuccess
252+
@brief Tests a successful invocation of @c verifyPhoneNumber with recaptcha enterprise in audit mode
253+
*/
254+
func testVerifyPhoneNumberWithRceAuditFallbackToAPNs() async throws {
255+
initApp(#function)
256+
let auth = try XCTUnwrap(PhoneAuthProviderTests.auth)
257+
let provider = PhoneAuthProvider.provider(auth: auth)
258+
let mockVerifier = FakeAuthRecaptchaVerifier()
259+
AuthRecaptchaVerifier.setShared(mockVerifier, auth: auth)
260+
rpcIssuer.rceMode = "AUDIT"
261+
let invalidRecaptchaExpectation =
262+
expectation(description: "verifyRequesterInvalidRecaptcha")
263+
rpcIssuer?.verifyRequester = { request in
264+
XCTAssertEqual(request.phoneNumber, self.kTestPhoneNumber)
265+
XCTAssertEqual(request.captchaResponse, "NO_RECAPTCHA")
266+
XCTAssertEqual(request.recaptchaVersion, "RECAPTCHA_ENTERPRISE")
267+
XCTAssertEqual(request.codeIdentity, CodeIdentity.empty)
268+
invalidRecaptchaExpectation.fulfill()
269+
do {
270+
try self.rpcIssuer?.respond(
271+
serverErrorMessage: "INVALID_RECAPTCHA_TOKEN",
272+
error: AuthErrorUtils.invalidRecaptchaTokenError() as NSError
273+
)
274+
} catch {
275+
XCTFail("Failure sending response: \(error)")
276+
}
277+
}
278+
279+
do {
280+
_ = try await provider.verifyClAndSendVerificationCodeWithRecaptcha(
281+
toPhoneNumber: kTestPhoneNumber,
282+
retryOnInvalidAppCredential: false,
283+
uiDelegate: nil,
284+
recaptchaVerifier: mockVerifier
285+
)
286+
} catch {
287+
// Check for the correct error
288+
let underlyingError = (error as NSError).userInfo[NSUnderlyingErrorKey] as? NSError
289+
let rootError = underlyingError?.userInfo[NSUnderlyingErrorKey] as? NSError
290+
XCTAssertEqual(rootError?.code, AuthErrorCode.invalidRecaptchaToken.code.rawValue)
291+
}
292+
293+
await fulfillment(of: [invalidRecaptchaExpectation], timeout: 5.0)
294+
try internalFlowRetry(function: #function, goodRetry: true)
295+
}
296+
250297
/** @fn testVerifyPhoneNumberInTestMode
251298
@brief Tests a successful invocation of @c verifyPhoneNumber:completion: when app verification
252299
is disabled.

0 commit comments

Comments
 (0)