FinalizeMFAEnrollmentRequestTests.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 FinalizeMFAEnrollmentRequestTests
  18. @brief Tests for @c FinalizeMFAEnrollmentRequest
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
  22. let kAPIKey = "APIKey"
  23. /**
  24. @fn testTOTPFinalizeMFAEnrollmentRequest
  25. @brief Tests the Finalize MFA Enrollment using TOTP request.
  26. */
  27. func testTOTPStartMFAEnrollmentRequest() async throws {
  28. let kIDToken = "idToken"
  29. let kDisplayName = "displayName"
  30. let kSessionInfo = "sessionInfo"
  31. let kVerificationCode = "code"
  32. let kTOTPVerificationInfo = "totpVerificationInfo"
  33. let kPhoneVerificationInfo = "phoneVerificationInfo"
  34. let requestConfiguration = AuthRequestConfiguration(apiKey: kAPIKey, appID: "appID")
  35. let requestInfo = AuthProtoFinalizeMFATOTPEnrollmentRequestInfo(sessionInfo: kSessionInfo,
  36. verificationCode: kVerificationCode)
  37. let request = FinalizeMFAEnrollmentRequest(idToken: kIDToken,
  38. displayName: kDisplayName,
  39. totpVerificationInfo: requestInfo,
  40. requestConfiguration: requestConfiguration)
  41. let expectedURL =
  42. "https://identitytoolkit.googleapis.com/v2/accounts/mfaEnrollment:finalize?key=" +
  43. "\(kAPIKey)"
  44. try await checkRequest(
  45. request: request,
  46. expected: expectedURL,
  47. key: kIDToken,
  48. value: kIDToken
  49. )
  50. let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
  51. XCTAssertEqual(requestDictionary[kDisplayName], kDisplayName)
  52. let totpInfo = try XCTUnwrap(requestDictionary[kTOTPVerificationInfo] as? [String: String])
  53. XCTAssertEqual(totpInfo["verificationCode"], kVerificationCode)
  54. XCTAssertNil(requestDictionary[kPhoneVerificationInfo])
  55. }
  56. }