|
8 | 8 |
|
9 | 9 | URL_TESTS = ( |
10 | 10 | # Valid URLs |
11 | | - ("http://example.com", "hxxp://example[.]com"), |
12 | | - ("http://1.2.3.4/", "hxxp://1[.]2[.]3[.]4/"), |
13 | | - ("http://[fd00:1234::4321]/", "hxxp://[fd00[:]1234[:][:]4321]/"), |
14 | | - ("ftp://1.2.3.4/", "fxp://1[.]2[.]3[.]4/"), |
| 11 | + ("http://example.com", ("hxxp://example[.]com")), |
| 12 | + ("http://1.2.3.4/mgr.cgi", ("hxxp://1[.]2[.]3[.]4/mgr.cgi")), |
| 13 | + ("http://[fd00:1234::4321]/", ("hxxp://[fd00[:]1234[:][:]4321]/")), |
| 14 | + ("ftp://1.2.3.4/", ("fxp://1[.]2[.]3[.]4/")), |
15 | 15 | # Invalid, but parsed anyway |
16 | | - ("http://<Target-IP>/", "hxxp://<Target-IP>/"), |
17 | | - ("http://1.2.3.4.5/", "hxxp://1[.]2[.]3[.]4[.]5/"), |
18 | | - ("http://555.555.555.555/", "hxxp://555[.]555[.]555[.]555/"), |
19 | | - # Fallback path |
20 | | - ("http://[fd00:::]/", "http[:]//[fd00[:][:][:]]/"), |
| 16 | + ("http://<placeholder>/", ("hxxp://<placeholder>/")), |
| 17 | + ("http://1.2.3.4.5/", ("hxxp://1[.]2[.]3[.]4[.]5/")), |
| 18 | + ("http://555.555.555.555/", ("hxxp://555[.]555[.]555[.]555/")), |
| 19 | + # urllib.urlparse() works in python <=3.10 but fails in 3.11 |
| 20 | + ("http://[fd00:::]/", ("hxxp://[fd00[:][:][:]]/", "http[:]//[fd00[:][:][:]]/")), |
| 21 | + ("http://[placeholder]/", ("hxxp://[placeholder]/", "http[:]//[placeholder]/")), |
21 | 22 | ) |
22 | 23 |
|
23 | 24 |
|
24 | | -@pytest.mark.parametrize("original, safed", URL_TESTS) |
25 | | -def test_safeify_url(original, safed): |
26 | | - assert safeify_url(original) == safed |
27 | | - |
28 | | - |
29 | | -def test_safeify_maybe_parsefail(): |
30 | | - # Parse succeeds in python <=3.10 but fails in 3.11 |
31 | | - original = "http://[Target-IP]/account_mgr.cgi" |
32 | | - parseok = "hxxp://[Target-IP]/account_mgr.cgi" |
33 | | - parsefail = "http[:]//[Target-IP]/account_mgr[.]cgi" |
34 | | - |
35 | | - assert safeify_url(original) in (parseok, parsefail) |
| 25 | +@pytest.mark.parametrize("original, safed_options", URL_TESTS) |
| 26 | +def test_safeify_url(original, safed_options): |
| 27 | + assert safeify_url(original) in safed_options |
0 commit comments