FinalizeMFASignInRequestTests.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 FinalizeMFASignInRequestTests
  18. @brief Tests for @c FinalizeMFASignInRequest
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class FinalizeMFASignInRequestTests: RPCBaseTests {
  22. let kAPIKey = "APIKey"
  23. /**
  24. @fn testTOTPFinalizeMFASignInRequest
  25. @brief Tests the Start MFA Enrollment using TOTP request.
  26. */
  27. func testTOTPFinalizeMFASignInRequest() async throws {
  28. let kMfaPendingCredential = "mfaPendingCredential"
  29. let kMfaEnrollmentID = "mfaEnrollmentId"
  30. let kVerificationCode = "verificationCode"
  31. let kTOTPVerificationInfo = "totpVerificationInfo"
  32. let kPhoneVerificationInfo = "phoneVerificationInfo"
  33. let requestConfiguration = AuthRequestConfiguration(apiKey: kAPIKey, appID: "appID")
  34. let requestInfo = AuthProtoFinalizeMFATOTPSignInRequestInfo(mfaEnrollmentID: kMfaEnrollmentID,
  35. verificationCode: kVerificationCode)
  36. let request = FinalizeMFASignInRequest(mfaPendingCredential: kMfaPendingCredential,
  37. verificationInfo: requestInfo,
  38. requestConfiguration: requestConfiguration)
  39. let expectedURL =
  40. "https://identitytoolkit.googleapis.com/v2/accounts/mfaSignIn:finalize?key=\(kAPIKey)"
  41. try await checkRequest(
  42. request: request,
  43. expected: expectedURL,
  44. key: kMfaPendingCredential,
  45. value: kMfaPendingCredential
  46. )
  47. let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
  48. XCTAssertEqual(requestDictionary[kMfaEnrollmentID], kMfaEnrollmentID)
  49. let totpInfo = try XCTUnwrap(requestDictionary[kTOTPVerificationInfo] as? [String: String])
  50. XCTAssertEqual(totpInfo["verificationCode"], kVerificationCode)
  51. XCTAssertNil(requestDictionary[kPhoneVerificationInfo])
  52. }
  53. }