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