FIRStartPasskeyEnrollmentRequestTests.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2023 Google LLC
  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 <TargetConditionals.h>
  17. #if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
  18. #import <XCTest/XCTest.h>
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentRequest.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentResponse.h"
  21. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthErrors.h"
  22. #import "FirebaseAuth/Tests/Unit/FIRFakeBackendRPCIssuer.h"
  23. /**
  24. @var kTestAPIKey
  25. @brief Fake API key used for testing.
  26. */
  27. static NSString *const kTestAPIKey = @"APIKey";
  28. /**
  29. @var kTestFirebaseAppID
  30. @brief Fake Firebase app ID used for testing.
  31. */
  32. static NSString *const kTestFirebaseAppID = @"appID";
  33. /**
  34. @var kExpectedAPIURL
  35. @brief The expected URL for the test calls.
  36. */
  37. static NSString *const kExpectedAPIURL =
  38. @"https://identitytoolkit.googleapis.com/v2/accounts/passkeyEnrollment:start?key=APIKey";
  39. /**
  40. @var kIDToken
  41. @brief Token representing the user's identity.
  42. */
  43. static NSString *const kIDToken = @"idToken";
  44. /**
  45. @class FIRStartPasskeyEnrollmentRequestTests
  46. @brief Tests for @c FIRStartPasskeyEnrollmentRequest.
  47. */
  48. @interface FIRStartPasskeyEnrollmentRequestTests : XCTestCase
  49. @end
  50. @implementation FIRStartPasskeyEnrollmentRequestTests {
  51. /**
  52. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  53. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  54. */
  55. FIRFakeBackendRPCIssuer *_RPCIssuer;
  56. /**
  57. @brief This is the request configuration used for testing.
  58. */
  59. FIRAuthRequestConfiguration *_requestConfiguration;
  60. }
  61. - (void)setUp {
  62. [super setUp];
  63. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  64. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  65. _RPCIssuer = RPCIssuer;
  66. _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey
  67. appID:kTestFirebaseAppID];
  68. }
  69. - (void)tearDown {
  70. _RPCIssuer = nil;
  71. _requestConfiguration = nil;
  72. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  73. [super tearDown];
  74. }
  75. - (void)testStartPasskeyEnrollmentRequest {
  76. FIRStartPasskeyEnrollmentRequest *request =
  77. [[FIRStartPasskeyEnrollmentRequest alloc] initWithIDToken:kIDToken
  78. requestConfiguration:_requestConfiguration];
  79. [FIRAuthBackend startPasskeyEnrollment:request
  80. callback:^(FIRStartPasskeyEnrollmentResponse *_Nullable response,
  81. NSError *_Nullable error){
  82. }];
  83. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  84. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  85. XCTAssertEqualObjects(_RPCIssuer.decodedRequest[kIDToken], kIDToken);
  86. }
  87. @end
  88. #endif