FIRDeviceCheckAPIServiceE2ETests.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <TargetConditionals.h>
  17. // Tests that use the Keychain require a host app and Swift Package Manager
  18. // does not support adding a host app to test targets.
  19. #if !SWIFT_PACKAGE
  20. // Skip keychain tests on Catalyst and macOS. Tests are skipped because they
  21. // involve interactions with the keychain that require a provisioning profile.
  22. // See go/firebase-macos-keychain-popups for more details.
  23. #if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
  24. #import <XCTest/XCTest.h>
  25. #import "FBLPromise+Testing.h"
  26. #import <FirebaseCore/FirebaseCore.h>
  27. #import "FirebaseAppCheck/Sources/Core/APIService/FIRAppCheckAPIService.h"
  28. #import "FirebaseAppCheck/Sources/DeviceCheckProvider/API/FIRDeviceCheckAPIService.h"
  29. #import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckToken.h"
  30. #import "FirebaseCore/Extension/FirebaseCoreInternal.h"
  31. @interface FIRDeviceCheckAPIServiceE2ETests : XCTestCase
  32. @property(nonatomic) FIRDeviceCheckAPIService *deviceCheckAPIService;
  33. @property(nonatomic) FIRAppCheckAPIService *APIService;
  34. @property(nonatomic) NSURLSession *URLSession;
  35. @end
  36. // TODO(ncooke3): Fix these tests up and get them running on CI.
  37. @implementation FIRDeviceCheckAPIServiceE2ETests
  38. - (void)setUp {
  39. self.URLSession = [NSURLSession
  40. sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  41. FIROptions *options = [self firebaseTestOptions];
  42. FIRHeartbeatLogger *heartbeatLogger =
  43. [[FIRHeartbeatLogger alloc] initWithAppID:options.googleAppID];
  44. self.APIService = [[FIRAppCheckAPIService alloc] initWithURLSession:self.URLSession
  45. APIKey:options.APIKey
  46. appID:options.googleAppID
  47. heartbeatLogger:heartbeatLogger];
  48. self.deviceCheckAPIService =
  49. [[FIRDeviceCheckAPIService alloc] initWithAPIService:self.APIService
  50. projectID:options.projectID
  51. appID:options.googleAppID];
  52. }
  53. - (void)tearDown {
  54. self.deviceCheckAPIService = nil;
  55. self.APIService = nil;
  56. self.URLSession = nil;
  57. }
  58. // TODO: Re-enable the test once secret with "GoogleService-Info.plist" is configured.
  59. - (void)temporaryDisabled_testAppCheckTokenSuccess {
  60. __auto_type appCheckPromise =
  61. [self.deviceCheckAPIService appCheckTokenWithDeviceToken:[NSData data]];
  62. XCTAssert(FBLWaitForPromisesWithTimeout(20));
  63. XCTAssertNil(appCheckPromise.error);
  64. XCTAssertNotNil(appCheckPromise.value);
  65. XCTAssertNotNil(appCheckPromise.value.token);
  66. XCTAssertNotNil(appCheckPromise.value.expirationDate);
  67. }
  68. #pragma mark - Helpers
  69. - (FIROptions *)firebaseTestOptions {
  70. NSString *plistPath =
  71. [[NSBundle bundleForClass:[self class]] pathForResource:@"GoogleService-Info"
  72. ofType:@"plist"];
  73. FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:plistPath];
  74. return options;
  75. }
  76. @end
  77. #endif // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
  78. #endif // !SWIFT_PACKAGE