StartMFAEnrollmentRequestTests.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2023 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. import Foundation
  15. import XCTest
  16. @testable import FirebaseAuth
  17. /** @class StartMFAEnrollmentRequestTests
  18. @brief Tests for @c StartMFAEnrollmentRequest
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class StartMFAEnrollmentRequestTests: RPCBaseTests {
  22. let kAPIKey = "APIKey"
  23. /**
  24. @fn testTOTPStartMFAEnrollmentRequest
  25. @brief Tests the Start MFA Enrollment using TOTP request.
  26. */
  27. func testTOTPStartMFAEnrollmentRequest() async throws {
  28. let kIDToken = "idToken"
  29. let kTOTPEnrollmentInfo = "totpEnrollmentInfo"
  30. let kPhoneEnrollmentInfo = "enrollmentInfo"
  31. let requestConfiguration = AuthRequestConfiguration(apiKey: kAPIKey, appID: "appID")
  32. let requestInfo = AuthProtoStartMFATOTPEnrollmentRequestInfo()
  33. let request = StartMFAEnrollmentRequest(idToken: kIDToken,
  34. totpEnrollmentInfo: requestInfo,
  35. requestConfiguration: requestConfiguration)
  36. let expectedURL =
  37. "https://identitytoolkit.googleapis.com/v2/accounts/mfaEnrollment:start?key=\(kAPIKey)"
  38. do {
  39. try await checkRequest(
  40. request: request,
  41. expected: expectedURL,
  42. key: kIDToken,
  43. value: kIDToken
  44. )
  45. } catch {
  46. // Ignore error from missing users array in fake JSON return.
  47. return
  48. }
  49. let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
  50. let totpInfo = try XCTUnwrap(requestDictionary[kTOTPEnrollmentInfo] as? [String: String])
  51. XCTAssertEqual(totpInfo, [:])
  52. XCTAssertNil(requestDictionary[kPhoneEnrollmentInfo])
  53. }
  54. }