FIRDeviceCheckAPIServiceE2ETests.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <XCTest/XCTest.h>
  17. #import "FBLPromise+Testing.h"
  18. #import <FirebaseCore/FirebaseCore.h>
  19. #import "FirebaseAppCheck/Sources/Core/APIService/FIRAppCheckAPIService.h"
  20. #import "FirebaseAppCheck/Sources/DeviceCheckProvider/API/FIRDeviceCheckAPIService.h"
  21. #import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckToken.h"
  22. #import "FirebaseCore/Extension/FirebaseCoreInternal.h"
  23. @interface FIRDeviceCheckAPIServiceE2ETests : XCTestCase
  24. @property(nonatomic) FIRDeviceCheckAPIService *deviceCheckAPIService;
  25. @property(nonatomic) FIRAppCheckAPIService *APIService;
  26. @property(nonatomic) NSURLSession *URLSession;
  27. @end
  28. // TODO(ncooke3): Fix these tests up and get them running on CI.
  29. @implementation FIRDeviceCheckAPIServiceE2ETests
  30. - (void)setUp {
  31. self.URLSession = [NSURLSession
  32. sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  33. FIROptions *options = [self firebaseTestOptions];
  34. FIRHeartbeatLogger *heartbeatLogger =
  35. [[FIRHeartbeatLogger alloc] initWithAppID:options.googleAppID];
  36. self.APIService = [[FIRAppCheckAPIService alloc] initWithURLSession:self.URLSession
  37. APIKey:options.APIKey
  38. appID:options.googleAppID
  39. heartbeatLogger:heartbeatLogger];
  40. self.deviceCheckAPIService =
  41. [[FIRDeviceCheckAPIService alloc] initWithAPIService:self.APIService
  42. projectID:options.projectID
  43. appID:options.googleAppID];
  44. }
  45. - (void)tearDown {
  46. self.deviceCheckAPIService = nil;
  47. self.APIService = nil;
  48. self.URLSession = nil;
  49. }
  50. // TODO: Re-enable the test once secret with "GoogleService-Info.plist" is configured.
  51. - (void)temporaryDisabled_testAppCheckTokenSuccess {
  52. __auto_type appCheckPromise =
  53. [self.deviceCheckAPIService appCheckTokenWithDeviceToken:[NSData data]];
  54. XCTAssert(FBLWaitForPromisesWithTimeout(20));
  55. XCTAssertNil(appCheckPromise.error);
  56. XCTAssertNotNil(appCheckPromise.value);
  57. XCTAssertNotNil(appCheckPromise.value.token);
  58. XCTAssertNotNil(appCheckPromise.value.expirationDate);
  59. }
  60. #pragma mark - Helpers
  61. - (FIROptions *)firebaseTestOptions {
  62. NSString *plistPath =
  63. [[NSBundle bundleForClass:[self class]] pathForResource:@"GoogleService-Info"
  64. ofType:@"plist"];
  65. FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:plistPath];
  66. return options;
  67. }
  68. @end