Skip to content

Commit 9b194b8

Browse files
authored
Test handle universal link (#8793)
* Adding support for '-' and '_' in regex validation * Adding new unit test to check handleUniversalLink:url to return YES for valid DDL
1 parent 6a12566 commit 9b194b8

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

FirebaseDynamicLinks/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v8.9.0
2+
- [fixed] [Dynamic links] Shortlink is not handled in 8.8.0. (#8786)
3+
14
# v8.8.0
25
- [fixed] Firebase dynamic links with custom domain will only work if the custom domain has a trailing '/'. (#7087)
36
- [fixed] Fix device-only build warning for unused `processIsTranslated` function. (#8694)

FirebaseDynamicLinks/Sources/Utilities/FDLUtilities.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ BOOL FIRDLIsAValidDLWithFDLDomain(NSURL *_Nullable URL) {
248248
// Matches the *.page.link and *.app.goo.gl domains.
249249
matchesRegularExpression =
250250
([urlStr rangeOfString:@"^https?://[a-zA-Z0-9]+((\\.app\\.goo\\.gl)|(\\.page\\.link))((\\/"
251-
@"?\\?link=https?.*)|(\\/[a-zA-Z0-9]+)((\\/?\\?.*=.*)?$|$))"
251+
@"?\\?link=https?.*)|(\\/[a-zA-Z0-9-_]+)((\\/?\\?.*=.*)?$|$))"
252252
options:NSRegularExpressionSearch]
253253
.location != NSNotFound);
254254

FirebaseDynamicLinks/Tests/Unit/FIRDynamicLinksTest.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,54 @@ - (void)testHandleUniversalLinkCompletionReturnsNoForNonDDL {
13691369
}];
13701370
}
13711371

1372+
- (void)testHandleUniversalLinkCompletionReturnsYesForValidDDL {
1373+
[self.service setUpWithLaunchOptions:nil
1374+
apiKey:kAPIKey
1375+
urlScheme:kURLScheme
1376+
userDefaults:self.userDefaults];
1377+
1378+
NSArray<NSString *> *urlStrings = @[
1379+
@"https://some.page.link/test", @"https://some.page.link/test-test",
1380+
@"https://some.page.link/test_test", @"https://some.page.link/test_test-test",
1381+
@"https://some.app.goo.gl/test_test-test"
1382+
];
1383+
1384+
for (NSString *urlString in urlStrings) {
1385+
NSURL *url = [NSURL URLWithString:urlString];
1386+
1387+
void (^executeRequestBlock)(id, NSDictionary *, NSString *,
1388+
FIRNetworkRequestCompletionHandler) =
1389+
^(id p1, NSDictionary *requestBody, NSString *requestURLString,
1390+
FIRNetworkRequestCompletionHandler handler) {
1391+
NSData *data = FIRDataWithDictionary(@{}, nil);
1392+
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url
1393+
statusCode:200
1394+
HTTPVersion:nil
1395+
headerFields:nil];
1396+
handler(data, response, nil);
1397+
};
1398+
1399+
SEL executeRequestSelector = @selector(executeOnePlatformRequest:forURL:completionHandler:);
1400+
[GULSwizzler swizzleClass:[FIRDynamicLinkNetworking class]
1401+
selector:executeRequestSelector
1402+
isClassSelector:NO
1403+
withBlock:executeRequestBlock];
1404+
1405+
XCTestExpectation *expectation = [self expectationWithDescription:@"handler called"];
1406+
1407+
BOOL handled = [self.service
1408+
handleUniversalLink:url
1409+
completion:^(FIRDynamicLink *_Nullable dynamicLink, NSError *_Nullable error) {
1410+
XCTAssertNotNil(dynamicLink, @"Non DDL returned FIRDynamicLink");
1411+
[expectation fulfill];
1412+
}];
1413+
1414+
XCTAssertTrue(handled, @"Valid DDL Universal Link was not handled");
1415+
1416+
[self waitForExpectationsWithTimeout:kAsyncTestTimout handler:nil];
1417+
}
1418+
}
1419+
13721420
- (void)test_ensureInternalMethodsNotRenamed {
13731421
// sanity check to ensure these methods has not been renamed
13741422
// we relaying on these to be the same for tests to work properly

0 commit comments

Comments
 (0)