FIRSecureTokenRequestTests.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/Sources/Backend/RPC/FIRSecureTokenRequest.h"
  18. #import "FirebaseAuth/Sources/Backend/FIRAuthRequestConfiguration.h"
  19. /** @var kAPIKey
  20. @brief A testing API Key.
  21. */
  22. static NSString *const kAPIKey = @"APIKey";
  23. /** @var kFirebaseAppID
  24. @brief A testing Firebase app ID.
  25. */
  26. static NSString *const kFirebaseAppID = @"appID";
  27. /** @var kRefreshToken
  28. @brief A testing refresh token.
  29. */
  30. static NSString *const kRefreshToken = @"refreshToken";
  31. /** @var kEmulatorHostAndPort
  32. @brief A testing emulator host and port.
  33. */
  34. static NSString *const kEmulatorHostAndPort = @"emulatorhost:12345";
  35. /** @class FIRSecureTokenRequestTests
  36. @brief Tests for @c FIRSecureTokenRequest
  37. */
  38. @interface FIRSecureTokenRequestTests : XCTestCase
  39. @end
  40. @implementation FIRSecureTokenRequestTests
  41. /** @fn testRequestURL
  42. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  43. request inputs.
  44. */
  45. - (void)testRequestURL {
  46. FIRAuthRequestConfiguration *requestConfiguration =
  47. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
  48. FIRSecureTokenRequest *request =
  49. [FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
  50. requestConfiguration:requestConfiguration];
  51. NSString *expectedURL =
  52. [NSString stringWithFormat:@"https://securetoken.googleapis.com/v1/token?key=%@", kAPIKey];
  53. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  54. }
  55. /** @fn testRequestURLUseEmulator
  56. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  57. request inputs when using the emulator.
  58. */
  59. - (void)testRequestURLUseEmulator {
  60. FIRAuthRequestConfiguration *requestConfiguration =
  61. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
  62. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort;
  63. FIRSecureTokenRequest *request =
  64. [FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
  65. requestConfiguration:requestConfiguration];
  66. NSString *expectedURL =
  67. [NSString stringWithFormat:@"http://%@/securetoken.googleapis.com/v1/token?key=%@",
  68. kEmulatorHostAndPort, kAPIKey];
  69. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  70. }
  71. @end