FIRRevokeTokenResponseTests.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2023 Google LLC
  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/Public/FirebaseAuth/FIRAuthErrors.h"
  20. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  21. #import "FirebaseAuth/Sources/Backend/RPC/FIRRevokeTokenRequest.h"
  22. #import "FirebaseAuth/Sources/Backend/RPC/FIRRevokeTokenResponse.h"
  23. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  24. /** @var kFakeToken
  25. @brief The fake token to use in the test request.
  26. */
  27. static NSString *const kFakeToken = @"fakeToken";
  28. /** @var kFakeIDToken
  29. @brief The fake ID token to use in the test request.
  30. */
  31. static NSString *const kFakeIDToken = @"fakeIDToken";
  32. /** @var kFakeToken
  33. @brief The fake token to use in the test request.
  34. */
  35. static NSString *const kFakeTokenKey = @"tokenKey";
  36. /** @var kFakeIDToken
  37. @brief The fake ID token to use in the test request.
  38. */
  39. static NSString *const kFakeIDTokenKey = @"idTokenKey";
  40. /** @var kFakeAPIKey
  41. @brief The fake API key to use in the test request.
  42. */
  43. static NSString *const kFakeAPIKey = @"APIKey";
  44. /** @var kFakeFirebaseAppID
  45. @brief The fake Firebase app ID to use in the test request.
  46. */
  47. static NSString *const kFakeFirebaseAppID = @"appID";
  48. /** @var kExpectedAPIURL
  49. @brief The expected URL for the test calls.
  50. */
  51. static NSString *const kExpectedAPIURL =
  52. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/revokeToken?key=APIKey";
  53. @interface FIRRevokeTokenResponseTests : XCTestCase
  54. @end
  55. @implementation FIRRevokeTokenResponseTests {
  56. /** @var _RPCIssuer
  57. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  58. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  59. */
  60. FIRFakeBackendRPCIssuer *_RPCIssuer;
  61. /** @var _requestConfiguration
  62. @brief This is the request configuration used for testing.
  63. */
  64. FIRAuthRequestConfiguration *_requestConfiguration;
  65. }
  66. - (void)setUp {
  67. [super setUp];
  68. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  69. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  70. _RPCIssuer = RPCIssuer;
  71. _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kFakeAPIKey
  72. appID:kFakeFirebaseAppID];
  73. }
  74. /** @fn testSuccessfulRevokeTokenResponse
  75. @brief Tests a successful attempt of the token revocation flow.
  76. */
  77. - (void)testSuccessfulResponse {
  78. FIRRevokeTokenRequest *request =
  79. [[FIRRevokeTokenRequest alloc] initWithToken:kFakeToken
  80. idToken:kFakeIDToken
  81. requestConfiguration:_requestConfiguration];
  82. __block BOOL callbackInvoked;
  83. __block FIRRevokeTokenResponse *RPCResponse;
  84. __block NSError *RPCError;
  85. [FIRAuthBackend
  86. revokeToken:request
  87. callback:^(FIRRevokeTokenResponse *_Nullable response, NSError *_Nullable error) {
  88. RPCResponse = response;
  89. RPCError = error;
  90. callbackInvoked = YES;
  91. }];
  92. [_RPCIssuer respondWithJSON:@{}];
  93. XCTAssert(callbackInvoked);
  94. XCTAssertNotNil(RPCResponse);
  95. }
  96. @end
  97. #endif