FIRStartPasskeySignInRequestTests.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/FIRStartPasskeySignInRequest.h"
  20. #import "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeySignInResponse.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/passkeySignIn:start?key=APIKey";
  39. /**
  40. @class FIRStartPasskeySignInRequestTests
  41. @brief Tests for @c FIRStartPasskeySignInRequest.
  42. */
  43. @interface FIRStartPasskeySignInRequestTests : XCTestCase
  44. @end
  45. @implementation FIRStartPasskeySignInRequestTests {
  46. /**
  47. @brief This backend RPC issuer is used to fake network responses for each test in the suite.
  48. In the @c setUp method we initialize this and set @c FIRAuthBackend's RPC issuer to it.
  49. */
  50. FIRFakeBackendRPCIssuer *_RPCIssuer;
  51. /**
  52. @brief This is the request configuration used for testing.
  53. */
  54. FIRAuthRequestConfiguration *_requestConfiguration;
  55. }
  56. - (void)setUp {
  57. [super setUp];
  58. FIRFakeBackendRPCIssuer *RPCIssuer = [[FIRFakeBackendRPCIssuer alloc] init];
  59. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:RPCIssuer];
  60. _RPCIssuer = RPCIssuer;
  61. _requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:kTestAPIKey
  62. appID:kTestFirebaseAppID];
  63. }
  64. - (void)tearDown {
  65. _RPCIssuer = nil;
  66. _requestConfiguration = nil;
  67. [FIRAuthBackend setDefaultBackendImplementationWithRPCIssuer:nil];
  68. [super tearDown];
  69. }
  70. - (void)testStartPasskeySignInRequest {
  71. FIRStartPasskeySignInRequest *request =
  72. [[FIRStartPasskeySignInRequest alloc] initWithRequestConfiguration:_requestConfiguration];
  73. [FIRAuthBackend startPasskeySignIn:request
  74. callback:^(FIRStartPasskeySignInResponse *_Nullable response,
  75. NSError *_Nullable error){
  76. }];
  77. XCTAssertEqualObjects(_RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
  78. XCTAssertNotNil(_RPCIssuer.decodedRequest);
  79. }
  80. @end
  81. #endif