diff --git a/tests/validators/invalid_urls.txt b/tests/validators/invalid_urls.txt deleted file mode 100644 index 8a04800d85..0000000000 --- a/tests/validators/invalid_urls.txt +++ /dev/null @@ -1,81 +0,0 @@ -foo -http:// -http://example -http://example. -http://example.com:-1 -http://example.com:-1/ -http://example.com:000000080 -http://example.com:000000080/ -http://.com -http://invalid-.com -http://-invalid.com -http://invalid.com- -http://invalid.-com -http://inv-.alid-.com -http://inv-.-alid.com -file://localhost/path -git://example.com/ -http://. -http://.. -http://../ -http://? -http://?? -http://??/ -http://# -http://## -http://##/ -http://foo.bar?q=Spaces should be encoded -// -//a -///a -/// -http:///a -foo.com -rdar://1234 -h://test -http:// shouldfail.com -:// should fail -http://foo.bar/foo(bar)baz quux -http://-error-.invalid/ -http://dashinpunytld.trailingdot.xn--. -http://dashinpunytld.xn--- -http://-a.b.co -http://a.b-.co -http://a.-b.co -http://a.b-.c.co -http:/ -http:// -http:// -http://1.1.1.1.1 -http://123.123.123 -http://3628126748 -http://123 -http://000.000.000.000 -http://016.016.016.016 -http://192.168.000.001 -http://01.2.3.4 -http://01.2.3.4 -http://1.02.3.4 -http://1.2.03.4 -http://1.2.3.04 -http://.www.foo.bar/ -http://.www.foo.bar./ -http://[::1:2::3]:8/ -http://[::1:2::3]:8080/ -http://[] -http://[]:8080 -http://example..com/ -http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.com -http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com -http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaa -https://test.[com -http://@example.com -http://:@example.com -http://:bar@example.com -http://foo@bar@example.com -http://foo/bar@example.com -http://foo:bar:baz@example.com -http://foo:bar@baz@example.com -http://foo:bar/baz@example.com -http://invalid-.com/?m=foo@example.com diff --git a/tests/validators/tests.py b/tests/validators/tests.py index e39d0e3a1c..9256ed15ba 100644 --- a/tests/validators/tests.py +++ b/tests/validators/tests.py @@ -1,4 +1,3 @@ -import os import re import types from datetime import datetime, timedelta @@ -29,6 +28,229 @@ else: NOW = datetime.now() EXTENDED_SCHEMES = ['http', 'https', 'ftp', 'ftps', 'git', 'file', 'git+ssh'] +VALID_URLS = [ + 'http://www.djangoproject.com/', + 'HTTP://WWW.DJANGOPROJECT.COM/', + 'http://localhost/', + 'http://example.com/', + 'http://example.com:0', + 'http://example.com:0/', + 'http://example.com:65535', + 'http://example.com:65535/', + 'http://example.com./', + 'http://www.example.com/', + 'http://www.example.com:8000/test', + 'http://valid-with-hyphens.com/', + 'http://subdomain.example.com/', + 'http://a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'http://200.8.9.10/', + 'http://200.8.9.10:8000/test', + 'http://su--b.valid-----hyphens.com/', + 'http://example.com?something=value', + 'http://example.com/index.php?something=value&another=value2', + 'https://example.com/', + 'ftp://example.com/', + 'ftps://example.com/', + 'http://foo.com/blah_blah', + 'http://foo.com/blah_blah/', + 'http://foo.com/blah_blah_(wikipedia)', + 'http://foo.com/blah_blah_(wikipedia)_(again)', + 'http://www.example.com/wpstyle/?p=364', + 'https://www.example.com/foo/?bar=baz&inga=42&quux', + 'http://✪df.ws/123', + 'http://userid@example.com', + 'http://userid@example.com/', + 'http://userid@example.com:8080', + 'http://userid@example.com:8080/', + 'http://userid@example.com:65535', + 'http://userid@example.com:65535/', + 'http://userid:@example.com', + 'http://userid:@example.com/', + 'http://userid:@example.com:8080', + 'http://userid:@example.com:8080/', + 'http://userid:password@example.com', + 'http://userid:password@example.com/', + 'http://userid:password@example.com:8', + 'http://userid:password@example.com:8/', + 'http://userid:password@example.com:8080', + 'http://userid:password@example.com:8080/', + 'http://userid:password@example.com:65535', + 'http://userid:password@example.com:65535/', + 'https://userid:paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaassword@example.com', + 'https://userid:paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaassword@example.com:8080', + 'https://useridddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'dddddddddddddddddddddd:password@example.com', + 'https://useridddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' + 'ddddddddddddddddd:password@example.com:8080', + 'http://142.42.1.1/', + 'http://142.42.1.1:8080/', + 'http://➡.ws/䨹', + 'http://⌘.ws', + 'http://⌘.ws/', + 'http://foo.com/blah_(wikipedia)#cite-1', + 'http://foo.com/blah_(wikipedia)_blah#cite-1', + 'http://foo.com/unicode_(✪)_in_parens', + 'http://foo.com/(something)?after=parens', + 'http://☺.damowmow.com/', + 'http://djangoproject.com/events/#&product=browser', + 'http://j.mp', + 'ftp://foo.bar/baz', + 'http://foo.bar/?q=Test%20URL-encoded%20stuff', + 'http://مثال.إختبار', + 'http://例子.测试', + 'http://उदाहरण.परीक्षा', + "http://-.~_!$&'()*+,;=%40:80%2f@example.com", + 'http://xn--7sbb4ac0ad0be6cf.xn--p1ai', + 'http://1337.net', + 'http://a.b-c.de', + 'http://223.255.255.254', + 'ftps://foo.bar/', + 'http://10.1.1.254', + 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html', + 'http://[::192.9.5.5]/ipng', + 'http://[::ffff:192.9.5.5]/ipng', + 'http://[::1]:8080/', + 'http://0.0.0.0/', + 'http://255.255.255.255', + 'http://224.0.0.0', + 'http://224.1.1.1', + 'http://111.112.113.114/', + 'http://88.88.88.88/', + 'http://11.12.13.14/', + 'http://10.20.30.40/', + 'http://1.2.3.4/', + 'http://127.0.01.09.home.lan', + 'http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ex' + 'ample.com', + 'http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaa.com', + 'http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaa', + 'http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa' + 'aaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaa', + 'http://dashintld.c-m', + 'http://multipledashintld.a-b-c', + 'http://evenmoredashintld.a---c', + 'http://dashinpunytld.xn---c', +] + +INVALID_URLS = [ + None, + 56, + 'no_scheme', + 'foo', + 'http://', + 'http://example', + 'http://example.', + 'http://example.com:-1', + 'http://example.com:-1/', + 'http://example.com:000000080', + 'http://example.com:000000080/', + 'http://.com', + 'http://invalid-.com', + 'http://-invalid.com', + 'http://invalid.com-', + 'http://invalid.-com', + 'http://inv-.alid-.com', + 'http://inv-.-alid.com', + 'file://localhost/path', + 'git://example.com/', + 'http://.', + 'http://..', + 'http://../', + 'http://?', + 'http://??', + 'http://??/', + 'http://#', + 'http://##', + 'http://##/', + 'http://foo.bar?q=Spaces should be encoded', + '//', + '//a', + '///a', + '///', + 'http:///a', + 'foo.com', + 'rdar://1234', + 'h://test', + 'http:// shouldfail.com', + ':// should fail', + 'http://foo.bar/foo(bar)baz quux', + 'http://-error-.invalid/', + 'http://dashinpunytld.trailingdot.xn--.', + 'http://dashinpunytld.xn---', + 'http://-a.b.co', + 'http://a.b-.co', + 'http://a.-b.co', + 'http://a.b-.c.co', + 'http:/', + 'http://', + 'http://', + 'http://1.1.1.1.1', + 'http://123.123.123', + 'http://3628126748', + 'http://123', + 'http://000.000.000.000', + 'http://016.016.016.016', + 'http://192.168.000.001', + 'http://01.2.3.4', + 'http://01.2.3.4', + 'http://1.02.3.4', + 'http://1.2.03.4', + 'http://1.2.3.04', + 'http://.www.foo.bar/', + 'http://.www.foo.bar./', + 'http://[::1:2::3]:8/', + 'http://[::1:2::3]:8080/', + 'http://[]', + 'http://[]:8080', + 'http://example..com/', + 'http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.e' + 'xample.com', + 'http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaa.com', + 'http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' + 'aaaaaa', + 'http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.' + 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaa' + 'aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaa' + 'aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaa', + 'https://test.[com', + 'http://@example.com', + 'http://:@example.com', + 'http://:bar@example.com', + 'http://foo@bar@example.com', + 'http://foo/bar@example.com', + 'http://foo:bar:baz@example.com', + 'http://foo:bar@baz@example.com', + 'http://foo:bar/baz@example.com', + 'http://invalid-.com/?m=foo@example.com', + # Newlines and tabs are not accepted. + 'http://www.djangoproject.com/\n', + 'http://[::ffff:192.9.5.5]\n', + 'http://www.djangoproject.com/\r', + 'http://[::ffff:192.9.5.5]\r', + 'http://www.django\rproject.com/', + 'http://[::\rffff:192.9.5.5]', + 'http://\twww.djangoproject.com/', + 'http://\t[::ffff:192.9.5.5]', + # Trailing junk does not take forever to reject. + 'http://www.asdasdasdasdsadfm.com.br ', + 'http://www.asdasdasdasdsadfm.com.br z', +] + TEST_DATA = [ # (validator, value, expected), (validate_integer, '42', None), @@ -243,21 +465,6 @@ TEST_DATA = [ (URLValidator(EXTENDED_SCHEMES), 'git+ssh://git@github.com/example/hg-git.git', None), (URLValidator(EXTENDED_SCHEMES), 'git://-invalid.com', ValidationError), - (URLValidator(), None, ValidationError), - (URLValidator(), 56, ValidationError), - (URLValidator(), 'no_scheme', ValidationError), - # Newlines and tabs are not accepted. - (URLValidator(), 'http://www.djangoproject.com/\n', ValidationError), - (URLValidator(), 'http://[::ffff:192.9.5.5]\n', ValidationError), - (URLValidator(), 'http://www.djangoproject.com/\r', ValidationError), - (URLValidator(), 'http://[::ffff:192.9.5.5]\r', ValidationError), - (URLValidator(), 'http://www.django\rproject.com/', ValidationError), - (URLValidator(), 'http://[::\rffff:192.9.5.5]', ValidationError), - (URLValidator(), 'http://\twww.djangoproject.com/', ValidationError), - (URLValidator(), 'http://\t[::ffff:192.9.5.5]', ValidationError), - # Trailing junk does not take forever to reject - (URLValidator(), 'http://www.asdasdasdasdsadfm.com.br ', ValidationError), - (URLValidator(), 'http://www.asdasdasdasdsadfm.com.br z', ValidationError), (BaseValidator(True), True, None), (BaseValidator(True), False, ValidationError), @@ -325,19 +532,10 @@ TEST_DATA = [ (ProhibitNullCharactersValidator(), None, None), ] - -def create_path(filename): - return os.path.abspath(os.path.join(os.path.dirname(__file__), filename)) - - # Add valid and invalid URL tests. # This only tests the validator without extended schemes. -with open(create_path('valid_urls.txt'), encoding='utf8') as f: - for url in f: - TEST_DATA.append((URLValidator(), url.strip(), None)) -with open(create_path('invalid_urls.txt'), encoding='utf8') as f: - for url in f: - TEST_DATA.append((URLValidator(), url.strip(), ValidationError)) +TEST_DATA.extend((URLValidator(), url, None) for url in VALID_URLS) +TEST_DATA.extend((URLValidator(), url, ValidationError) for url in INVALID_URLS) class TestValidators(SimpleTestCase): diff --git a/tests/validators/valid_urls.txt b/tests/validators/valid_urls.txt deleted file mode 100644 index 1420d727a8..0000000000 --- a/tests/validators/valid_urls.txt +++ /dev/null @@ -1,97 +0,0 @@ -http://www.djangoproject.com/ -HTTP://WWW.DJANGOPROJECT.COM/ -http://localhost/ -http://example.com/ -http://example.com:0 -http://example.com:0/ -http://example.com:65535 -http://example.com:65535/ -http://example.com./ -http://www.example.com/ -http://www.example.com:8000/test -http://valid-with-hyphens.com/ -http://subdomain.example.com/ -http://a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -http://200.8.9.10/ -http://200.8.9.10:8000/test -http://su--b.valid-----hyphens.com/ -http://example.com?something=value -http://example.com/index.php?something=value&another=value2 -https://example.com/ -ftp://example.com/ -ftps://example.com/ -http://foo.com/blah_blah -http://foo.com/blah_blah/ -http://foo.com/blah_blah_(wikipedia) -http://foo.com/blah_blah_(wikipedia)_(again) -http://www.example.com/wpstyle/?p=364 -https://www.example.com/foo/?bar=baz&inga=42&quux -http://✪df.ws/123 -http://userid@example.com -http://userid@example.com/ -http://userid@example.com:8080 -http://userid@example.com:8080/ -http://userid@example.com:65535 -http://userid@example.com:65535/ -http://userid:@example.com -http://userid:@example.com/ -http://userid:@example.com:8080 -http://userid:@example.com:8080/ -http://userid:password@example.com -http://userid:password@example.com/ -http://userid:password@example.com:8 -http://userid:password@example.com:8/ -http://userid:password@example.com:8080 -http://userid:password@example.com:8080/ -http://userid:password@example.com:65535 -http://userid:password@example.com:65535/ -https://userid:paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassword@example.com -https://userid:paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassword@example.com:8080 -https://useridddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd:password@example.com -https://useriddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd:password@example.com:8080 -http://142.42.1.1/ -http://142.42.1.1:8080/ -http://➡.ws/䨹 -http://⌘.ws -http://⌘.ws/ -http://foo.com/blah_(wikipedia)#cite-1 -http://foo.com/blah_(wikipedia)_blah#cite-1 -http://foo.com/unicode_(✪)_in_parens -http://foo.com/(something)?after=parens -http://☺.damowmow.com/ -http://djangoproject.com/events/#&product=browser -http://j.mp -ftp://foo.bar/baz -http://foo.bar/?q=Test%20URL-encoded%20stuff -http://مثال.إختبار -http://例子.测试 -http://उदाहरण.परीक्षा -http://-.~_!$&'()*+,;=%40:80%2f@example.com -http://xn--7sbb4ac0ad0be6cf.xn--p1ai -http://1337.net -http://a.b-c.de -http://223.255.255.254 -ftps://foo.bar/ -http://10.1.1.254 -http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html -http://[::192.9.5.5]/ipng -http://[::ffff:192.9.5.5]/ipng -http://[::1]:8080/ -http://0.0.0.0/ -http://255.255.255.255 -http://224.0.0.0 -http://224.1.1.1 -http://111.112.113.114/ -http://88.88.88.88/ -http://11.12.13.14/ -http://10.20.30.40/ -http://1.2.3.4/ -http://127.0.01.09.home.lan -http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example.com -http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com -http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaa -http://dashintld.c-m -http://multipledashintld.a-b-c -http://evenmoredashintld.a---c -http://dashinpunytld.xn---c