Преглед изворни кода

[AppCheck] Disable tests that use keychain (#10146)

Nick Cooke пре 3 година
родитељ
комит
16304ea7eb

+ 15 - 0
FirebaseAppCheck/Tests/Integration/FIRDeviceCheckAPIServiceE2ETests.m

@@ -14,6 +14,17 @@
  * limitations under the License.
  */
 
+#import <TargetConditionals.h>
+
+// Tests that use the Keychain require a host app and Swift Package Manager
+// does not support adding a host app to test targets.
+#if !SWIFT_PACKAGE
+
+// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
+// involve interactions with the keychain that require a provisioning profile.
+// See go/firebase-macos-keychain-popups for more details.
+#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
 #import <XCTest/XCTest.h>
 
 #import "FBLPromise+Testing.h"
@@ -84,3 +95,7 @@
 }
 
 @end
+
+#endif  // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
+#endif  // !SWIFT_PACKAGE

+ 15 - 3
FirebaseAppCheck/Tests/Unit/AppAttestProvider/Storage/FIRAppAttestArtifactStorageTests.m

@@ -14,6 +14,17 @@
  * limitations under the License.
  */
 
+#import <TargetConditionals.h>
+
+// Tests that use the Keychain require a host app and Swift Package Manager
+// does not support adding a host app to test targets.
+#if !SWIFT_PACKAGE
+
+// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
+// involve interactions with the keychain that require a provisioning profile.
+// See go/firebase-macos-keychain-popups for more details.
+#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
 #import <XCTest/XCTest.h>
 
 #import <OCMock/OCMock.h>
@@ -51,8 +62,6 @@
   [super tearDown];
 }
 
-#if !TARGET_OS_MACCATALYST  // Catalyst should be possible with Xcode 12.5+
-
 - (void)testSetAndGetArtifact {
   [self assertSetGetForStorage];
 }
@@ -271,6 +280,9 @@
   [storage2 setArtifact:nil forKey:keyID];
   XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
 }
-#endif  // !TARGET_OS_MACCATALYST
 
 @end
+
+#endif  // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
+#endif  // !SWIFT_PACKAGE

+ 42 - 27
FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckIntegrationTests.m

@@ -18,6 +18,8 @@
 
 #import <OCMock/OCMock.h>
 
+#import <TargetConditionals.h>
+
 #import "FirebaseAppCheck/Sources/Core/TokenRefresh/FIRAppCheckTokenRefresher.h"
 #import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
 #import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckProviderFactory.h"
@@ -32,6 +34,8 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS
+
 @interface DummyAppCheckProvider : NSObject <FIRAppCheckProvider>
 @end
 
@@ -62,6 +66,8 @@ NS_ASSUME_NONNULL_BEGIN
 @property(nonatomic, nullable) id mockAppCheckProvider;
 @property(nonatomic, nullable) id mockTokenRefresher;
 
+- (void)testDefaultAppCheckProvider FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY;
+
 @end
 
 @implementation FIRAppCheckIntegrationTests
@@ -79,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)tearDown {
   [FIRApp resetApps];
 
-  if (@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, *)) {
+  if (@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *)) {
     // Recover default provider factory.
     [FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
   }
@@ -95,40 +101,44 @@ NS_ASSUME_NONNULL_BEGIN
 }
 
 - (void)testDefaultAppCheckProvider {
-  if (@available(iOS 11.0, tvOS 11.0, macOS 10.15, *)) {
-    NSString *appName = @"testDefaultAppCheckProvider";
+  NSString *appName = @"testDefaultAppCheckProvider";
 
-    // 1. Expect FIRDeviceCheckProvider to be instantiated.
+  // 1. Expect FIRDeviceCheckProvider to be instantiated.
 
-    id deviceCheckProviderMock = OCMClassMock([FIRDeviceCheckProvider class]);
-    id appValidationArg = [OCMArg checkWithBlock:^BOOL(FIRApp *app) {
-      XCTAssertEqualObjects(app.name, appName);
-      return YES;
-    }];
+  id deviceCheckProviderMock = OCMClassMock([FIRDeviceCheckProvider class]);
+  id appValidationArg = [OCMArg checkWithBlock:^BOOL(FIRApp *app) {
+    XCTAssertEqualObjects(app.name, appName);
+    return YES;
+  }];
 
-    OCMStub([deviceCheckProviderMock alloc]).andReturn(deviceCheckProviderMock);
-    OCMExpect([deviceCheckProviderMock initWithApp:appValidationArg])
-        .andReturn(deviceCheckProviderMock);
+  OCMStub([deviceCheckProviderMock alloc]).andReturn(deviceCheckProviderMock);
+  OCMExpect([deviceCheckProviderMock initWithApp:appValidationArg])
+      .andReturn(deviceCheckProviderMock);
 
-    // 2. Configure Firebase
-    [self configureAppWithName:appName];
+  // 2. Configure Firebase
+  [self configureAppWithName:appName];
 
-    FIRApp *app = [FIRApp appNamed:appName];
-    XCTAssertNotNil(FIR_COMPONENT(FIRAppCheckInterop, app.container));
+  FIRApp *app = [FIRApp appNamed:appName];
+  XCTAssertNotNil(FIR_COMPONENT(FIRAppCheckInterop, app.container));
 
-    // 3. Verify
-    OCMVerifyAll(deviceCheckProviderMock);
+  // 3. Verify
+  OCMVerifyAll(deviceCheckProviderMock);
 
-    // 4. Cleanup
-    // Recover default provider factory.
-    [FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
-    [deviceCheckProviderMock stopMocking];
-  } else {
-    // Fallback on earlier versions
-  }
+  // 4. Cleanup
+  // Recover default provider factory.
+  [FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
+  [deviceCheckProviderMock stopMocking];
 }
 
-#if !TARGET_OS_MACCATALYST  // Catalyst should be possible with Xcode 12.5+
+// Tests that use the Keychain require a host app and Swift Package Manager
+// does not support adding a host app to test targets.
+#if !SWIFT_PACKAGE
+
+// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
+// involve interactions with the keychain that require a provisioning profile.
+// See go/firebase-macos-keychain-popups for more details.
+#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
 - (void)testSetAppCheckProviderFactoryWithDefaultApp {
   NSString *appName = kFIRDefaultAppName;
 
@@ -172,7 +182,10 @@ NS_ASSUME_NONNULL_BEGIN
   OCMVerifyAll(self.mockProviderFactory);
   OCMVerifyAll(self.mockAppCheckProvider);
 }
-#endif  // !TARGET_OS_MACCATALYST
+
+#endif  // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
+#endif  // !SWIFT_PACKAGE
 
 #pragma mark - Helpers
 
@@ -213,4 +226,6 @@ NS_ASSUME_NONNULL_BEGIN
 
 @end
 
+#endif  // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
+
 NS_ASSUME_NONNULL_END

+ 15 - 3
FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckStorageTests.m

@@ -14,6 +14,17 @@
  * limitations under the License.
  */
 
+#import <TargetConditionals.h>
+
+// Tests that use the Keychain require a host app and Swift Package Manager
+// does not support adding a host app to test targets.
+#if !SWIFT_PACKAGE
+
+// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
+// involve interactions with the keychain that require a provisioning profile.
+// See go/firebase-macos-keychain-popups for more details.
+#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
 #import <XCTest/XCTest.h>
 
 #import <OCMock/OCMock.h>
@@ -50,8 +61,6 @@
   [super tearDown];
 }
 
-#if !TARGET_OS_MACCATALYST  // Catalyst should be possible with Xcode 12.5+
-
 - (void)testSetAndGetToken {
   FIRAppCheckToken *tokenToStore = [[FIRAppCheckToken alloc] initWithToken:@"token"
                                                             expirationDate:[NSDate distantPast]
@@ -181,6 +190,9 @@
   XCTAssertNil(getPromise.value);
   XCTAssertNil(getPromise.error);
 }
-#endif  // !TARGET_OS_MACCATALYST
 
 @end
+
+#endif  // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
+
+#endif  // !SWIFT_PACKAGE

+ 0 - 6
Package.swift

@@ -1256,12 +1256,6 @@ let package = Package(
       exclude: [
         // Disable Swift tests as mixed targets are not supported (Xcode 12.3).
         "Unit/Swift",
-
-        // Disable Keychain dependent tests as they require a host application on iOS.
-        "Integration",
-        "Unit/AppAttestProvider/Storage/FIRAppAttestArtifactStorageTests.m",
-        "Unit/Core/FIRAppCheckIntegrationTests.m",
-        "Unit/Core/FIRAppCheckStorageTests.m",
       ],
       resources: [
         .process("Fixture"),