FIRResetPasswordRequestTests.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/Public/FirebaseAuth/FIRAuthErrors.h"
  18. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRResetPasswordRequest.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRResetPasswordResponse.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 kTestOOBCode
  31. @brief Fake OOBCode used for testing.
  32. */
  33. static NSString *const kTestOOBCode = @"OOBCode";
  34. /** @var kTestNewPassword
  35. @brief Fake new password used for testing.
  36. */
  37. static NSString *const kTestNewPassword = @"newPassword:-)";
  38. /** @var kOOBCodeKey
  39. @brief The "resetPassword" key.
  40. */
  41. static NSString *const kOOBCodeKey = @"oobCode";
  42. /** @var knewPasswordKey
  43. @brief The "newPassword" key.
  44. */
  45. static NSString *const knewPasswordKey = @"newPassword";
  46. /** @var kExpectedAPIURL
  47. @brief The expected URL for test calls.
  48. */
  49. static NSString *const kExpectedAPIURL =
  50. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/resetPassword?key=APIKey";
  51. /** @class FIRResetPasswordRequestTests
  52. @brief Tests for @c FIRResetPasswordRequest.
  53. */
  54. @interface FIRResetPasswordRequestTest : XCTestCase
  55. @end
  56. @implementation FIRResetPasswordRequestTest {
  57. /** @var _RPCIssuer
  58. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  59. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  60. */
  61. FIRFakeBackendRPCIssuer *_RPCIssuer;
  62. }
  63. - (void)setUp {
  64. [super setUp];
  65. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  66. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  67. _RPCIssuer = RPCIssuer;
  68. }
  69. - (void)tearDown {
  70. _RPCIssuer = nil;
  71. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  72. [super tearDown];
  73. }
  74. /** @fn testResetPasswordRequest
  75. @brief Tests the reset password reqeust.
  76. */
  77. - (void)testResetPasswordRequest {
  78. FIRAuthRequestConfiguration *requestConfiguration =
  79. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  80. FIRResetPasswordRequest *request =
  81. [[FIRResetPasswordRequest alloc] initWithOobCode:kTestOOBCode
  82. newPassword:kTestNewPassword
  83. requestConfiguration:requestConfiguration];
  84. [FIRAuthBackend
  85. resetPassword:request
  86. callback:^(FIRResetPasswordResponse *_Nullable response, NSError *_Nullable error){
  87. }];
  88. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  89. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  90. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[knewPasswordKey], kTestNewPassword);
  91. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kOOBCodeKey], kTestOOBCode);
  92. }
  93. @end