-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathtest_dns.py
101 lines (75 loc) · 2.99 KB
/
test_dns.py
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
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
#
# Copyright (c) 2024 YunoHost Contributors
#
# This file is part of YunoHost (see https://yunohost.org)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import pytest
from moulinette.utils.filesystem import read_toml
from yunohost.dns import (
DOMAIN_REGISTRAR_LIST_PATH,
_build_dns_conf,
_get_dns_zone_for_domain,
_get_registrar_config_section,
)
from yunohost.domain import domain_add, domain_remove
def setup_function(function):
clean()
def teardown_function(function):
clean()
def clean():
pass
# DNS utils testing
def test_get_dns_zone_from_domain_existing():
assert _get_dns_zone_for_domain("yunohost.org") == "yunohost.org"
assert _get_dns_zone_for_domain("donate.yunohost.org") == "yunohost.org"
assert _get_dns_zone_for_domain("fr.wikipedia.org") == "wikipedia.org"
assert _get_dns_zone_for_domain("www.fr.wikipedia.org") == "wikipedia.org"
assert (
_get_dns_zone_for_domain("non-existing-domain.yunohost.org") == "yunohost.org"
)
assert _get_dns_zone_for_domain("yolo.nohost.me") == "yolo.nohost.me"
assert _get_dns_zone_for_domain("foo.yolo.nohost.me") == "yolo.nohost.me"
assert _get_dns_zone_for_domain("bar.foo.yolo.nohost.me") == "yolo.nohost.me"
assert _get_dns_zone_for_domain("yolo.test") == "yolo.test"
assert _get_dns_zone_for_domain("foo.yolo.test") == "yolo.test"
assert _get_dns_zone_for_domain("yolo.tld") == "yolo.tld"
assert _get_dns_zone_for_domain("foo.yolo.tld") == "yolo.tld"
# Domain registrar testing
def test_registrar_list_integrity():
assert read_toml(DOMAIN_REGISTRAR_LIST_PATH)
def test_magic_guess_registrar_weird_domain():
assert _get_registrar_config_section("yolo.tld")["registrar"]["default"] is None
def test_magic_guess_registrar_ovh():
assert (
_get_registrar_config_section("yolo.yunohost.org")["registrar"]["default"]
== "ovh"
)
def test_magic_guess_registrar_yunodyndns():
assert (
_get_registrar_config_section("yolo.nohost.me")["registrar"]["default"]
== "yunohost"
)
@pytest.fixture
def example_domain():
domain_add("example.tld")
yield "example.tld"
domain_remove("example.tld")
def test_domain_dns_suggest(example_domain):
assert _build_dns_conf(example_domain)
# def domain_dns_push(domain, dry_run):
# import yunohost.dns
# return yunohost.dns.domain_registrar_push(domain, dry_run)