-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hosts_validation.py
More file actions
89 lines (67 loc) · 2.36 KB
/
test_hosts_validation.py
File metadata and controls
89 lines (67 loc) · 2.36 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
Lost: a hosts file manager for Linux
Copyright (C) 2025-2026 Butterroach
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from validateHosts import validateHostsFile
import requests
def test_valid_hosts():
HOSTS = """
# comment
#comment
#coment
127.0.0.1 localhost
::1 localhost
192.168.1.10 example.com
192.168.1.11 test.local
10.0.0.2 example.org # comment
127.0.0.1 mylocal myapp
192.168.100.100 dev.mywebsite.com
192.168.100.101 staging.mywebsite.com
192.168.0.2 www.example.com www.example.net api.example.com
2001:0db8:85a3:0000:0000:8a2e:0370:7334 ipv6example.com
0.0.0.0 blockedwebsite.com
127.0.0.1 anotherexample.com
"""
assert validateHostsFile(HOSTS)[0]
def test_invalid_ipv4_hosts():
HOSTS = """
256.255.255.255 localhost
::1 localhost
"""
assert not validateHostsFile(HOSTS)[0]
def test_invalid_ipv6_hosts():
HOSTS = """
127.0.0.1 localhost
:1 localhost
"""
assert not validateHostsFile(HOSTS)[0]
def test_invalid_syntax():
HOSTS = """
google.com 0.0.0.0
"""
assert not validateHostsFile(HOSTS)[0]
def test_empty_hosts():
HOSTS = ""
assert validateHostsFile(HOSTS)[0] # this should be valid!
def test_hagezi_ultimate_uncompressed_hosts():
# time for a real test!
HOSTS = requests.get(
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/hosts/ultimate.txt"
).text # this hosts file has over 700,000 entries 😵
assert validateHostsFile(HOSTS)[0] # should be valid
def test_hagezi_ultimate_compressed_hosts():
# another test just in case
HOSTS = requests.get(
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/hosts/ultimate-compressed.txt"
).text
assert validateHostsFile(HOSTS)[0] # should also be valid