AppCheckInteropAPITests.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2024 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. // MARK: This file is used to evaluate the AppCheckInterop API in Swift.
  15. import Foundation
  16. // MARK: Do not import `FirebaseAppCheck`, this file is for `FirebaseAppCheckInterop` only.
  17. import FirebaseAppCheckInterop
  18. final class AppCheckInteropAPITests {
  19. let appCheckInterop: AppCheckInterop! = nil
  20. func usage() {
  21. let _: Void = appCheckInterop.getToken(forcingRefresh: false) { result in
  22. let _: FIRAppCheckTokenResultInterop = result
  23. let _: String = result.token
  24. if let error = result.error {
  25. let _: String = error.localizedDescription
  26. }
  27. }
  28. let _: String = appCheckInterop.tokenDidChangeNotificationName()
  29. let _: String = appCheckInterop.notificationTokenKey()
  30. let _: String = appCheckInterop.notificationAppNameKey()
  31. guard let getLimitedUseToken: (@escaping AppCheckTokenHandlerInterop) -> Void =
  32. appCheckInterop.getLimitedUseToken else { return }
  33. let _: Void = getLimitedUseToken { result in
  34. let _: FIRAppCheckTokenResultInterop = result
  35. let _: String = result.token
  36. if let error = result.error {
  37. let _: String = error.localizedDescription
  38. }
  39. }
  40. }
  41. @available(iOS 13, macOS 10.15, macCatalyst 13, tvOS 13, *)
  42. func usage_async() async {
  43. let result: FIRAppCheckTokenResultInterop =
  44. await appCheckInterop.getToken(forcingRefresh: false)
  45. let _: String = result.token
  46. if let error = result.error {
  47. let _: String = error.localizedDescription
  48. }
  49. // The following fails to compile with "Command SwiftCompile failed with a nonzero exit code".
  50. // let _ = await appCheckInterop.getLimitedUseToken?()
  51. }
  52. }