SecureTokenRequestTests.swift 2.2 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. /** @class SecureTokenRequestTests
  18. @brief Tests for @c SecureTokenRequest
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class SecureTokenRequestTests: XCTestCase {
  22. let kAPIKey = "APIKey"
  23. let kEmulatorHostAndPort = "emulatorhost:12345"
  24. /** @fn testRequestURL
  25. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  26. request inputs.
  27. */
  28. func testRequestURL() {
  29. let requestConfiguration = AuthRequestConfiguration(apiKey: kAPIKey, appID: "appID")
  30. let request = SecureTokenRequest.refreshRequest(refreshToken: "Token",
  31. requestConfiguration: requestConfiguration)
  32. let expectedURL = "https://securetoken.googleapis.com/v1/token?key=\(kAPIKey)"
  33. XCTAssertEqual(expectedURL, request.requestURL().absoluteString)
  34. }
  35. /** @fn testRequestURLUseEmulator
  36. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  37. request inputs when using the emulator.
  38. */
  39. func testRequestURLUseEmulator() {
  40. let requestConfiguration = AuthRequestConfiguration(apiKey: kAPIKey, appID: "appID")
  41. let request = SecureTokenRequest.refreshRequest(refreshToken: "Token",
  42. requestConfiguration: requestConfiguration)
  43. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort
  44. let expectedURL =
  45. "http://\(kEmulatorHostAndPort)/securetoken.googleapis.com/v1/token?key=\(kAPIKey)"
  46. XCTAssertEqual(expectedURL, request.requestURL().absoluteString)
  47. }
  48. }