FIRGetAccountInfoRequestTests.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "FIRAuthBackend.h"
  18. #import "FIRFakeBackendRPCIssuer.h"
  19. #import "FIRGetAccountInfoRequest.h"
  20. #import "FIRGetAccountInfoResponse.h"
  21. #import "FIRGetOOBConfirmationCodeResponse.h"
  22. /** @var kTestAPIKey
  23. @brief Fake API key used for testing.
  24. */
  25. static NSString *const kTestAPIKey = @"APIKey";
  26. /** @var kIDTokenKey
  27. @brief The key for the "idToken" value in the request. This is actually the STS Access Token,
  28. despite it's confusing (backwards compatiable) parameter name.
  29. */
  30. static NSString *const kIDTokenKey = @"idToken";
  31. /** @var kTestAccessToken
  32. @brief testing token.
  33. */
  34. static NSString *const kTestAccessToken = @"testAccessToken";
  35. /** @var kExpectedAPIURL
  36. @brief The expected URL for test calls.
  37. */
  38. static NSString *const kExpectedAPIURL =
  39. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=APIKey";
  40. @interface FIRGetAccountInfoRequestTests : XCTestCase
  41. @end
  42. @implementation FIRGetAccountInfoRequestTests {
  43. /** @var _RPCIssuer
  44. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  45. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  46. */
  47. FIRFakeBackendRPCIssuer *_RPCIssuer;
  48. }
  49. - (void)setUp {
  50. [super setUp];
  51. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  52. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  53. _RPCIssuer = RPCIssuer;
  54. }
  55. - (void)tearDown {
  56. _RPCIssuer = nil;
  57. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  58. [super tearDown];
  59. }
  60. /** @fn testGetAccountInfoRequest
  61. @brief Tests the set account info request.
  62. */
  63. - (void)testGetAccountInfoRequest {
  64. FIRAuthRequestConfiguration *requestConfiguration =
  65. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey];
  66. FIRGetAccountInfoRequest *request =
  67. [[FIRGetAccountInfoRequest alloc] initWithAccessToken:kTestAccessToken
  68. requestConfiguration:requestConfiguration];
  69. [FIRAuthBackend
  70. getAccountInfo:request
  71. callback:^(FIRGetAccountInfoResponse *_Nullable response, NSError *_Nullable error){
  72. }];
  73. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  74. XCTAssert([_RPCIssuer.decodedRequest isKindOfClass:[NSDictionary class]]);
  75. XCTAssertNotNil(_RPCIssuer.decodedRequest[kIDTokenKey]);
  76. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kIDTokenKey], kTestAccessToken);
  77. }
  78. @end