FIRVerifyClientRequestTest.m 3.3 KB

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