-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathtest_trailing_dot.py
More file actions
30 lines (22 loc) · 1.12 KB
/
test_trailing_dot.py
File metadata and controls
30 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Tests for trailing-dot FQDN hostname normalisation (issue #1063)."""
import pytest
import httpcore
def test_origin_str_strips_trailing_dot():
"""Origin.__str__ must strip the trailing dot from FQDNs.
'myhost.internal.' is a valid FQDN but TLS certificates use
'myhost.internal' (without the dot). Passing the raw hostname
to ssl_wrap_socket would cause CERTIFICATE_VERIFY_FAILED.
"""
origin = httpcore.Origin(b"https", b"myhost.internal.", 443)
assert str(origin) == "https://myhost.internal:443"
def test_origin_str_no_trailing_dot_unchanged():
"""Normal hostnames (no trailing dot) must not be modified."""
origin = httpcore.Origin(b"https", b"example.com", 443)
assert str(origin) == "https://example.com:443"
def test_url_host_strips_trailing_dot():
"""URL.host used for SNI should not carry the trailing dot."""
url = httpcore.URL("https://myhost.internal.:8443/")
assert url.host == b"myhost.internal." # raw host preserved
# but str(origin) strips it for TLS
origin = httpcore.Origin(b"https", url.host, url.port)
assert str(origin) == "https://myhost.internal:8443"