GitHubAuthProviderTests.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 FIRGitHubAuthProviderTests
  18. @brief Tests for @c FIRGitHubAuthProvider
  19. */
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. class GitHubAuthProviderTests: 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 kGitHubToken = "Token"
  28. let requestConfiguration = AuthRequestConfiguration(apiKey: "APIKey", appID: "appID")
  29. let credential = GitHubAuthProvider.credential(withToken: kGitHubToken)
  30. let request = VerifyAssertionRequest(providerID: GitHubAuthProvider.id,
  31. requestConfiguration: requestConfiguration)
  32. credential.prepare(request)
  33. XCTAssertEqual(kGitHubToken, request.providerAccessToken)
  34. }
  35. /** @fn testGitHubAuthCredentialCoding
  36. @brief Tests successful archiving and unarchiving of @c GitHubAuthCredential.
  37. */
  38. func testGitHubAuthCredentialCoding() throws {
  39. let kGitHubToken = "Token"
  40. let credential = GitHubAuthProvider.credential(withToken: kGitHubToken)
  41. XCTAssertTrue(GitHubAuthCredential.supportsSecureCoding)
  42. let data = try NSKeyedArchiver.archivedData(
  43. withRootObject: credential,
  44. requiringSecureCoding: true
  45. )
  46. let unarchivedCredential = try XCTUnwrap(NSKeyedUnarchiver.unarchivedObject(
  47. ofClass: GitHubAuthCredential.self, from: data
  48. ))
  49. XCTAssertEqual(unarchivedCredential.token, kGitHubToken)
  50. }
  51. }