GetProjectConfigTests.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 GetProjectConfigTests: RPCBaseTests {
  19. /** @var kGetProjectConfigEndPoint
  20. @brief The "getProjectConfig" endpoint.
  21. */
  22. let kGetProjectConfigEndPoint = "getProjectConfig"
  23. /** @var kExpectedAPIURL
  24. @brief The expected URL for the test calls.
  25. */
  26. let kExpectedAPIURL =
  27. "https://www.googleapis.com/identitytoolkit/v3/relyingparty/getProjectConfig?key=APIKey"
  28. func testGetProjectConfig() async throws {
  29. let kMissingAPIKeyErrorMessage = "MISSING_API_KEY"
  30. try await checkRequest(
  31. request: makeGetProjectConfigRequest(),
  32. expected: kExpectedAPIURL,
  33. key: kTestAPIKey,
  34. value: kGetProjectConfigEndPoint,
  35. checkPostBody: true
  36. )
  37. // This test simulates a missing API key error. Since the API key is provided to the backend
  38. // from the auth library this error should map to an internal error.
  39. try await checkBackendError(
  40. request: makeGetProjectConfigRequest(),
  41. message: kMissingAPIKeyErrorMessage,
  42. errorCode: AuthErrorCode.internalError
  43. )
  44. }
  45. /** @fn testSuccessFulGetProjectConfigRequest
  46. @brief This test checks for a successful response
  47. */
  48. func testSuccessfulGetProjectConfigRequest() async throws {
  49. let kTestProjectID = "21141651616"
  50. let kTestDomain1 = "localhost"
  51. let kTestDomain2 = "example.firebaseapp.com"
  52. rpcIssuer?.respondBlock = {
  53. try self.rpcIssuer?.respond(withJSON: ["projectId": kTestProjectID,
  54. "authorizedDomains": [kTestDomain1, kTestDomain2]])
  55. }
  56. let rpcResponse = try await AuthBackend.call(with: makeGetProjectConfigRequest())
  57. XCTAssertEqual(rpcResponse.projectID, kTestProjectID)
  58. XCTAssertEqual(rpcResponse.authorizedDomains?.first, kTestDomain1)
  59. XCTAssertEqual(rpcResponse.authorizedDomains?[1], kTestDomain2)
  60. }
  61. private func makeGetProjectConfigRequest() -> GetProjectConfigRequest {
  62. return GetProjectConfigRequest(requestConfiguration: makeRequestConfiguration())
  63. }
  64. }