FIRGetProjectConfigRequestTests.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2017 Google
  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. #if SWIFT_PACKAGE
  18. #import <FirebaseAuth-Swift.h>
  19. #else
  20. #import <FirebaseAuth/FirebaseAuth-Swift.h>
  21. #endif
  22. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  23. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  24. /** @var kGetProjectConfigEndPoint
  25. @brief The "getProjectConfig" endpoint.
  26. */
  27. static NSString *const kGetProjectConfigEndPoint = @"getProjectConfig";
  28. /** @var kTestAPIKey
  29. @brief Fake API key used for testing.
  30. */
  31. static NSString *const kTestAPIKey = @"APIKey";
  32. /** @var kTestFirebaseAppID
  33. @brief Fake Firebase app ID used for testing.
  34. */
  35. static NSString *const kTestFirebaseAppID = @"appID";
  36. /** @var kAPIURLFormat
  37. @brief URL format for server API calls.
  38. */
  39. static NSString *const kAPIURLFormat = @"https://%@/identitytoolkit/v3/relyingparty/%@?key=%@";
  40. /** @var gAPIHost
  41. @brief Host for server API calls.
  42. */
  43. static NSString *gAPIHost = @"www.googleapis.com";
  44. @interface FIRGetProjectConfigRequestTests : XCTestCase
  45. @end
  46. @implementation FIRGetProjectConfigRequestTests {
  47. /** @var _RPCIssuer
  48. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  49. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  50. */
  51. FIRFakeBackendRPCIssuer *_RPCIssuer;
  52. }
  53. - (void)setUp {
  54. [super setUp];
  55. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  56. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  57. _RPCIssuer = RPCIssuer;
  58. }
  59. - (void)tearDown {
  60. _RPCIssuer = nil;
  61. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  62. [super tearDown];
  63. }
  64. /** @fn testGetProjectConfigRequest
  65. @brief Tests get project config request.
  66. */
  67. - (void)testGetProjectConfigRequest {
  68. FIRAuthRequestConfiguration *requestConfiguration =
  69. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  70. FIRGetProjectConfigRequest *request =
  71. [[FIRGetProjectConfigRequest alloc] initWithRequestConfiguration:requestConfiguration];
  72. [FIRAuthBackend
  73. getProjectConfig:request
  74. callback:^(FIRGetProjectConfigResponse *_Nullable response, NSError *_Nullable error){
  75. }];
  76. XCTAssertFalse([request containsPostBody]);
  77. // Confirm that the quest has no decoded body as it is get request.
  78. XCTAssertNil(_RPCIssuer.decodedRequest);
  79. NSString *URLString =
  80. [NSString stringWithFormat:kAPIURLFormat, gAPIHost, kGetProjectConfigEndPoint, kTestAPIKey];
  81. XCTAssertEqualObjects(URLString, [request requestURL].absoluteString);
  82. }
  83. @end