FIRIdentityToolkitRequestTests.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/FIRIdentityToolkitRequest.h"
  18. /** @var kEndpoint
  19. @brief The endpoint for the requests.
  20. */
  21. static NSString *const kEndpoint = @"endpoint";
  22. /** @var kAPIKey
  23. @brief A testing API Key.
  24. */
  25. static NSString *const kAPIKey = @"APIKey";
  26. /** @var kEmulatorHostAndPort
  27. @brief A testing emulator host and port.
  28. */
  29. static NSString *const kEmulatorHostAndPort = @"emulatorhost:12345";
  30. /** @class FIRIdentityToolkitRequestTests
  31. @brief Tests for @c FIRIdentityToolkitRequest
  32. */
  33. @interface FIRIdentityToolkitRequestTests : XCTestCase
  34. @end
  35. @implementation FIRIdentityToolkitRequestTests
  36. /** @fn testInitWithEndpointExpectedRequestURL
  37. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  38. request inputs.
  39. */
  40. - (void)testInitWithEndpointExpectedRequestURL {
  41. FIRAuthRequestConfiguration *requestConfiguration =
  42. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  43. FIRIdentityToolkitRequest *request =
  44. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  45. requestConfiguration:requestConfiguration];
  46. NSString *expectedURL = [NSString
  47. stringWithFormat:@"https://www.googleapis.com/identitytoolkit/v3/relyingparty/%@?key=%@",
  48. kEndpoint, kAPIKey];
  49. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  50. }
  51. /** @fn testInitWithEndpointUseStagingExpectedRequestURL
  52. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  53. request inputs when the staging endpoint is specified.
  54. */
  55. - (void)testInitWithEndpointUseStagingExpectedRequestURL {
  56. FIRAuthRequestConfiguration *requestConfiguration =
  57. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  58. FIRIdentityToolkitRequest *request =
  59. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  60. requestConfiguration:requestConfiguration
  61. useIdentityPlatform:NO
  62. useStaging:YES];
  63. NSString *expectedURL = [NSString
  64. stringWithFormat:
  65. @"https://staging-www.sandbox.googleapis.com/identitytoolkit/v3/relyingparty/%@?key=%@",
  66. kEndpoint, kAPIKey];
  67. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  68. }
  69. /** @fn testInitWithEndpointUseIdentityPlatformExpectedRequestURL
  70. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  71. request inputs when the Identity Platform endpoint is specified.
  72. */
  73. - (void)testInitWithEndpointUseIdentityPlatformExpectedRequestURL {
  74. FIRAuthRequestConfiguration *requestConfiguration =
  75. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  76. FIRIdentityToolkitRequest *request =
  77. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  78. requestConfiguration:requestConfiguration
  79. useIdentityPlatform:YES
  80. useStaging:NO];
  81. NSString *expectedURL = [NSString
  82. stringWithFormat:@"https://identitytoolkit.googleapis.com/v2/%@?key=%@", kEndpoint, kAPIKey];
  83. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  84. }
  85. /** @fn testInitWithEndpointUseIdentityPlatformUseStagingExpectedRequestURL
  86. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  87. request inputs when the Identity Platform and staging endpoint is specified.
  88. */
  89. - (void)testInitWithEndpointUseIdentityPlatformUseStagingExpectedRequestURL {
  90. FIRAuthRequestConfiguration *requestConfiguration =
  91. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  92. FIRIdentityToolkitRequest *request =
  93. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  94. requestConfiguration:requestConfiguration
  95. useIdentityPlatform:YES
  96. useStaging:YES];
  97. NSString *expectedURL = [NSString
  98. stringWithFormat:@"https://staging-identitytoolkit.sandbox.googleapis.com/v2/%@?key=%@",
  99. kEndpoint, kAPIKey];
  100. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  101. }
  102. /** @fn testInitWithEndpointUseEmulatorExpectedRequestURL
  103. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  104. request inputs when the emulator is used.
  105. */
  106. - (void)testInitWithEndpointUseEmulatorExpectedRequestURL {
  107. FIRAuthRequestConfiguration *requestConfiguration =
  108. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  109. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort;
  110. FIRIdentityToolkitRequest *request =
  111. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  112. requestConfiguration:requestConfiguration];
  113. NSString *expectedURL = [NSString
  114. stringWithFormat:@"http://%@/www.googleapis.com/identitytoolkit/v3/relyingparty/%@?key=%@",
  115. kEmulatorHostAndPort, kEndpoint, kAPIKey];
  116. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  117. }
  118. /** @fn testInitWithEndpointUseIdentityPlatformUseEmulatorExpectedRequestURL
  119. @brief Tests the @c requestURL method to make sure the URL it produces corresponds to the
  120. request inputs when the emulator is used with the Identity Platform endpoint.
  121. */
  122. - (void)testInitWithEndpointUseIdentityPlatformUseEmulatorExpectedRequestURL {
  123. FIRAuthRequestConfiguration *requestConfiguration =
  124. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey];
  125. requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort;
  126. FIRIdentityToolkitRequest *request =
  127. [[FIRIdentityToolkitRequest alloc] initWithEndpoint:kEndpoint
  128. requestConfiguration:requestConfiguration
  129. useIdentityPlatform:YES
  130. useStaging:NO];
  131. NSString *expectedURL =
  132. [NSString stringWithFormat:@"http://%@/identitytoolkit.googleapis.com/v2/%@?key=%@",
  133. kEmulatorHostAndPort, kEndpoint, kAPIKey];
  134. XCTAssertEqualObjects(expectedURL, request.requestURL.absoluteString);
  135. }
  136. @end