diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index e406dba8f..bb85ca607 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -45,7 +45,9 @@ EOF SSL_HOSTNAME=$(openssl x509 -in $SSL_INUSE/server.crt -noout -subject | tr '/' '\n' | grep CN= | cut -c4-) SSL_HOSTNAME=$(echo "$SSL_HOSTNAME" | sed 's|\.|\\.|g' | sed 's/\*/\.\*/g') - SSL_VHOSTS=$(egrep ^"$SSL_HOSTNAME"$ $VHOST_PATH) + + [[ -z "$(egrep ^"$SSL_HOSTNAME"$ $VHOST_PATH)" ]] && echo "$SSL_HOSTNAME" | sed 's/\\./\./g' >> $VHOST_PATH + SSL_VHOSTS=$(egrep ^"$SSL_HOSTNAME"$ $VHOST_PATH || exit 0) NONSSL_VHOSTS=$(egrep -v ^"$SSL_HOSTNAME"$ $VHOST_PATH || exit 0) while read line; do diff --git a/tests.mk b/tests.mk index 3c9b965b5..17c0afe0a 100644 --- a/tests.mk +++ b/tests.mk @@ -54,8 +54,9 @@ lint: # SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034 # SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086 # SC2143: Instead of [ -n $(foo | grep bar) ], use foo | grep -q bar - https://github.com/koalaman/shellcheck/wiki/SC2143 + # SC2001: See if you can use ${variable//search/replace} instead. - https://github.com/koalaman/shellcheck/wiki/SC2001 @echo linting... - @$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2034,SC2086,SC2143 + @$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2034,SC2086,SC2143,SC2001 unit-tests: @echo running unit tests... diff --git a/tests/unit/nginx-vhosts.bats b/tests/unit/nginx-vhosts.bats new file mode 100644 index 000000000..8eda6458c --- /dev/null +++ b/tests/unit/nginx-vhosts.bats @@ -0,0 +1,20 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + create_app + setup_test_tls + deploy_app +} + +teardown() { + destroy_app +} + +@test "nginx:build-config (with SSL CN mismatch)" { + run /bin/bash -c "dokku domains $TEST_APP | grep node-js-app.dokku.me" + echo "output: "$output + echo "status: "$status + assert_output "node-js-app.dokku.me" +} diff --git a/tests/unit/server_ssl.tar b/tests/unit/server_ssl.tar new file mode 100644 index 000000000..855a33210 Binary files /dev/null and b/tests/unit/server_ssl.tar differ diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 7a1d6719f..d671ae1b6 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -101,3 +101,10 @@ deploy_app() { git commit -m 'initial commit' git push target master || destroy_app } + +setup_test_tls() { + TLS="/home/dokku/$TEST_APP/tls" + mkdir -p $TLS + tar xf $BATS_TEST_DIRNAME/server_ssl.tar -C $TLS + sudo chown -R dokku:dokku $TLS +}