FIRVerifyClientRequestTest.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <TargetConditionals.h>
  17. #if TARGET_OS_IOS
  18. #import <XCTest/XCTest.h>
  19. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientRequest.h"
  21. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyClientResponse.h"
  22. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  23. /** @var kFakeAppToken
  24. @brief The fake app token to use in the test request.
  25. */
  26. static NSString *const kFakeAppToken = @"appToken";
  27. /** @var kFakeAPIKey
  28. @brief The fake API key to use in the test request.
  29. */
  30. static NSString *const kFakeAPIKey = @"APIKey";
  31. /** @var kFakeFirebaseAppID
  32. @brief The fake Firebase app ID to use in the test request.
  33. */
  34. static NSString *const kFakeFirebaseAppID = @"appID";
  35. /** @var kAppTokenKey
  36. @brief The key for the appToken request paramenter.
  37. */
  38. static NSString *const kAPPTokenKey = @"appToken";
  39. /** @var kIsSandboxKey
  40. @brief The key for the isSandbox request parameter
  41. */
  42. static NSString *const kIsSandboxKey = @"isSandbox";
  43. /** @var kExpectedAPIURL
  44. @brief The expected URL for the test calls.
  45. */
  46. static NSString *const kExpectedAPIURL =
  47. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyClient?key=APIKey";
  48. /** @class FIRVerifyClientRequestTest
  49. @brief Tests for @c FIRVerifyClientRequests.
  50. */
  51. @interface FIRVerifyClientRequestTest : XCTestCase
  52. @end
  53. @implementation FIRVerifyClientRequestTest {
  54. /** @var _RPCIssuer
  55. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  56. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  57. */
  58. FIRFakeBackendRPCIssuer *_RPCIssuer;
  59. }
  60. - (void)setUp {
  61. [super setUp];
  62. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  63. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  64. _RPCIssuer = RPCIssuer;
  65. }
  66. - (void)tearDown {
  67. _RPCIssuer = nil;
  68. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  69. [super tearDown];
  70. }
  71. /** @fn testVerifyClientRequest
  72. @brief Tests the verify client request.
  73. */
  74. - (void)testVerifyClientRequest {
  75. FIRAuthRequestConfiguration *requestConfiguration =
  76. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kFakeAPIKey appID:kFakeFirebaseAppID];
  77. FIRVerifyClientRequest *request =
  78. [[FIRVerifyClientRequest alloc] initWithAppToken:kFakeAppToken
  79. isSandbox:YES
  80. requestConfiguration:requestConfiguration];
  81. [FIRAuthBackend
  82. verifyClient:request
  83. callback:^(FIRVerifyClientResponse *_Nullable response, NSError *_Nullable error){
  84. }];
  85. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  86. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  87. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kAPPTokenKey], kFakeAppToken);
  88. XCTAssertTrue(_RPCIssuer.decodedRequest[kIsSandboxKey]);
  89. }
  90. @end
  91. #endif