SecureTokenTests.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 SecureTokenTests: RPCBaseTests {
  19. private let kEmulatorHostAndPort = "emulatorhost:12345"
  20. /** @fn testRequestURL
  21. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  22. request inputs.
  23. */
  24. func testRequestURL() throws {
  25. let kExpectedAPIURL = "https://securetoken.googleapis.com/v1/token?key=\(kTestAPIKey)"
  26. let request = makeSecureTokenRequest()
  27. XCTAssertEqual(request.requestURL().absoluteString, kExpectedAPIURL)
  28. }
  29. /** @fn testRequestURLUseEmulator
  30. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  31. request inputs when using the emulator.
  32. */
  33. func testRequestURLUseEmulator() throws {
  34. let kExpectedAPIURL =
  35. "http://\(kEmulatorHostAndPort)/securetoken.googleapis.com/v1/token?key=\(kTestAPIKey)"
  36. let request = makeSecureTokenRequest(useEmulator: true)
  37. XCTAssertEqual(request.requestURL().absoluteString, kExpectedAPIURL)
  38. }
  39. private func makeSecureTokenRequest(useEmulator: Bool = false) -> SecureTokenRequest {
  40. let requestConfiguration = makeRequestConfiguration()
  41. if useEmulator {
  42. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort
  43. }
  44. return SecureTokenRequest.refreshRequest(refreshToken: kRefreshToken,
  45. requestConfiguration: requestConfiguration)
  46. }
  47. }