File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def chain_to_bytes(*strings):
1414
1515
1616def get_hostname_for_ssl_match (hostname ):
17- match = re .match (r'^((?P<subdomain>[^\.]+)\.)?(?P<domain>[^\./]+\.[^/]+)/?.*$' , hostname )
18- domain = match .group ('domain' )
19- return '*.{domain}' .format (domain = domain ) if match .group ('subdomain' ) else domain
17+ parts = hostname .split ('.' )
18+
19+ if len (parts ) < 3 :
20+ return hostname
21+
22+ parts [0 ] = '*'
23+ return '.' .join (parts )
Original file line number Diff line number Diff line change @@ -53,13 +53,23 @@ def test_subdomain_replaced_to_star(self):
5353
5454 assert result == expected_string
5555
56+ def test_subdomain_replaced_to_star_special_tld (self ):
57+ expected_string = '*.example.co.uk'
58+
59+ result = get_hostname_for_ssl_match ('test.example.co.uk' )
60+
61+ assert result == expected_string
62+
5663 def test_no_subdomain_to_replace (self ):
5764 expected_string = 'example.com'
5865
59- result = get_hostname_for_ssl_match ('example.com' )
66+ result = get_hostname_for_ssl_match (expected_string )
6067
6168 assert result == expected_string
6269
63- def test_no_match (self ):
64- with pytest .raises (AttributeError ) as exc :
65- get_hostname_for_ssl_match ('' )
70+ def test_no_tld (self ):
71+ expected_string = 'localhost'
72+
73+ result = get_hostname_for_ssl_match (expected_string )
74+
75+ assert result == expected_string
You can’t perform that action at this time.
0 commit comments