Skip to content

Commit

Permalink
add VerifyPhoneNumberWithRceAuditSuccess test
Browse files Browse the repository at this point in the history
  • Loading branch information
srushtisv committed Sep 10, 2024
1 parent 981939d commit 2639bcb
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions FirebaseAuth/Tests/Unit/PhoneAuthProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,45 @@
)
}

/**
@fn testVerifyPhoneNumberWithRceAudit
@brief Tests a successful invocation of @c verifyPhoneNumber with recaptcha enterprise in audit mode
*/
func testVerifyPhoneNumberWithRceAuditSuccess() async throws {
initApp(#function)
let auth = try XCTUnwrap(PhoneAuthProviderTests.auth)
let provider = PhoneAuthProvider.provider(auth: auth)
let mockVerifier = FakeAuthRecaptchaVerifier(captchaResponse: kCaptchaResponse)
AuthRecaptchaVerifier.setShared(mockVerifier, auth: auth)
rpcIssuer.rceMode = "AUDIT"
let requestExpectation = expectation(description: "verifyRequester")
rpcIssuer?.verifyRequester = { request in
XCTAssertEqual(request.phoneNumber, self.kTestPhoneNumber)
XCTAssertEqual(request.captchaResponse, self.kCaptchaResponse)
XCTAssertEqual(request.recaptchaVersion, "RECAPTCHA_ENTERPRISE")
XCTAssertEqual(request.codeIdentity, CodeIdentity.empty)
requestExpectation.fulfill()
do {
try self.rpcIssuer?
.respond(withJSON: [self.kVerificationIDKey: self.kTestVerificationID])
} catch {
XCTFail("Failure sending response: \(error)")
}
}
do {
let result = try await provider.verifyClAndSendVerificationCodeWithRecaptcha(
toPhoneNumber: kTestPhoneNumber,
retryOnInvalidAppCredential: false,
uiDelegate: nil,
recaptchaVerifier: mockVerifier
)
XCTAssertEqual(result, kTestVerificationID)
} catch {
XCTFail("Unexpected error")
}
await fulfillment(of: [requestExpectation], timeout: 5.0)
}

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

0 comments on commit 2639bcb

Please sign in to comment.