PromucFlow_constructor/deploy/docker/route-tests/entrypoint.sh
Shrikant Sharat Kandula e6ebfbaea1
fix: Remove Server header and allow all on port 80 (#29585)
Another attempt at #29550, which was reverted. Fallback is not happening
if cert provisioning fails _despite_ having the correct header. But with
the changes in this PR, since we'll listen on `:80`, fallback _will_
happen when cert provisioning fails due to incorrect domain
configuration.

We're also adding [Hurl](https://hurl.dev) based tests. They're not run
in any CI yet. That'll come in soon.
2023-12-18 09:44:31 +05:30

84 lines
2.2 KiB
Bash

#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
new-spec() {
echo "-----------" "$@" "-----------"
unset APPSMITH_CUSTOM_DOMAIN
mkdir -p /appsmith-stacks/ssl
find /appsmith-stacks/ssl -type f -delete
}
reload-caddy() {
sed -i 's/127.0.0.1:{args\[0]}/127.0.0.1:5050/' "$TMP/Caddyfile"
caddy fmt --overwrite "$TMP/Caddyfile"
caddy reload --config "$TMP/Caddyfile"
sleep 1
}
run-hurl() {
hurl --test \
--resolve local.com:80:127.0.0.1 \
--resolve custom-domain.com:80:127.0.0.1 \
--resolve custom-domain.com:443:127.0.0.1 \
"$@"
}
if [[ "${OPEN_SHELL-}" == 1 ]]; then
# Open shell for debugging after this script is done.
trap bash EXIT
fi
echo
echo "caddy version: $(caddy --version)"
echo "hurl version: $(hurl --version)"
echo "mkcert version: $(mkcert --version)"
echo
export TMP=/tmp/appsmith
export WWW_PATH="$TMP/www"
mkdir -p "$WWW_PATH"
echo -n 'index.html body' > "$WWW_PATH/index.html"
mkcert -install
# Start echo server
(
export XDG_DATA_HOME="$TMP/echo-data"
export XDG_CONFIG_HOME="$TMP/echo-conf"
mkdir -p "$XDG_DATA_HOME" "$XDG_CONFIG_HOME"
caddy start --config echo.caddyfile --adapter caddyfile >> "$TMP/echo-caddy.log" 2>&1
)
# Start Caddy for use with our config to test
echo localhost > "$TMP/Caddyfile"
caddy start --config "$TMP/Caddyfile" >> "$TMP/caddy.log" 2>&1
sleep 1
new-spec "Spec 1: With no custom domain"
node /caddy-reconfigure.mjs
reload-caddy
run-hurl common/*.hurl
new-spec "Spec 2: With a custom domain, cert obtained (because of internal CA)"
export APPSMITH_CUSTOM_DOMAIN=custom-domain.com
node /caddy-reconfigure.mjs
#sed -i '2i acme_ca https://acme-staging-v02.api.letsencrypt.org/directory' "$TMP/Caddyfile"
sed -i '/https:\/\/'"$APPSMITH_CUSTOM_DOMAIN"' {$/a tls internal' "$TMP/Caddyfile"
reload-caddy
run-hurl common/*.hurl common-https/*.hurl spec-2/*.hurl
new-spec "Spec 3: With a custom domain, certs given in ssl folder"
export APPSMITH_CUSTOM_DOMAIN=custom-domain.com
mkcert -cert-file "/appsmith-stacks/ssl/fullchain.pem" -key-file "/appsmith-stacks/ssl/privkey.pem" "$APPSMITH_CUSTOM_DOMAIN"
node /caddy-reconfigure.mjs
reload-caddy
run-hurl common/*.hurl spec-3/*.hurl