@@ -228,6 +228,78 @@ def test_process_virtual_hosts_uses_next_network_when_first_ip_blank(self):
228228 backend = location .backends [0 ]
229229 assert backend .address == "10.0.0.12"
230230
231+ def test_https_virtual_host_rejects_certificate_hostname_longer_than_64_chars (self ):
232+ long_hostname = f"{ 'a' * 55 } .example.com"
233+ assert len (long_hostname ) > 64
234+ bt = BackendTarget (
235+ id = "long-https-id" ,
236+ name = "long-https-test" ,
237+ env = {"VIRTUAL_HOST" : f"https://{ long_hostname } " },
238+ network_settings = {"my-net" : {"NetworkID" : "my-net-id" , "IPAddress" : "10.0.0.12" }},
239+ )
240+
241+ config_data = process_virtual_hosts (bt , {"my-net-id" })
242+
243+ assert len (list (config_data .host_list ())) == 0
244+
245+ def test_http_virtual_host_allows_dns_valid_hostname_longer_than_64_chars (self ):
246+ long_hostname = f"{ 'a' * 55 } .example.com"
247+ assert len (long_hostname ) > 64
248+ bt = BackendTarget (
249+ id = "long-http-id" ,
250+ name = "long-http-test" ,
251+ env = {"VIRTUAL_HOST" : long_hostname },
252+ network_settings = {"my-net" : {"NetworkID" : "my-net-id" , "IPAddress" : "10.0.0.12" }},
253+ )
254+
255+ config_data = process_virtual_hosts (bt , {"my-net-id" })
256+
257+ hosts = list (config_data .host_list ())
258+ assert len (hosts ) == 1
259+ assert hosts [0 ].hostname == long_hostname
260+
261+ def test_https_virtual_host_allows_certificate_hostname_at_64_chars (self ):
262+ hostname = f"{ 'a' * 52 } .example.com"
263+ assert len (hostname ) == 64
264+ bt = BackendTarget (
265+ id = "max-https-id" ,
266+ name = "max-https-test" ,
267+ env = {"VIRTUAL_HOST" : f"https://{ hostname } " },
268+ network_settings = {"my-net" : {"NetworkID" : "my-net-id" , "IPAddress" : "10.0.0.12" }},
269+ )
270+
271+ config_data = process_virtual_hosts (bt , {"my-net-id" })
272+
273+ hosts = list (config_data .host_list ())
274+ assert len (hosts ) == 1
275+ assert hosts [0 ].hostname == hostname
276+
277+ def test_virtual_host_rejects_invalid_hostname (self ):
278+ bt = BackendTarget (
279+ id = "invalid-host-id" ,
280+ name = "invalid-host-test" ,
281+ env = {"VIRTUAL_HOST" : "bad_host.example.com" },
282+ network_settings = {"my-net" : {"NetworkID" : "my-net-id" , "IPAddress" : "10.0.0.12" }},
283+ )
284+
285+ config_data = process_virtual_hosts (bt , {"my-net-id" })
286+
287+ assert len (list (config_data .host_list ())) == 0
288+
289+ def test_virtual_host_allows_wildcard_hostname (self ):
290+ bt = BackendTarget (
291+ id = "wildcard-host-id" ,
292+ name = "wildcard-host-test" ,
293+ env = {"VIRTUAL_HOST" : "https://*.example.com" },
294+ network_settings = {"my-net" : {"NetworkID" : "my-net-id" , "IPAddress" : "10.0.0.12" }},
295+ )
296+
297+ config_data = process_virtual_hosts (bt , {"my-net-id" })
298+
299+ hosts = list (config_data .host_list ())
300+ assert len (hosts ) == 1
301+ assert hosts [0 ].hostname == "*.example.com"
302+
231303 def test_parse_host_entry_simple (self ):
232304 h , loc , c , extras = _parse_host_entry ("example.com" )
233305 assert h .hostname == "example.com"
0 commit comments