dns_test.sh
2.85 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
. $(dirname $0)/test_helper.sh
if [ "$SPB_ENV" = local -o "$SPB_ENV" = lxc ]; 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' 'include:$expected\$'"
}
check_spf() {
domain="$1"
spf_domain="$2"
local results="$(host -t TXT "$domain")"
assertTrue "TXT entry for $domain must have include:$spf_domain (found: $results)" "expr match '$results' 'include:$spf_domain'"
}
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"
}
if [ -n "$config_external_outgoing_mail_domain" ]; then
test_spf_domain() {
check_spf "$config_external_hostname" "$config_external_outgoing_mail_domain"
}
test_spf_lists() {
check_spf "$config_lists_hostname" "$config_external_outgoing_mail_domain"
}
fi
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}."
}
check_spf() {
echo " * - TXT (SPF: \"v=spf1 ...\")"
echo " - $1 "
echo " - include:${2} "
}
header() {
local aponta="${2:-Aponta para}"
echo '.. list-table::'
echo ' :header-rows: 1'
echo
echo ' * - Tipo'
echo ' - Entrada'
echo " - $aponta"
}
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
header 'SPF' 'Deve conter'
test_spf_domain
test_spf_lists
footer
)
else
. shunit2
fi