Commit 484e08a2a09aa12cec11e5adcf7512d585a8b9ae

Authored by Antonio Terceiro
Committed by Sergio Oliveira
1 parent 387b4854

Add DNS tests and documentation generator

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: &#39;[spb]&#39;
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
... ...
test/config_helper.sh 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +# exports all configuration variables into the environment with a config_
  2 +# prefix, e.g.
  3 +#
  4 +# external_hostname → $config_external_hostname
  5 +
  6 +eval $(sed -e '/^\S*:\s*\S\+/!d; s/^/config_/; s/:\s*/=/' ${ROOTDIR:-.}/config/${SPB_ENV:-local}/config.yaml)
... ...
test/dns_test.sh 0 → 100644
... ... @@ -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
... ...
test/test_helper.sh
... ... @@ -19,4 +19,5 @@ load_shunit2() {
19 19 }
20 20  
21 21 . $(dirname $0)/ip_helper.sh
  22 +. $(dirname $0)/config_helper.sh
22 23  
... ...