FIRSecureTokenRequestTests.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. @import FirebaseAuth;
  18. /** @var kAPIKey
  19. @brief A testing API Key.
  20. */
  21. static NSString *const kAPIKey = @"APIKey";
  22. /** @var kFirebaseAppID
  23. @brief A testing Firebase app ID.
  24. */
  25. static NSString *const kFirebaseAppID = @"appID";
  26. /** @var kRefreshToken
  27. @brief A testing refresh token.
  28. */
  29. static NSString *const kRefreshToken = @"refreshToken";
  30. /** @var kEmulatorHostAndPort
  31. @brief A testing emulator host and port.
  32. */
  33. static NSString *const kEmulatorHostAndPort = @"emulatorhost:12345";
  34. /** @class FIRSecureTokenRequestTests
  35. @brief Tests for @c FIRSecureTokenRequest
  36. */
  37. @interface FIRSecureTokenRequestTests : XCTestCase
  38. @end
  39. @implementation FIRSecureTokenRequestTests
  40. /** @fn testRequestURL
  41. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  42. request inputs.
  43. */
  44. - (void)testRequestURL {
  45. FIRAuthRequestConfiguration *requestConfiguration =
  46. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
  47. FIRSecureTokenRequest *request =
  48. [FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
  49. requestConfiguration:requestConfiguration];
  50. NSString *expectedURL =
  51. [NSString stringWithFormat:@"https://securetoken.googleapis.com/v1/token?key=%@", kAPIKey];
  52. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  53. }
  54. /** @fn testRequestURLUseEmulator
  55. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  56. request inputs when using the emulator.
  57. */
  58. - (void)testRequestURLUseEmulator {
  59. FIRAuthRequestConfiguration *requestConfiguration =
  60. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
  61. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort;
  62. FIRSecureTokenRequest *request =
  63. [FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
  64. requestConfiguration:requestConfiguration];
  65. NSString *expectedURL =
  66. [NSString stringWithFormat:@"http://%@/securetoken.googleapis.com/v1/token?key=%@",
  67. kEmulatorHostAndPort, kAPIKey];
  68. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  69. }
  70. @end