diff --git a/config/production/config.yaml b/config/production/config.yaml index dbf8547..4922af1 100644 --- a/config/production/config.yaml +++ b/config/production/config.yaml @@ -3,6 +3,7 @@ admins: - Paulo Meirelles - paulo@softwarelivre.org external_hostname: beta.softwarepublico.gov.br +external_ip: 164.41.9.49 site_url: https://beta.softwarepublico.gov.br colab_from_address: '"Portal do Software Publico" ' server_email: '"Portal do Software Publico" ' @@ -10,5 +11,6 @@ email_subject_prefix: '[spb]' lists_hostname: listas.softwarepublico.gov.br lists_admin: paulo@softwarelivre.org relay_hostname: relay.softwarepublico.gov.br +relay_ip: 164.41.9.48 alt_ssh_port: 55555 from_address: noreply@softwarepublico.gov.br diff --git a/test/config_helper.sh b/test/config_helper.sh new file mode 100644 index 0000000..c2ad0af --- /dev/null +++ b/test/config_helper.sh @@ -0,0 +1,6 @@ +# exports all configuration variables into the environment with a config_ +# prefix, e.g. +# +# external_hostname → $config_external_hostname + +eval $(sed -e '/^\S*:\s*\S\+/!d; s/^/config_/; s/:\s*/=/' ${ROOTDIR:-.}/config/${SPB_ENV:-local}/config.yaml) diff --git a/test/dns_test.sh b/test/dns_test.sh new file mode 100644 index 0000000..ef6a2b7 --- /dev/null +++ b/test/dns_test.sh @@ -0,0 +1,107 @@ +. $(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 | $1 | $2 |" + } + check_mx() { + echo "| ❏ MX | $1 | ${2}. |" + } + check_reverse_dns() { + echo "| ❏ PTR | $1 | ${2}. |" + } + header() { + echo "## $1" + echo + echo '| Tipo | Entrada | Aponta para |' + echo '|:-----|:------|:----------|' + } + footer() { + echo + } + ( + echo "# Entradas de DNS necessárias" + 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 diff --git a/test/test_helper.sh b/test/test_helper.sh index cdbe640..fee9275 100644 --- a/test/test_helper.sh +++ b/test/test_helper.sh @@ -19,4 +19,5 @@ load_shunit2() { } . $(dirname $0)/ip_helper.sh +. $(dirname $0)/config_helper.sh -- libgit2 0.21.2