Skip to content

Commit 3c99e7e

Browse files
FIRApp bundle ID validation: allow exact match for extensions (#5531)
* FIRApp bundle ID validation: allow exact match for extensions * Comments
1 parent 2c19ceb commit 3c99e7e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

FirebaseCore/Sources/FIRBundleUtil.m

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ + (NSArray *)relevantURLSchemes {
4949

5050
+ (BOOL)hasBundleIdentifierPrefix:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
5151
for (NSBundle *bundle in bundles) {
52-
// This allows app extensions that have the app's bundle as their prefix to pass this test.
53-
NSString *applicationBundleIdentifier =
54-
[GULAppEnvironmentUtil isAppExtension]
55-
? [self bundleIdentifierByRemovingLastPartFrom:bundle.bundleIdentifier]
56-
: bundle.bundleIdentifier;
57-
58-
if ([applicationBundleIdentifier isEqualToString:bundleIdentifier]) {
52+
if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
5953
return YES;
6054
}
55+
56+
if ([GULAppEnvironmentUtil isAppExtension]) {
57+
// A developer could be using the same `FIROptions` for both their app and extension. Since
58+
// extensions have a suffix added to the bundleID, we consider a matching prefix as valid.
59+
NSString *appBundleIDFromExtension =
60+
[self bundleIdentifierByRemovingLastPartFrom:bundle.bundleIdentifier];
61+
if ([appBundleIDFromExtension isEqualToString:bundleIdentifier]) {
62+
return YES;
63+
}
64+
}
6165
}
6266
return NO;
6367
}

FirebaseCore/Tests/Unit/FIRBundleUtilTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ - (void)testBundleIdentifierHasPrefixInBundlesForExtension {
9595
[environmentUtilsMock stopMocking];
9696
}
9797

98+
- (void)testBundleIdentifierExistsInBundlesForExtensions_exactMatch {
99+
id environmentUtilsMock = [OCMockObject mockForClass:[GULAppEnvironmentUtil class]];
100+
[[[environmentUtilsMock stub] andReturnValue:@(YES)] isAppExtension];
101+
102+
// Mock bundle should have what app extension has, the extension bundle ID.
103+
[OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test.someextension"];
104+
XCTAssertTrue([FIRBundleUtil hasBundleIdentifierPrefix:@"com.google.test.someextension"
105+
inBundles:@[ self.mockBundle ]]);
106+
107+
[environmentUtilsMock stopMocking];
108+
}
109+
98110
- (void)testBundleIdentifierHasPrefixInBundlesNotValidExtension {
99111
id environmentUtilsMock = [OCMockObject mockForClass:[GULAppEnvironmentUtil class]];
100112
[[[environmentUtilsMock stub] andReturnValue:@(YES)] isAppExtension];

0 commit comments

Comments
 (0)