Skip to content

Commit 8760bc7

Browse files
committed
test(vision): align SSRF tests with merged imageUrl validation
GoogleCloudPlatform#10389 landed with the ASCII-host check inlined in requireAllowedImageUrl and with explicit port 443 allowed. Update the tests to match: - Drop the isAllowedImageHost unit tests; that helper is not part of the merged code. Unicode lookalike hosts are still covered at the URL level. - Accept an explicit default HTTPS port (:443) and keep rejecting non-default ports (:80, :8080) and malformed ports. - Remove the now-unused assertTrue/assertFalse imports.
1 parent 152a388 commit 8760bc7

1 file changed

Lines changed: 7 additions & 35 deletions

File tree

‎vision/spring-framework/src/test/java/com/example/vision/VisionControllerTest.java‎

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package com.example.vision;
1818

1919
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
21-
import static org.junit.Assert.assertTrue;
2220
import static org.junit.Assert.fail;
2321
import static org.mockito.Mockito.mock;
2422
import static org.mockito.Mockito.verify;
@@ -173,37 +171,6 @@ public void requireAllowedImageUrl_rejectsUnicodeCaseFoldingLookalikes() {
173171
assertRejected("https://storage.googKeapis.com/b/o");
174172
}
175173

176-
@Test
177-
public void isAllowedImageHost_rejectsNonAsciiLookalikesThatEqualsIgnoreCaseWouldAccept() {
178-
// Exercises the ASCII guard directly: java.net.URI currently returns a null host for these
179-
// authorities, so the URL-level test above would pass even without the guard.
180-
String[] lookalikes = {
181-
"ſtorage.googleapis.com", // U+017F long s folds to 's'
182-
"storage.googleapıs.com", // U+0131 dotless i folds to 'i'
183-
"ſtorage.googleapıs.com", // both
184-
};
185-
for (String host : lookalikes) {
186-
assertTrue(
187-
"precondition: equalsIgnoreCase matches " + host,
188-
"storage.googleapis.com".equalsIgnoreCase(host));
189-
assertFalse(
190-
"Expected host to be rejected: " + host, VisionController.isAllowedImageHost(host));
191-
}
192-
// U+212A Kelvin sign folds to 'k'. The allowed host has no 'k', so it cannot produce a
193-
// case-insensitive match here, but any non-ASCII host must still be rejected.
194-
assertFalse(VisionController.isAllowedImageHost("storage.googKeapis.com")); // U+212A
195-
assertFalse(VisionController.isAllowedImageHost("Kstorage.googleapis.com")); // U+212A
196-
}
197-
198-
@Test
199-
public void isAllowedImageHost_acceptsAsciiHostInAnyCase() {
200-
assertTrue(VisionController.isAllowedImageHost("storage.googleapis.com"));
201-
assertTrue(VisionController.isAllowedImageHost("STORAGE.GOOGLEAPIS.COM"));
202-
assertTrue(VisionController.isAllowedImageHost("Storage.GoogleApis.Com"));
203-
assertFalse(VisionController.isAllowedImageHost(null));
204-
assertFalse(VisionController.isAllowedImageHost(""));
205-
}
206-
207174
@Test
208175
public void requireAllowedImageUrl_rejectsUserInfo() {
209176
assertRejected("https://storage.googleapis.com@evil.example/b/o");
@@ -214,8 +181,13 @@ public void requireAllowedImageUrl_rejectsUserInfo() {
214181
}
215182

216183
@Test
217-
public void requireAllowedImageUrl_rejectsExplicitPorts() {
218-
assertRejected("https://storage.googleapis.com:443/b/o");
184+
public void requireAllowedImageUrl_acceptsExplicitDefaultHttpsPort() {
185+
assertAccepted("https://storage.googleapis.com:443/b/o.jpg");
186+
}
187+
188+
@Test
189+
public void requireAllowedImageUrl_rejectsNonDefaultPorts() {
190+
assertRejected("https://storage.googleapis.com:80/b/o");
219191
assertRejected("https://storage.googleapis.com:8080/b/o");
220192
assertRejected("https://storage.googleapis.com:abc/b/o");
221193
}

0 commit comments

Comments
 (0)