FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
validators/tests/test_hostname.py at master · python-validators/validators · GitHub
python-validators
validators
Repository navigation
Code
Issues
6
(6)
Pull requests
33
(33)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
validators
/
tests
/
test_hostname.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (61 loc) · 2.47 KB
Breadcrumbs
validators
/
tests
/
test_hostname.py
Copy path
File metadata and controls
67 lines (61 loc) · 2.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Test Hostname."""
# external
import
pytest
# local
from
validators
import
ValidationError
,
hostname
@
pytest
.
mark
.
parametrize
(
(
"value"
,
"rfc_1034"
,
"rfc_2782"
),
[
# simple hostname w/ optional ports
(
"ubuntu-pc:443"
,
False
,
False
),
(
"this-pc"
,
False
,
False
),
(
"lab-01a-notebook:404"
,
False
,
False
),
(
"4-oh-4"
,
False
,
False
),
# hostname w/ optional ports
(
"example.com:4444"
,
False
,
False
),
(
"kräuter.com."
,
True
,
False
),
(
"xn----gtbspbbmkef.xn--p1ai:65535"
,
False
,
False
),
(
"_example.com"
,
False
,
True
),
# ipv4 addr w/ optional ports
(
"123.123.123.123:9090"
,
False
,
False
),
(
"127.0.0.1:43512"
,
False
,
False
),
(
"123.5.77.88:31000"
,
False
,
False
),
(
"12.12.12.12:5353"
,
False
,
False
),
# ipv6 addr w/ optional ports
(
"[::1]:22"
,
False
,
False
),
(
"[dead:beef:0:0:0:0000:42:1]:5731"
,
False
,
False
),
(
"[0:0:0:0:0:ffff:1.2.3.4]:80"
,
False
,
False
),
(
"[0:a:b:c:d:e:f::]:53"
,
False
,
False
),
],
)
def
test_returns_true_on_valid_hostname
(
value
:
str
,
rfc_1034
:
bool
,
rfc_2782
:
bool
):
"""Test returns true on valid hostname."""
assert
hostname
(
value
,
rfc_1034
=
rfc_1034
,
rfc_2782
=
rfc_2782
)
@
pytest
.
mark
.
parametrize
(
(
"value"
,
"rfc_1034"
,
"rfc_2782"
),
[
# bad (simple hostname w/ optional ports)
(
"ubuntu-pc:443080"
,
False
,
False
),
(
"this-pc-is-sh*t"
,
False
,
False
),
(
"lab-01a-note._com_.com:404"
,
False
,
False
),
(
"4-oh-4:@.com"
,
False
,
False
),
# bad (hostname w/ optional ports)
(
"example.com:-4444"
,
False
,
False
),
(
"xn----gtbspbbmkef.xn--p1ai:65538"
,
False
,
False
),
(
"_example.com:0"
,
False
,
True
),
(
"kräuter.com.:81_00"
,
True
,
False
),
# bad (ipv4 addr w/ optional ports)
(
"123.123.123.123:99999"
,
False
,
False
),
(
"127.0.0.1:"
,
False
,
False
),
(
"123.5.-12.88:8080"
,
False
,
False
),
(
"12.12.12.12:$#"
,
False
,
False
),
# bad (ipv6 addr w/ optional ports)
(
"[::1]:[22]"
,
False
,
False
),
(
"[dead:beef:0:-:0:-:42:1]:5731"
,
False
,
False
),
(
"[0:0:0:0:0:ffff:1.2.3.4]:-65538"
,
False
,
False
),
(
"[0:&:b:c:@:e:f:::9999"
,
False
,
False
),
],
)
def
test_returns_failed_validation_on_invalid_hostname
(
value
:
str
,
rfc_1034
:
bool
,
rfc_2782
:
bool
):
"""Test returns failed validation on invalid hostname."""
assert
isinstance
(
hostname
(
value
,
rfc_1034
=
rfc_1034
,
rfc_2782
=
rfc_2782
),
ValidationError
)
Back
|
FazBrowse Home
|
New Git URL