AppCheckInteropFake.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 getLimitedUseToken() async -> any FIRAppCheckTokenResultInterop {
  36. return AppCheckTokenResultInteropFake(token: "limited_use_\(token)", error: error)
  37. }
  38. func tokenDidChangeNotificationName() -> String {
  39. fatalError("\(#function) not implemented.")
  40. }
  41. func notificationTokenKey() -> String {
  42. fatalError("\(#function) not implemented.")
  43. }
  44. func notificationAppNameKey() -> String {
  45. fatalError("\(#function) not implemented.")
  46. }
  47. private class AppCheckTokenResultInteropFake: NSObject, FIRAppCheckTokenResultInterop,
  48. @unchecked Sendable {
  49. let token: String
  50. let error: Error?
  51. init(token: String, error: Error?) {
  52. self.token = token
  53. self.error = error
  54. }
  55. }
  56. }
  57. struct AppCheckErrorFake: Error {}