Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Example/Core/Tests/FIRBundleUtilTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,22 @@ - (void)testFindOptionsDictionaryPath_secondBundle {
- (void)testBundleIdentifierExistsInBundles {
NSString *bundleID = @"com.google.test";
[OCMStub([self.mockBundle bundleIdentifier]) andReturn:bundleID];
XCTAssertTrue([FIRBundleUtil hasBundleIdentifier:bundleID inBundles:@[ self.mockBundle ]]);
XCTAssertTrue([FIRBundleUtil hasBundleIdentifierPrefix:bundleID inBundles:@[ self.mockBundle ]]);
}

- (void)testBundleIdentifierExistsInBundles_notExist {
[OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test"];
XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"not-exist" inBundles:@[ self.mockBundle ]]);
XCTAssertFalse([FIRBundleUtil hasBundleIdentifierPrefix:@"not-exist" inBundles:@[ self.mockBundle ]]);
}

- (void)testBundleIdentifierExistsInBundles_emptyBundlesArray {
XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"com.google.test" inBundles:@[]]);
XCTAssertFalse([FIRBundleUtil hasBundleIdentifierPrefix:@"com.google.test" inBundles:@[]]);
}

- (void)testBundleIdentifierHasPrefixInBundles {
[OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test"];
XCTAssertTrue([FIRBundleUtil hasBundleIdentifierPrefix:@"com.google.test.someextension"
inBundles:@[ self.mockBundle ]]);
}

@end
2 changes: 1 addition & 1 deletion Firebase/Core/FIRApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ - (void)checkExpectedBundleID {
NSString *expectedBundleID = [self expectedBundleID];
// The checking is only done when the bundle ID is provided in the serviceInfo dictionary for
// backward compatibility.
if (expectedBundleID != nil && ![FIRBundleUtil hasBundleIdentifier:expectedBundleID
if (expectedBundleID != nil && ![FIRBundleUtil hasBundleIdentifierPrefix:expectedBundleID
inBundles:bundles]) {
FIRLogError(kFIRLoggerCore, @"I-COR000008",
@"The project's Bundle ID is inconsistent with "
Expand Down
5 changes: 3 additions & 2 deletions Firebase/Core/FIRBundleUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ + (NSArray *)relevantURLSchemes {
return result;
}

+ (BOOL)hasBundleIdentifier:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
+ (BOOL)hasBundleIdentifierPrefix:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles {
for (NSBundle *bundle in bundles) {
if ([bundle.bundleIdentifier isEqualToString:bundleIdentifier]) {
// This allows app extensions that have the app's bundle as their prefix to pass this test.
if ([bundleIdentifier hasPrefix:bundle.bundleIdentifier]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to be a bit more careful here I think - this would match on things like com.firebase.foobar or com.firebase.foo.staging where it should only match on com.firebase.foo.

We could change the method call to matchesBundleIdentifier:inBundles: which could do an exact string match if it's not an extension, but if it is, compare to ensure it's the entire bundleID + a period + an extension identifier.

There's an existing isAppExtension call in GoogleUtilities I believe we could use, and if that's true, separate by ., drop the last one, and re-assemble to verify that it's identical.

return YES;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Firebase/Core/Private/FIRBundleUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
+ (NSArray *)relevantURLSchemes;

/**
* Checks if the bundle identifier exists in the given bundles.
* Checks the given bundles to see of them is a prefix of the given identifier.
*/
+ (BOOL)hasBundleIdentifier:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles;
+ (BOOL)hasBundleIdentifierPrefix:(NSString *)bundleIdentifier inBundles:(NSArray *)bundles;

@end