Skip to content

Commit 79653ec

Browse files
authored
Update test for iOS 17 (and related OSes) NSURL changes. (#378)
+[NSURL URLWithString:] changed with iOS 17 (and the related OSes), it used to always fail (return nil) for some invalid urls. The test depended on that behavior. Now NSURL will escape the characters that would have failed things before. Since the test is calling an internal helper it will only ever see urls that return in redirect responses from servers. So there is no real way a server should ever return something matched the test case. Rather that change the logic in the handling, revise the test to explicitly test the nil case that was desired. If there ever is a concern that a server might get some other redirect from "secure" to "insecure", then we can revise the logic at that time. (it would only be around protocol changes) Fixes #368
1 parent 0498f59 commit 79653ec

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

UnitTests/GTMSessionFetcherFetchingTest.m

+16-8
Original file line numberDiff line numberDiff line change
@@ -2769,20 +2769,28 @@ - (void)testFetcherRedirectURLHandling {
27692769
@[ @"http://original_host/", @"https://redirect_host/", @"https://redirect_host/" ],
27702770
// Secure to insecure = disallowed.
27712771
@[ @"https://original_host/", @"http://redirect_host/", @"https://redirect_host/" ],
2772-
// Arbitrary change = disallowed.
2772+
// Arbitrary change = disallowed. This really shouldn't happen since there
2773+
// would be a redirect from a server to a different protocol.
27732774
@[ @"http://original_host/", @"fake://redirect_host/", @"http://redirect_host/" ],
27742775
// Validate the behavior of nil URLs in the redirect. This should not happen under
2775-
// real conditions, but if one of the redirect URLs are nil, the other one should
2776-
// always be returned. For these tests, use a string that will not parse to a URL
2777-
// due to invalid characters (the backslash \).
2778-
@[ @"invalid:\\url", @"https://redirect_host/", @"https://redirect_host/" ],
2779-
@[ @"http://original_host/", @"invalid:\\url", @"http://original_host/" ],
2776+
// real conditions, but iOS 17 (and the related OSes) changes their behavior for
2777+
// +[NSURL URLWithString:] for invalid characters, and what used to be a otherwise
2778+
// malformed URL now gets the characters encoded. This maintains the testing of
2779+
// the internal helper for these cases, but since the helper is only calls from
2780+
// an NSURLSession redirect handing, that path should never really see these
2781+
// sort of cases.
2782+
@[ @"[nil]", @"https://redirect_host/", @"https://redirect_host/" ],
2783+
@[ @"http://original_host/", @"[nil]", @"http://original_host/" ],
27802784
];
27812785

2786+
NSURL *(^toNSURL)(NSString*) = ^NSURL*(NSString *s) {
2787+
return [s isEqual:@"[nil]"] ? nil : [NSURL URLWithString:s];
2788+
};
2789+
27822790
for (NSArray<NSString *> *testCase in testCases) {
27832791
NSURL *redirectURL =
2784-
[GTMSessionFetcher redirectURLWithOriginalRequestURL:[NSURL URLWithString:testCase[0]]
2785-
redirectRequestURL:[NSURL URLWithString:testCase[1]]];
2792+
[GTMSessionFetcher redirectURLWithOriginalRequestURL:toNSURL(testCase[0])
2793+
redirectRequestURL:toNSURL(testCase[1])];
27862794
XCTAssertEqualObjects(redirectURL, [NSURL URLWithString:testCase[2]]);
27872795
}
27882796
}

0 commit comments

Comments
 (0)