FIRResetPasswordRequestTests.m 3.4 KB

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