StartPasskeySignInRequestTests.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2025 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if os(iOS) || os(tvOS) || os(macOS)
  15. @testable import FirebaseAuth
  16. import FirebaseCore
  17. import Foundation
  18. import XCTest
  19. @available(iOS 15.0, macOS 12.0, tvOS 16.0, *)
  20. final class StartPasskeySignInRequestTests: XCTestCase {
  21. private var config: AuthRequestConfiguration!
  22. override func setUp() {
  23. super.setUp()
  24. config = AuthRequestConfiguration(
  25. apiKey: "FAKE_API_KEY",
  26. appID: "FAKE_APP_ID"
  27. )
  28. }
  29. override func tearDown() {
  30. config = nil
  31. super.tearDown()
  32. }
  33. func testInit_SetsEndpointAndConfig() {
  34. let request = StartPasskeySignInRequest(requestConfiguration: config)
  35. XCTAssertEqual(request.endpoint, "accounts/passkeySignIn:start")
  36. XCTAssertTrue(request.useIdentityPlatform)
  37. XCTAssertEqual(request.requestConfiguration().apiKey, "FAKE_API_KEY")
  38. XCTAssertEqual(request.requestConfiguration().appID, "FAKE_APP_ID")
  39. }
  40. func testUnencodedHTTPRequestBody_WithTenantId() {
  41. // setting up fake auth to set tenantId
  42. let options = FirebaseOptions(googleAppID: "0:0000000000000:ios:0000000000000000",
  43. gcmSenderID: "00000000000000000-00000000000-000000000")
  44. options.apiKey = AuthTests.kFakeAPIKey
  45. options.projectID = "myProjectID"
  46. let name = "test-AuthTests\(AuthTests.testNum)"
  47. AuthTests.testNum = AuthTests.testNum + 1
  48. let fakeAuth = Auth(app: FirebaseApp(instanceWithName: name, options: options))
  49. fakeAuth.tenantID = "TEST_TENANT"
  50. let configWithTenant = AuthRequestConfiguration(
  51. apiKey: "FAKE_API_KEY",
  52. appID: "FAKE_APP_ID",
  53. auth: fakeAuth
  54. )
  55. _ = AuthRequestConfiguration(apiKey: "apiKey", appID: "appId")
  56. let request = StartPasskeySignInRequest(
  57. requestConfiguration: configWithTenant
  58. )
  59. let body = request.unencodedHTTPRequestBody
  60. XCTAssertEqual(body!["tenantId"], "TEST_TENANT")
  61. }
  62. func testUnencodedHTTPRequestBody_WithoutTenantId() {
  63. let request = StartPasskeySignInRequest(requestConfiguration: config)
  64. XCTAssertEqual(request.unencodedHTTPRequestBody, [:])
  65. }
  66. }
  67. #endif