Skip to content

Commit cd6facb

Browse files
committed
test: cover IDN octet length and the #407 example
1 parent 13a7773 commit cd6facb

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎tests/test_domain.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ def _name_of_length(length: int):
136136
"a" * 63 + ".com",
137137
# a label may start with a digit (RFC 1123)
138138
"1host.example.com",
139+
# the limit is in octets of the encoded name, not characters: 189 characters
140+
# here, but 225 octets once IDNA-encoded
141+
".".join(["ü" * 30] * 6) + ".com",
139142
],
140143
)
141144
def test_returns_true_on_domain_within_rfc_length_limits(value: str):
@@ -152,6 +155,10 @@ def test_returns_true_on_domain_within_rfc_length_limits(value: str):
152155
".".join(["kld8MXQh6YalMqKRbfs895gMjW5T4p2EwToPoCSThPHHbXgmXc"] * 4)
153156
+ ".kld8MXQh6YalMqKRbfs895gMjW5T4p2EwToPoCSThPHHbXgmXcab",
154157
"a" * 64 + ".com",
158+
# fewer than 253 characters (220), but 262 octets once IDNA-encoded
159+
".".join(["ü" * 30] * 7) + ".com",
160+
# the example from #407 (261 characters)
161+
"www." + ".".join(["abcdefghijklmnop"] * 15) + ".fr",
155162
# a label must not start or end with a hyphen
156163
"-host.example.com",
157164
"host-.example.com",

‎tests/test_hostname.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def test_returns_failed_validation_on_invalid_hostname(value: str, rfc_1034: boo
8181
"a" * 63 + ".com",
8282
# a label may start with a digit (RFC 1123)
8383
"1host.example.com",
84+
# the limit is in octets of the encoded name, not characters
85+
".".join(["ü" * 30] * 6) + ".com",
8486
],
8587
)
8688
def test_returns_true_on_hostname_within_rfc_length_limits(value: str):
@@ -96,6 +98,8 @@ def test_returns_true_on_hostname_within_rfc_length_limits(value: str):
9698
+ ".kld8MXQh6YalMqKRbfs895gMjW5T4p2EwToPoCSThPHHbXgmXcab",
9799
".".join(["a" * 63, "a" * 63, "a" * 63, "a" * 62]),
98100
"a" * 64 + ".com",
101+
# fewer than 253 characters (220), but 262 octets once IDNA-encoded
102+
".".join(["ü" * 30] * 7) + ".com",
99103
# a label must not start or end with a hyphen, nor contain an underscore
100104
"-host.example.com",
101105
"host-.example.com",

0 commit comments

Comments
 (0)