FIRCreateAuthURIRequestTests.m 3.7 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/FIRCreateAuthURIRequest.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRCreateAuthURIResponse.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 kTestAuthUri
  31. @brief The test value of the "authURI" property in the json response.
  32. */
  33. static NSString *const kTestAuthUri = @"AuthURI";
  34. /** @var kTestIdentifier
  35. @brief Fake identifier key used for testing.
  36. */
  37. static NSString *const kTestIdentifier = @"Identifier";
  38. /** @var kContinueURITestKey
  39. @brief The key for the "continueUri" value in the request.
  40. */
  41. static NSString *const kContinueURITestKey = @"continueUri";
  42. /** @var kTestContinueURI
  43. @brief Fake Continue URI key used for testing.
  44. */
  45. static NSString *const kTestContinueURI = @"ContinueUri";
  46. /** @var kExpectedAPIURL
  47. @brief The expected URL for the test calls.
  48. */
  49. static NSString *const kExpectedAPIURL =
  50. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key=APIKey";
  51. /** @class FIRCreateAuthURIRequestTests
  52. @brief Tests for @c CreateAuthURIRequest.
  53. */
  54. @interface FIRCreateAuthURIRequestTests : XCTestCase
  55. @end
  56. @implementation FIRCreateAuthURIRequestTests {
  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 testCreateAuthUriRequest
  75. @brief Tests the encoding of an create auth URI request.
  76. */
  77. - (void)testEmailVerificationRequest {
  78. FIRAuthRequestConfiguration *requestConfiguration =
  79. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  80. FIRCreateAuthURIRequest *request =
  81. [[FIRCreateAuthURIRequest alloc] initWithIdentifier:kTestIdentifier
  82. continueURI:kTestContinueURI
  83. requestConfiguration:requestConfiguration];
  84. [FIRAuthBackend
  85. createAuthURI:request
  86. callback:^(FIRCreateAuthURIResponse *_Nullable response, NSError *_Nullable error){
  87. }];
  88. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  89. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  90. XCTAssert([_RPCIssuer.decodedRequest isKindOfClass:[NSDictionary class]]);
  91. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kContinueURITestKey], kTestContinueURI);
  92. }
  93. @end