AppCheckInteropFake.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2025 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 FirebaseAppCheckInterop
  15. import Foundation
  16. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
  17. class AppCheckInteropFake: NSObject, AppCheckInterop {
  18. /// The placeholder token value returned when an error occurs
  19. static let placeholderTokenValue = "placeholder-token"
  20. var token: String
  21. var error: Error?
  22. private init(token: String, error: Error?) {
  23. self.token = token
  24. self.error = error
  25. }
  26. convenience init(token: String) {
  27. self.init(token: token, error: nil)
  28. }
  29. convenience init(error: Error) {
  30. self.init(token: AppCheckInteropFake.placeholderTokenValue, error: error)
  31. }
  32. func getToken(forcingRefresh: Bool) async -> any FIRAppCheckTokenResultInterop {
  33. return AppCheckTokenResultInteropFake(token: token, error: error)
  34. }
  35. func tokenDidChangeNotificationName() -> String {
  36. fatalError("\(#function) not implemented.")
  37. }
  38. func notificationTokenKey() -> String {
  39. fatalError("\(#function) not implemented.")
  40. }
  41. func notificationAppNameKey() -> String {
  42. fatalError("\(#function) not implemented.")
  43. }
  44. private class AppCheckTokenResultInteropFake: NSObject, FIRAppCheckTokenResultInterop {
  45. var token: String
  46. var error: Error?
  47. init(token: String, error: Error?) {
  48. self.token = token
  49. self.error = error
  50. }
  51. }
  52. }
  53. struct AppCheckErrorFake: Error {}