Skip to content

Commit 2639bcb

Browse files
committed
add VerifyPhoneNumberWithRceAuditSuccess test
1 parent 981939d commit 2639bcb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

FirebaseAuth/Tests/Unit/PhoneAuthProviderTests.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,45 @@
208208
)
209209
}
210210

211+
/**
212+
@fn testVerifyPhoneNumberWithRceAudit
213+
@brief Tests a successful invocation of @c verifyPhoneNumber with recaptcha enterprise in audit mode
214+
*/
215+
func testVerifyPhoneNumberWithRceAuditSuccess() async throws {
216+
initApp(#function)
217+
let auth = try XCTUnwrap(PhoneAuthProviderTests.auth)
218+
let provider = PhoneAuthProvider.provider(auth: auth)
219+
let mockVerifier = FakeAuthRecaptchaVerifier(captchaResponse: kCaptchaResponse)
220+
AuthRecaptchaVerifier.setShared(mockVerifier, auth: auth)
221+
rpcIssuer.rceMode = "AUDIT"
222+
let requestExpectation = expectation(description: "verifyRequester")
223+
rpcIssuer?.verifyRequester = { request in
224+
XCTAssertEqual(request.phoneNumber, self.kTestPhoneNumber)
225+
XCTAssertEqual(request.captchaResponse, self.kCaptchaResponse)
226+
XCTAssertEqual(request.recaptchaVersion, "RECAPTCHA_ENTERPRISE")
227+
XCTAssertEqual(request.codeIdentity, CodeIdentity.empty)
228+
requestExpectation.fulfill()
229+
do {
230+
try self.rpcIssuer?
231+
.respond(withJSON: [self.kVerificationIDKey: self.kTestVerificationID])
232+
} catch {
233+
XCTFail("Failure sending response: \(error)")
234+
}
235+
}
236+
do {
237+
let result = try await provider.verifyClAndSendVerificationCodeWithRecaptcha(
238+
toPhoneNumber: kTestPhoneNumber,
239+
retryOnInvalidAppCredential: false,
240+
uiDelegate: nil,
241+
recaptchaVerifier: mockVerifier
242+
)
243+
XCTAssertEqual(result, kTestVerificationID)
244+
} catch {
245+
XCTFail("Unexpected error")
246+
}
247+
await fulfillment(of: [requestExpectation], timeout: 5.0)
248+
}
249+
211250
/** @fn testVerifyPhoneNumberInTestMode
212251
@brief Tests a successful invocation of @c verifyPhoneNumber:completion: when app verification
213252
is disabled.

0 commit comments

Comments
 (0)