Skip to content

Commit

Permalink
Update 418 pages with correct info and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Swann committed Sep 8, 2021
1 parent 8af6c87 commit 0eae499
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
/tmp/*
*.swp
client-ca
upstream-*
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ In order to run this container you'll need docker installed.
* [OS X](https://docs.docker.com/mac/started/)
* [Linux](https://docs.docker.com/linux/started/)

## Creating builds
When an update has been deployed to master, tag and push the master branch to kick off a Drone build:
```
git tag <next_version>
git push --tags
```

## Testing Locally
Authentic GEOIP credentials are needed when curling MaxMind Urls otherwise a 401 is returned. Therefore if no `GEOIP_LICENSE_KEY` secret/env var is set when running `./ci-build.sh`, a `LOCAL_TEST` variable is set to true to ensure the relevant urls are not called. This means not having to start up a Drone build every single time you want to test something and your local machine reuses any Docker cache available to it making the test/retry process much faster.

*MAC USERS*
You will need to install wget so that this can run in the `./ci-build.sh` script:
```
brew install wget
```

## Usage

### Environment Variables
Expand Down
21 changes: 18 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
set -eu
set -o pipefail

if [ -z "$GEOIP_LICENSE_KEY" ]; then
LOCAL_TEST=true
else
LOCAL_TEST=false
fi

GEOIP_ACCOUNT_ID="${GEOIP_ACCOUNT_ID:-123456}"
GEOIP_LICENSE_KEY="${GEOIP_LICENSE_KEY:-xxxxxx}"
GEOIP_CITY_URL="https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=${GEOIP_LICENSE_KEY}&suffix=tar.gz"
Expand Down Expand Up @@ -52,15 +58,24 @@ mkdir -p ${MAXMIND_PATH}
./configure
make check install
echo "/usr/local/lib" >> /etc/ld.so.conf.d/libmaxminddb.conf
curl -fSL ${GEOIP_COUNTRY_URL} | tar -xz > ${MAXMIND_PATH}/GeoLite2-Country.mmdb
curl -fSL ${GEOIP_CITY_URL} | tar -xz > ${MAXMIND_PATH}/GeoLite2-City.mmdb

# Only run if not testing locally
if [ "$LOCAL_TEST" = false ]; then
curl -fSL ${GEOIP_COUNTRY_URL} | tar -xz > ${MAXMIND_PATH}/GeoLite2-Country.mmdb
curl -fSL ${GEOIP_CITY_URL} | tar -xz > ${MAXMIND_PATH}/GeoLite2-City.mmdb
fi

chown -R 1000:1000 ${MAXMIND_PATH}
popd

pushd geoipupdate
sed -i 's/YOUR_ACCOUNT_ID_HERE/'"${GEOIP_ACCOUNT_ID}"'/g' GeoIP.conf
sed -i 's/YOUR_LICENSE_KEY_HERE/'"${GEOIP_LICENSE_KEY}"'/g' GeoIP.conf
./geoipupdate -f GeoIP.conf -d ${MAXMIND_PATH}

# Only run if not testing locally
if [ "$LOCAL_TEST" = false ]; then
./geoipupdate -f GeoIP.conf -d ${MAXMIND_PATH}
fi
popd

echo "Checking libmaxminddb module"
Expand Down
40 changes: 40 additions & 0 deletions ci-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,46 @@ else
echo "Testing VERBOSE_ERROR_PAGES works..."
fi

start_test "Test VERBOSE_ERROR_PAGES is not set displays default message info" "${STD_CMD} \
-e \"PROXY_SERVICE_HOST=http://${MOCKSERVER}\" \
-e \"PROXY_SERVICE_PORT=${MOCKSERVER_PORT}\" \
-e \"DNSMASK=TRUE\" \
-e \"ENABLE_UUID_PARAM=FALSE\" \
--link \"${MOCKSERVER}:${MOCKSERVER}\" "
if curl -k https://${DOCKER_HOST_NAME}:${PORT}/\?\"==\` | grep "Something went wrong." ; then
echo "Testing VERBOSE_ERROR_PAGES works..."
else
echo "Testing VERBOSE_ERROR_PAGES failed..."
exit 1
fi

start_test "Test FEEDBACK_EMAIL is set, displays contact message info" "${STD_CMD} \
-e \"PROXY_SERVICE_HOST=http://${MOCKSERVER}\" \
-e \"PROXY_SERVICE_PORT=${MOCKSERVER_PORT}\" \
-e \"DNSMASK=TRUE\" \
-e \"ENABLE_UUID_PARAM=FALSE\" \
-e \"[email protected]\" \
--link \"${MOCKSERVER}:${MOCKSERVER}\" "
if curl -k https://${DOCKER_HOST_NAME}:${PORT}/\?\"==\` | grep "[email protected]" ; then
echo "Testing VERBOSE_ERROR_PAGES works..."
else
echo "Testing VERBOSE_ERROR_PAGES failed..."
exit 1
fi

start_test "Test FEEDBACK_EMAIL is not set, does not display email message info" "${STD_CMD} \
-e \"PROXY_SERVICE_HOST=http://${MOCKSERVER}\" \
-e \"PROXY_SERVICE_PORT=${MOCKSERVER_PORT}\" \
-e \"DNSMASK=TRUE\" \
-e \"ENABLE_UUID_PARAM=FALSE\" \
--link \"${MOCKSERVER}:${MOCKSERVER}\" "
if curl -k https://${DOCKER_HOST_NAME}:${PORT}/\?\"==\` | grep "please contact us on" ; then
echo "Testing VERBOSE_ERROR_PAGES failed..."
exit 1
else
echo "Testing VERBOSE_ERROR_PAGES works..."
fi

echo "_________________________________"
echo "We got here, ALL tests successful"
clean_up
9 changes: 5 additions & 4 deletions html/418-request-denied.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
TIME: <!--#config timefmt="%Y-%m-%dT%H:%M:%S %Z" --><!--#echo var="date_local" -->
</code>
<!--#else -->
<!--#set var="title" value="Something went wrong." -->
<header><h1>Something went wrong.</h1></header>
<p>Text entered appears suspicious. This is likely due to unusual repeat or individual special characters, i.e. @@ or && or |. Please delete any unnecessary special characters and try again.</p>
<!--#if expr="${FEEDBACK_EMAIL}" -->
<p>If this problem persists, please contact us on <!--#echo var="${FEEDBACK_EMAIL}" --> so we can remedy any issues and improve our service.</p>
<!--#endif -->
<!--#endif -->

<!--#if expr="${FEEDBACK_EMAIL}" -->
<p>If this problem persists, please contact us on <!--#echo var="FEEDBACK_EMAIL" --> so we can remedy any issues and improve our service.</p>
<!--#endif -->
1 change: 1 addition & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ http {
# Debug information now available in headers ($http_x_naxsi_sig etc.)
# Return a 418 (Teapot) status
set_by_lua_file $verbose_error_pages lua/get_env.lua 'VERBOSE_ERROR_PAGES';
set_by_lua_file $feedback_email lua/get_env.lua 'FEEDBACK_EMAIL';
error_page 418 /nginx-proxy/418-request-denied.shtml;
return 418;
}
Expand Down

0 comments on commit 0eae499

Please sign in to comment.