GetRecaptchaConfigTests.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License")
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. import XCTest
  16. @testable import FirebaseAuth
  17. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  18. class GetRecaptchaConfigTests: RPCBaseTests {
  19. /** @fn testGetRecaptchaConfigRequest
  20. @brief Tests get Recaptcha config request.
  21. */
  22. func testGetRecaptchaConfigRequest() async throws {
  23. let request = GetRecaptchaConfigRequest(requestConfiguration: makeRequestConfiguration())
  24. // let _ = try await AuthBackend.call(with: request)
  25. XCTAssertFalse(request.containsPostBody)
  26. // Confirm that the request has no decoded body as it is get request.
  27. XCTAssertNil(rpcIssuer.decodedRequest)
  28. let urlString = "https://identitytoolkit.googleapis.com/v2/recaptchaConfig?key=\(kTestAPIKey)" +
  29. "&clientType=CLIENT_TYPE_IOS&version=RECAPTCHA_ENTERPRISE"
  30. try await checkRequest(
  31. request: request,
  32. expected: urlString,
  33. key: "should_be_empty_dictionary",
  34. value: nil
  35. )
  36. }
  37. /** @fn testSuccessfulGetRecaptchaConfigRequest
  38. @brief This test simulates a successful @c getRecaptchaConfig Flow.
  39. */
  40. func testSuccessfulGetRecaptchaConfigRequest() async throws {
  41. let kTestRecaptchaKey = "projects/123/keys/456"
  42. let request = GetRecaptchaConfigRequest(requestConfiguration: makeRequestConfiguration())
  43. rpcIssuer.recaptchaSiteKey = kTestRecaptchaKey
  44. let response = try await AuthBackend.call(with: request)
  45. XCTAssertEqual(response.recaptchaKey, kTestRecaptchaKey)
  46. XCTAssertNil(response.enforcementState)
  47. }
  48. }