Commit 484e08a2a09aa12cec11e5adcf7512d585a8b9ae

Authored by Antonio Terceiro
Committed by Sergio Oliveira
1 parent 387b4854
Exists in master and in 90 other branches 3.x, add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup, backup_not_prod, cdtc_configuration, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev-lappis, dev_env_minimal, disable_email_dev, docs, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, performance, prezento, r3, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_backup_emails, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, stable-devel, support_docs, syslog, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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  
... ...