dns_test.sh
2.18 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
. $(dirname $0)/test_helper.sh
if [ "$SPB_ENV" = local ]; then
echo "_No DNS for local environment_"
exit
fi
export LANG=C
check_hostname() {
local host="$1"
local ip="$2"
local results="$(host -t A $host)"
local expected="$host has address $ip"
assertEquals "$host must resolve to $ip" "$results" "$expected"
}
check_mx() {
local host="$1"
local mx="$2"
local results="$(host -t MX $host)"
local expected="$host mail is handled by 0 ${mx}."
assertEquals "$host MX must be $mx" "$results" "$expected"
}
check_reverse_dns() {
local ip="$1"
local hostname="$2"
local results="$(host $ip)"
local expected=".*in-addr.arpa domain name pointer ${hostname}."
assertTrue "Reverse DNS of $ip must be $hostname (found: $results)" "expr match '$results' '$expected\$'"
}
test_dns_web() {
check_hostname "$config_external_hostname" "$config_external_ip"
}
test_mx() {
check_mx "$config_external_hostname" "${config_relay_hostname}"
}
test_dns_lists() {
check_hostname "$config_lists_hostname" "$config_external_ip"
}
test_mx_lists() {
check_mx "$config_lists_hostname" "$config_relay_hostname"
}
test_dns_relay() {
check_hostname "$config_relay_hostname" "$config_relay_ip"
}
test_reverse_dns_web() {
check_reverse_dns "$config_external_ip" "$config_external_hostname"
}
test_reverse_dns_relay() {
check_reverse_dns "$config_relay_ip" "$config_relay_hostname"
}
# TODO test_spf_external_relay
if [ "$1" = '--doc' ]; then
check_hostname() {
echo ' * - A'
echo " - $1"
echo " - ${2}"
}
check_mx() {
echo ' * - MX'
echo " - $1"
echo " - ${2}."
}
check_reverse_dns() {
echo ' * - PTR'
echo " - $1"
echo " - ${2}."
}
header() {
echo '.. list-table::'
echo ' :header-rows: 1'
echo
echo ' * - Tipo'
echo ' - Entrada'
echo ' - Aponta para'
}
footer() {
echo
}
(
header 'DNS(A)'
test_dns_web
test_dns_lists
test_dns_relay
footer
header 'MX'
test_mx
test_mx_lists
footer
header 'DNS reverso'
test_reverse_dns_web
test_reverse_dns_relay
footer
# FIXME test_spf_external_relay
)
else
. shunit2
fi