FIRGetAccountInfoRequestTests.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  18. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoRequest.h"
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetOOBConfirmationCodeResponse.h"
  21. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  22. /** @var kTestAPIKey
  23. @brief Fake API key used for testing.
  24. */
  25. static NSString *const kTestAPIKey = @"APIKey";
  26. /** @var kTestFirebaseAppID
  27. @brief Fake Firebase app ID used for testing.
  28. */
  29. static NSString *const kTestFirebaseAppID = @"appID";
  30. /** @var kIDTokenKey
  31. @brief The key for the "idToken" value in the request. This is actually the STS Access Token,
  32. despite it's confusing (backwards compatiable) parameter name.
  33. */
  34. static NSString *const kIDTokenKey = @"idToken";
  35. /** @var kTestAccessToken
  36. @brief testing token.
  37. */
  38. static NSString *const kTestAccessToken = @"testAccessToken";
  39. /** @var kExpectedAPIURL
  40. @brief The expected URL for test calls.
  41. */
  42. static NSString *const kExpectedAPIURL =
  43. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=APIKey";
  44. @interface FIRGetAccountInfoRequestTests : XCTestCase
  45. @end
  46. @implementation FIRGetAccountInfoRequestTests {
  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 testGetAccountInfoRequest
  65. @brief Tests the set account info request.
  66. */
  67. - (void)testGetAccountInfoRequest {
  68. FIRAuthRequestConfiguration *requestConfiguration =
  69. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  70. FIRGetAccountInfoRequest *request =
  71. [[FIRGetAccountInfoRequest alloc] initWithAccessToken:kTestAccessToken
  72. requestConfiguration:requestConfiguration];
  73. [FIRAuthBackend
  74. getAccountInfo:request
  75. callback:^(FIRGetAccountInfoResponse *_Nullable response, NSError *_Nullable error){
  76. }];
  77. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  78. XCTAssert([_RPCIssuer.decodedRequest isKindOfClass:[NSDictionary class]]);
  79. XCTAssertNotNil(_RPCIssuer.decodedRequest[kIDTokenKey]);
  80. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kIDTokenKey], kTestAccessToken);
  81. }
  82. @end