Skip to content

Commit 16304ea

Browse files
authored
[AppCheck] Disable tests that use keychain (#10146)
1 parent 737700d commit 16304ea

File tree

5 files changed

+87
-39
lines changed

5 files changed

+87
-39
lines changed

FirebaseAppCheck/Tests/Integration/FIRDeviceCheckAPIServiceE2ETests.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
#import <TargetConditionals.h>
18+
19+
// Tests that use the Keychain require a host app and Swift Package Manager
20+
// does not support adding a host app to test targets.
21+
#if !SWIFT_PACKAGE
22+
23+
// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
24+
// involve interactions with the keychain that require a provisioning profile.
25+
// See go/firebase-macos-keychain-popups for more details.
26+
#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
27+
1728
#import <XCTest/XCTest.h>
1829

1930
#import "FBLPromise+Testing.h"
@@ -84,3 +95,7 @@ - (FIROptions *)firebaseTestOptions {
8495
}
8596

8697
@end
98+
99+
#endif // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
100+
101+
#endif // !SWIFT_PACKAGE

FirebaseAppCheck/Tests/Unit/AppAttestProvider/Storage/FIRAppAttestArtifactStorageTests.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
#import <TargetConditionals.h>
18+
19+
// Tests that use the Keychain require a host app and Swift Package Manager
20+
// does not support adding a host app to test targets.
21+
#if !SWIFT_PACKAGE
22+
23+
// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
24+
// involve interactions with the keychain that require a provisioning profile.
25+
// See go/firebase-macos-keychain-popups for more details.
26+
#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
27+
1728
#import <XCTest/XCTest.h>
1829

1930
#import <OCMock/OCMock.h>
@@ -51,8 +62,6 @@ - (void)tearDown {
5162
[super tearDown];
5263
}
5364

54-
#if !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
55-
5665
- (void)testSetAndGetArtifact {
5766
[self assertSetGetForStorage];
5867
}
@@ -271,6 +280,9 @@ - (void)assertIndependentSetGetForStoragesWithAppName1:(NSString *)appName1
271280
[storage2 setArtifact:nil forKey:keyID];
272281
XCTAssert(FBLWaitForPromisesWithTimeout(0.5));
273282
}
274-
#endif // !TARGET_OS_MACCATALYST
275283

276284
@end
285+
286+
#endif // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
287+
288+
#endif // !SWIFT_PACKAGE

FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckIntegrationTests.m

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#import <OCMock/OCMock.h>
2020

21+
#import <TargetConditionals.h>
22+
2123
#import "FirebaseAppCheck/Sources/Core/TokenRefresh/FIRAppCheckTokenRefresher.h"
2224
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
2325
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckProviderFactory.h"
@@ -32,6 +34,8 @@
3234

3335
NS_ASSUME_NONNULL_BEGIN
3436

37+
#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS
38+
3539
@interface DummyAppCheckProvider : NSObject <FIRAppCheckProvider>
3640
@end
3741

@@ -62,6 +66,8 @@ @interface FIRAppCheckIntegrationTests : XCTestCase
6266
@property(nonatomic, nullable) id mockAppCheckProvider;
6367
@property(nonatomic, nullable) id mockTokenRefresher;
6468

69+
- (void)testDefaultAppCheckProvider FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY;
70+
6571
@end
6672

6773
@implementation FIRAppCheckIntegrationTests
@@ -79,7 +85,7 @@ - (void)setUp {
7985
- (void)tearDown {
8086
[FIRApp resetApps];
8187

82-
if (@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, *)) {
88+
if (@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, watchOS 9.0, *)) {
8389
// Recover default provider factory.
8490
[FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
8591
}
@@ -95,40 +101,44 @@ - (void)tearDown {
95101
}
96102

97103
- (void)testDefaultAppCheckProvider {
98-
if (@available(iOS 11.0, tvOS 11.0, macOS 10.15, *)) {
99-
NSString *appName = @"testDefaultAppCheckProvider";
104+
NSString *appName = @"testDefaultAppCheckProvider";
100105

101-
// 1. Expect FIRDeviceCheckProvider to be instantiated.
106+
// 1. Expect FIRDeviceCheckProvider to be instantiated.
102107

103-
id deviceCheckProviderMock = OCMClassMock([FIRDeviceCheckProvider class]);
104-
id appValidationArg = [OCMArg checkWithBlock:^BOOL(FIRApp *app) {
105-
XCTAssertEqualObjects(app.name, appName);
106-
return YES;
107-
}];
108+
id deviceCheckProviderMock = OCMClassMock([FIRDeviceCheckProvider class]);
109+
id appValidationArg = [OCMArg checkWithBlock:^BOOL(FIRApp *app) {
110+
XCTAssertEqualObjects(app.name, appName);
111+
return YES;
112+
}];
108113

109-
OCMStub([deviceCheckProviderMock alloc]).andReturn(deviceCheckProviderMock);
110-
OCMExpect([deviceCheckProviderMock initWithApp:appValidationArg])
111-
.andReturn(deviceCheckProviderMock);
114+
OCMStub([deviceCheckProviderMock alloc]).andReturn(deviceCheckProviderMock);
115+
OCMExpect([deviceCheckProviderMock initWithApp:appValidationArg])
116+
.andReturn(deviceCheckProviderMock);
112117

113-
// 2. Configure Firebase
114-
[self configureAppWithName:appName];
118+
// 2. Configure Firebase
119+
[self configureAppWithName:appName];
115120

116-
FIRApp *app = [FIRApp appNamed:appName];
117-
XCTAssertNotNil(FIR_COMPONENT(FIRAppCheckInterop, app.container));
121+
FIRApp *app = [FIRApp appNamed:appName];
122+
XCTAssertNotNil(FIR_COMPONENT(FIRAppCheckInterop, app.container));
118123

119-
// 3. Verify
120-
OCMVerifyAll(deviceCheckProviderMock);
124+
// 3. Verify
125+
OCMVerifyAll(deviceCheckProviderMock);
121126

122-
// 4. Cleanup
123-
// Recover default provider factory.
124-
[FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
125-
[deviceCheckProviderMock stopMocking];
126-
} else {
127-
// Fallback on earlier versions
128-
}
127+
// 4. Cleanup
128+
// Recover default provider factory.
129+
[FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
130+
[deviceCheckProviderMock stopMocking];
129131
}
130132

131-
#if !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
133+
// Tests that use the Keychain require a host app and Swift Package Manager
134+
// does not support adding a host app to test targets.
135+
#if !SWIFT_PACKAGE
136+
137+
// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
138+
// involve interactions with the keychain that require a provisioning profile.
139+
// See go/firebase-macos-keychain-popups for more details.
140+
#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
141+
132142
- (void)testSetAppCheckProviderFactoryWithDefaultApp {
133143
NSString *appName = kFIRDefaultAppName;
134144

@@ -172,7 +182,10 @@ - (void)testSetAppCheckProviderFactoryWithDefaultApp {
172182
OCMVerifyAll(self.mockProviderFactory);
173183
OCMVerifyAll(self.mockAppCheckProvider);
174184
}
175-
#endif // !TARGET_OS_MACCATALYST
185+
186+
#endif // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
187+
188+
#endif // !SWIFT_PACKAGE
176189

177190
#pragma mark - Helpers
178191

@@ -213,4 +226,6 @@ - (void)disableTokenRefresher {
213226

214227
@end
215228

229+
#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
230+
216231
NS_ASSUME_NONNULL_END

FirebaseAppCheck/Tests/Unit/Core/FIRAppCheckStorageTests.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17+
#import <TargetConditionals.h>
18+
19+
// Tests that use the Keychain require a host app and Swift Package Manager
20+
// does not support adding a host app to test targets.
21+
#if !SWIFT_PACKAGE
22+
23+
// Skip keychain tests on Catalyst and macOS. Tests are skipped because they
24+
// involve interactions with the keychain that require a provisioning profile.
25+
// See go/firebase-macos-keychain-popups for more details.
26+
#if !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
27+
1728
#import <XCTest/XCTest.h>
1829

1930
#import <OCMock/OCMock.h>
@@ -50,8 +61,6 @@ - (void)tearDown {
5061
[super tearDown];
5162
}
5263

53-
#if !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
54-
5564
- (void)testSetAndGetToken {
5665
FIRAppCheckToken *tokenToStore = [[FIRAppCheckToken alloc] initWithToken:@"token"
5766
expirationDate:[NSDate distantPast]
@@ -181,6 +190,9 @@ - (void)testSetTokenPerApp {
181190
XCTAssertNil(getPromise.value);
182191
XCTAssertNil(getPromise.error);
183192
}
184-
#endif // !TARGET_OS_MACCATALYST
185193

186194
@end
195+
196+
#endif // !TARGET_OS_MACCATALYST && !TARGET_OS_OSX
197+
198+
#endif // !SWIFT_PACKAGE

Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,12 +1256,6 @@ let package = Package(
12561256
exclude: [
12571257
// Disable Swift tests as mixed targets are not supported (Xcode 12.3).
12581258
"Unit/Swift",
1259-
1260-
// Disable Keychain dependent tests as they require a host application on iOS.
1261-
"Integration",
1262-
"Unit/AppAttestProvider/Storage/FIRAppAttestArtifactStorageTests.m",
1263-
"Unit/Core/FIRAppCheckIntegrationTests.m",
1264-
"Unit/Core/FIRAppCheckStorageTests.m",
12651259
],
12661260
resources: [
12671261
.process("Fixture"),

0 commit comments

Comments
 (0)