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):
14
14
15
15
16
16
def 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):
53
53
54
54
assert result == expected_string
55
55
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
+
56
63
def test_no_subdomain_to_replace (self ):
57
64
expected_string = 'example.com'
58
65
59
- result = get_hostname_for_ssl_match ('example.com' )
66
+ result = get_hostname_for_ssl_match (expected_string )
60
67
61
68
assert result == expected_string
62
69
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