FacebookAuthProviderTests.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 FIRFacebookAuthProviderTests
  18. @brief Tests for @c FIRFacebookAuthProvider
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class FacebookAuthProviderTests: XCTestCase {
  22. /** @fn testCredentialWithToken
  23. @brief Tests the @c credentialWithToken method to make sure the credential it produces populates
  24. the appropriate fields in a verify assertion request.
  25. */
  26. func testCredentialWithToken() {
  27. let kFacebookToken = "Token"
  28. let requestConfiguration = AuthRequestConfiguration(apiKey: "APIKey", appID: "appID")
  29. let credential = FacebookAuthProvider.credential(withAccessToken: kFacebookToken)
  30. let request = VerifyAssertionRequest(providerID: FacebookAuthProvider.id,
  31. requestConfiguration: requestConfiguration)
  32. credential.prepare(request)
  33. XCTAssertEqual(kFacebookToken, request.providerAccessToken)
  34. }
  35. /** @fn testFacebookAuthCredentialCoding
  36. @brief Tests successful archiving and unarchiving of @c FacebookAuthCredential.
  37. */
  38. func testFacebookAuthCredentialCoding() throws {
  39. let kFacebookToken = "Token"
  40. let credential = FacebookAuthProvider.credential(withAccessToken: kFacebookToken)
  41. XCTAssertTrue(FacebookAuthCredential.supportsSecureCoding)
  42. let data = try NSKeyedArchiver.archivedData(
  43. withRootObject: credential,
  44. requiringSecureCoding: true
  45. )
  46. let unarchivedCredential = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(
  47. ofClass: FacebookAuthCredential.self, from: data
  48. ))
  49. XCTAssertEqual(unarchivedCredential.accessToken, kFacebookToken)
  50. }
  51. }