EmailAuthProviderTests.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 FIREmailAuthProviderTests
  18. @brief Tests for @c FIREmailAuthProvider
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class EmailAuthProviderTests: XCTestCase {
  22. /** @fn testEmailAuthCredentialCodingLink
  23. @brief Tests successful archiving and unarchiving of @c EmailAuthCredential.
  24. */
  25. func testEmailAuthCredentialCodingLink() throws {
  26. let kEmail = "Token"
  27. let kLink = "Secret"
  28. let credential = EmailAuthProvider.credential(withEmail: kEmail, link: kLink)
  29. XCTAssertTrue(EmailAuthCredential.supportsSecureCoding)
  30. let data = try NSKeyedArchiver.archivedData(
  31. withRootObject: credential,
  32. requiringSecureCoding: true
  33. )
  34. let unarchivedCredential = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(
  35. ofClass: EmailAuthCredential.self, from: data
  36. ))
  37. XCTAssertEqual(unarchivedCredential.email, kEmail)
  38. switch unarchivedCredential.emailType {
  39. case .password: XCTFail("Should be a link")
  40. case let .link(link): XCTAssertEqual(link, kLink)
  41. }
  42. }
  43. /** @fn testEmailAuthCredentialCodingPassword
  44. @brief Tests successful archiving and unarchiving of @c EmailAuthCredential.
  45. */
  46. func testEmailAuthCredentialCodingPassword() throws {
  47. let kEmail = "Token"
  48. let kPassword = "password123"
  49. let credential = EmailAuthProvider.credential(withEmail: kEmail, password: kPassword)
  50. XCTAssertTrue(EmailAuthCredential.supportsSecureCoding)
  51. let data = try NSKeyedArchiver.archivedData(
  52. withRootObject: credential,
  53. requiringSecureCoding: true
  54. )
  55. let unarchivedCredential = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(
  56. ofClass: EmailAuthCredential.self, from: data
  57. ))
  58. XCTAssertEqual(unarchivedCredential.email, kEmail)
  59. switch unarchivedCredential.emailType {
  60. case let .password(password): XCTAssertEqual(password, kPassword)
  61. case .link: XCTFail("Should be a password")
  62. }
  63. }
  64. }