@@ -70,3 +70,38 @@ def test_returns_true_on_valid_hostname(value: str, rfc_1034: bool, rfc_2782: bo
7070def test_returns_failed_validation_on_invalid_hostname (value : str , rfc_1034 : bool , rfc_2782 : bool ):
7171 """Test returns failed validation on invalid hostname."""
7272 assert isinstance (hostname (value , rfc_1034 = rfc_1034 , rfc_2782 = rfc_2782 ), ValidationError )
73+
74+
75+ @pytest .mark .parametrize (
76+ "value" ,
77+ [
78+ # total length: at most 253 characters (RFC 1035)
79+ "." .join (["a" * 63 , "a" * 63 , "a" * 63 , "a" * 61 ]),
80+ # label length: at most 63 characters (RFC 1035)
81+ "a" * 63 + ".com" ,
82+ # a label may start with a digit (RFC 1123)
83+ "1host.example.com" ,
84+ ],
85+ )
86+ def test_returns_true_on_hostname_within_rfc_length_limits (value : str ):
87+ """Test returns true on hostname within RFC length limits."""
88+ assert hostname (value )
89+
90+
91+ @pytest .mark .parametrize (
92+ "value" ,
93+ [
94+ # many short, dot-separated labels that exceed 253 characters; see #413
95+ "." .join (["kld8MXQh6YalMqKRbfs895gMjW5T4p2EwToPoCSThPHHbXgmXc" ] * 4 )
96+ + ".kld8MXQh6YalMqKRbfs895gMjW5T4p2EwToPoCSThPHHbXgmXcab" ,
97+ "." .join (["a" * 63 , "a" * 63 , "a" * 63 , "a" * 62 ]),
98+ "a" * 64 + ".com" ,
99+ # a label must not start or end with a hyphen, nor contain an underscore
100+ "-host.example.com" ,
101+ "host-.example.com" ,
102+ "ho_st.example.com" ,
103+ ],
104+ )
105+ def test_returns_failed_validation_on_hostname_beyond_rfc_limits (value : str ):
106+ """Test returns failed validation on hostname beyond RFC limits."""
107+ assert isinstance (hostname (value ), ValidationError )
0 commit comments