Skip to content

Commit

Permalink
fix test: domain name provided is not valid according to RFC 1034/1035
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Nov 3, 2016
1 parent 4e5a67a commit 5ffa1dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions tests/test_dynamic_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def setUp(self):
self.assertTrue(settings.DEBUG, "Must be true to skip hostname validation!")

Site.objects.all().delete()
self.site1 = Site.objects.create(pk=1, domain="domain_one.tld", name="site 1")
self.site1 = Site.objects.create(pk=1, domain="domain-one.test", name="site 1")
self.assertEqual(self.site1.pk, 1)
self.site2 = Site.objects.create(pk=2, domain="domain_two.tld", name="site 2")
self.site2 = Site.objects.create(pk=2, domain="domain-two.test", name="site 2")
self.assertEqual(self.site2.pk, 2)

self.alias1 = SiteAlias.objects.create(site=self.site1, alias="domain_one_alias_one.tld", regex=False)
self.alias2 = SiteAlias.objects.create(site=self.site1, alias="domain_one_alias_two.tld", regex=False)
self.alias3 = SiteAlias.objects.create(site=self.site2, alias="www.domain_one.tld", regex=False)
self.alias4 = SiteAlias.objects.create(site=self.site2, alias=r"^(.*?\.domain_two\.tld)$", regex=True)
self.alias1 = SiteAlias.objects.create(site=self.site1, alias="domain-one-alias-one.test", regex=False)
self.alias2 = SiteAlias.objects.create(site=self.site1, alias="domain-one-alias-two.test", regex=False)
self.alias3 = SiteAlias.objects.create(site=self.site2, alias="www.domain-one.test", regex=False)
self.alias4 = SiteAlias.objects.create(site=self.site2, alias=r"^(.*?\.domain-two\.test)$", regex=True)

def test_fallback(self):
response = self.client.get("/display_site/") # request with 'testserver'
Expand All @@ -60,57 +60,57 @@ def test_fallback(self):
)

def test_no_alias1(self):
response = self.client.get("/display_site/", HTTP_HOST="domain_one.tld")
response = self.client.get("/display_site/", HTTP_HOST="domain-one.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 1 - id from get_current(): 1'
)

def test_no_alias2(self):
response = self.client.get("/display_site/", HTTP_HOST="domain_two.tld")
response = self.client.get("/display_site/", HTTP_HOST="domain-two.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 2 - id from get_current(): 2'
)

def test_string_alias1(self):
response = self.client.get("/display_site/", HTTP_HOST="domain_one_alias_one.tld")
response = self.client.get("/display_site/", HTTP_HOST="domain-one-alias-one.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 1 - id from get_current(): 1'
)

def test_string_alias2(self):
response = self.client.get("/display_site/", HTTP_HOST="domain_one_alias_two.tld")
response = self.client.get("/display_site/", HTTP_HOST="domain-one-alias-two.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 1 - id from get_current(): 1'
)

def test_regex_alias1(self):
response = self.client.get("/display_site/", HTTP_HOST="foo.domain_two.tld")
response = self.client.get("/display_site/", HTTP_HOST="foo.domain-two.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 2 - id from get_current(): 2'
)

def test_regex_alias2(self):
response = self.client.get("/display_site/", HTTP_HOST="foo.bar.domain_two.tld")
response = self.client.get("/display_site/", HTTP_HOST="foo.bar.domain-two.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 2 - id from get_current(): 2'
)

def test_change(self):
response = self.client.get("/display_site/", HTTP_HOST="www.domain_one.tld")
response = self.client.get("/display_site/", HTTP_HOST="www.domain-one.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 2 - id from get_current(): 2'
)

self.alias3.site = self.site1
self.alias3.save() # Should clean all site caches

response = self.client.get("/display_site/", HTTP_HOST="www.domain_one.tld")
response = self.client.get("/display_site/", HTTP_HOST="www.domain-one.test")
self.assertEqual(response.content.decode("utf-8"),
'ID from settings: 1 - id from get_current(): 1'
)

def test_create(self):
host = "not_exist_yet.tld"
host = "does-not-exist-yet.test"

# Fallback to default:
response = self.client.get("/display_site/", HTTP_HOST=host)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,33 @@ def test_no_allow_all_schemes(self):
self.assertEqual(str(err), "allow_schemes would be ignored, while allow_all_schemes==True!")

def test_not_start_with_allow_all_schemes(self):
URLValidator2(allow_schemes=("svn",))("svn://domain.tld")
URLValidator2(allow_schemes=("svn",))("svn://domain.test")
try:
URLValidator2(allow_schemes=("http","ftp"))("svn://domain.tld")
URLValidator2(allow_schemes=("http","ftp"))("svn://domain.test")
except ValidationError as err:
self.assertEqual(six.text_type(err.message), "The URL doesn't start with a allowed scheme.")

def test_allow_query(self):
validator = URLValidator2(allow_query=False)
validator("http://www.domain.tld/without/query/")
validator("http://www.domain.test/without/query/")
try:
validator("http://www.domain.tld/with/?query")
validator("http://www.domain.test/with/?query")
except ValidationError as err:
self.assertEqual(six.text_type(err.message), "Enter a valid URL without a query.")

def test_allow_fragment(self):
validator = URLValidator2(allow_fragment=False)
validator("http://www.domain.tld/without/fragment/")
validator("http://www.domain.test/without/fragment/")
try:
validator("http://www.domain.tld/with/a/#fragment")
validator("http://www.domain.test/with/a/#fragment")
except ValidationError as err:
self.assertEqual(six.text_type(err.message), "Enter a valid URL without a fragment.")

def test_only_local_path1(self):
validator = URLValidator2(allow_schemes=None, allow_netloc=False)
validator("/path/?query#fragment")
try:
validator("http://domain.tld/path/?query#fragment")
validator("http://domain.test/path/?query#fragment")
except ValidationError as err:
self.assertEqual(six.text_type(err.message), "Please enter a local URL (without protocol/domain).")

Expand Down

0 comments on commit 5ffa1dc

Please sign in to comment.