Commit 484e08a2a09aa12cec11e5adcf7512d585a8b9ae
Committed by
Sergio Oliveira
1 parent
387b4854
Exists in
master
and in
90 other branches
Add DNS tests and documentation generator
Showing
4 changed files
with
116 additions
and
0 deletions
Show diff stats
config/production/config.yaml
... | ... | @@ -3,6 +3,7 @@ admins: |
3 | 3 | - Paulo Meirelles |
4 | 4 | - paulo@softwarelivre.org |
5 | 5 | external_hostname: beta.softwarepublico.gov.br |
6 | +external_ip: 164.41.9.49 | |
6 | 7 | site_url: https://beta.softwarepublico.gov.br |
7 | 8 | colab_from_address: '"Portal do Software Publico" <noreply@beta.softwarepublico.gov.br>' |
8 | 9 | server_email: '"Portal do Software Publico" <noreply@beta.softwarepublico.gov.br>' |
... | ... | @@ -10,5 +11,6 @@ email_subject_prefix: '[spb]' |
10 | 11 | lists_hostname: listas.softwarepublico.gov.br |
11 | 12 | lists_admin: paulo@softwarelivre.org |
12 | 13 | relay_hostname: relay.softwarepublico.gov.br |
14 | +relay_ip: 164.41.9.48 | |
13 | 15 | alt_ssh_port: 55555 |
14 | 16 | from_address: noreply@softwarepublico.gov.br | ... | ... |
... | ... | @@ -0,0 +1,107 @@ |
1 | +. $(dirname $0)/test_helper.sh | |
2 | + | |
3 | +if [ "$SPB_ENV" = local ]; then | |
4 | + echo "_No DNS for local environment_" | |
5 | + exit | |
6 | +fi | |
7 | + | |
8 | + | |
9 | +export LANG=C | |
10 | + | |
11 | +check_hostname() { | |
12 | + local host="$1" | |
13 | + local ip="$2" | |
14 | + local results="$(host -t A $host)" | |
15 | + local expected="$host has address $ip" | |
16 | + assertEquals "$host must resolve to $ip" "$results" "$expected" | |
17 | +} | |
18 | + | |
19 | +check_mx() { | |
20 | + local host="$1" | |
21 | + local mx="$2" | |
22 | + local results="$(host -t MX $host)" | |
23 | + local expected="$host mail is handled by 0 ${mx}." | |
24 | + assertEquals "$host MX must be $mx" "$results" "$expected" | |
25 | +} | |
26 | + | |
27 | +check_reverse_dns() { | |
28 | + local ip="$1" | |
29 | + local hostname="$2" | |
30 | + local results="$(host $ip)" | |
31 | + local expected=".*in-addr.arpa domain name pointer $hostname" | |
32 | + assertTrue "Reverse DNS of $ip must be $hostname (found: $results)" "expr match \"$results\$\" \"$expected\$\"" | |
33 | +} | |
34 | + | |
35 | +test_dns_web() { | |
36 | + check_hostname "$config_external_hostname" "$config_external_ip" | |
37 | +} | |
38 | + | |
39 | +test_mx() { | |
40 | + check_mx "$config_external_hostname" "${config_relay_hostname}" | |
41 | +} | |
42 | + | |
43 | +test_dns_lists() { | |
44 | + check_hostname "$config_lists_hostname" "$config_external_ip" | |
45 | +} | |
46 | + | |
47 | +test_mx_lists() { | |
48 | + check_mx "$config_lists_hostname" "$config_relay_hostname" | |
49 | +} | |
50 | + | |
51 | +test_dns_relay() { | |
52 | + check_hostname "$config_relay_hostname" "$config_relay_ip" | |
53 | +} | |
54 | + | |
55 | +test_reverse_dns_web() { | |
56 | + check_reverse_dns "$config_external_ip" "$config_external_hostname" | |
57 | +} | |
58 | + | |
59 | +test_reverse_dns_relay() { | |
60 | + check_reverse_dns "$config_relay_ip" "$config_relay_hostname" | |
61 | +} | |
62 | + | |
63 | +# TODO test_spf_external_relay | |
64 | + | |
65 | +if [ "$1" = '--doc' ]; then | |
66 | + check_hostname() { | |
67 | + echo "| ❏ A | $1 | $2 |" | |
68 | + } | |
69 | + check_mx() { | |
70 | + echo "| ❏ MX | $1 | ${2}. |" | |
71 | + } | |
72 | + check_reverse_dns() { | |
73 | + echo "| ❏ PTR | $1 | ${2}. |" | |
74 | + } | |
75 | + header() { | |
76 | + echo "## $1" | |
77 | + echo | |
78 | + echo '| Tipo | Entrada | Aponta para |' | |
79 | + echo '|:-----|:------|:----------|' | |
80 | + } | |
81 | + footer() { | |
82 | + echo | |
83 | + } | |
84 | + ( | |
85 | + echo "# Entradas de DNS necessárias" | |
86 | + header 'DNS(A)' | |
87 | + test_dns_web | |
88 | + test_dns_lists | |
89 | + test_dns_relay | |
90 | + footer | |
91 | + | |
92 | + header 'MX' | |
93 | + test_mx | |
94 | + test_mx_lists | |
95 | + footer | |
96 | + | |
97 | + header 'DNS reverso' | |
98 | + test_reverse_dns_web | |
99 | + test_reverse_dns_relay | |
100 | + footer | |
101 | + | |
102 | + # FIXME test_spf_external_relay | |
103 | + | |
104 | + ) | |
105 | +else | |
106 | + . shunit2 | |
107 | +fi | ... | ... |