FIRCreateAuthURIRequestTests.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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;
  18. #import "FirebaseAuth/Sources/Backend/FIRAuthBackend.h"
  19. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  20. /** @var kTestAPIKey
  21. @brief Fake API key used for testing.
  22. */
  23. static NSString *const kTestAPIKey = @"APIKey";
  24. /** @var kTestFirebaseAppID
  25. @brief Fake Firebase app ID used for testing.
  26. */
  27. static NSString *const kTestFirebaseAppID = @"appID";
  28. /** @var kTestAuthUri
  29. @brief The test value of the "authURI" property in the json response.
  30. */
  31. static NSString *const kTestAuthUri = @"AuthURI";
  32. /** @var kTestIdentifier
  33. @brief Fake identifier key used for testing.
  34. */
  35. static NSString *const kTestIdentifier = @"Identifier";
  36. /** @var kContinueURITestKey
  37. @brief The key for the "continueUri" value in the request.
  38. */
  39. static NSString *const kContinueURITestKey = @"continueUri";
  40. /** @var kTestContinueURI
  41. @brief Fake Continue URI key used for testing.
  42. */
  43. static NSString *const kTestContinueURI = @"ContinueUri";
  44. /** @var kExpectedAPIURL
  45. @brief The expected URL for the test calls.
  46. */
  47. static NSString *const kExpectedAPIURL =
  48. @"https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key=APIKey";
  49. /** @class FIRCreateAuthURIRequestTests
  50. @brief Tests for @c CreateAuthURIRequest.
  51. */
  52. @interface FIRCreateAuthURIRequestTests : XCTestCase
  53. @end
  54. @implementation FIRCreateAuthURIRequestTests {
  55. /** @var _RPCIssuer
  56. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  57. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  58. */
  59. FIRFakeBackendRPCIssuer *_RPCIssuer;
  60. }
  61. - (void)setUp {
  62. [super setUp];
  63. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  64. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  65. _RPCIssuer = RPCIssuer;
  66. }
  67. - (void)tearDown {
  68. _RPCIssuer = nil;
  69. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  70. [super tearDown];
  71. }
  72. /** @fn testCreateAuthUriRequest
  73. @brief Tests the encoding of an create auth URI request.
  74. */
  75. - (void)testEmailVerificationRequest {
  76. FIRAuthRequestConfiguration *requestConfiguration =
  77. [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey appID:kTestFirebaseAppID];
  78. FIRCreateAuthURIRequest *request =
  79. [[FIRCreateAuthURIRequest alloc] initWithIdentifier:kTestIdentifier
  80. continueURI:kTestContinueURI
  81. requestConfiguration:requestConfiguration];
  82. [FIRAuthBackend
  83. createAuthURI:request
  84. callback:^(FIRCreateAuthURIResponse *_Nullable response, NSError *_Nullable error){
  85. }];
  86. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  87. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  88. XCTAssert([_RPCIssuer.decodedRequest isKindOfClass:[NSDictionary class]]);
  89. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kContinueURITestKey], kTestContinueURI);
  90. }
  91. @end