Skip to content

Commit

Permalink
Fix testing
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Oct 14, 2023
1 parent 9228f25 commit ccc4fb8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env*
!.env.dist
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@ docker-test: test
test: run-test cleanup-test

run-test:
TEST_ADDR="${TEST_ADDR}" \
IMAGE_TAG="${IMAGE_TAG}" \
DMARC_SRG_UI_PASSWORD="public" \
# Random port maybe free ?
DMARC_SRG_HTTP_ADDRESS="8912" \
docker-compose -f docker-compose-latest.test.yml up --exit-code-from=sut --abort-on-container-exit
IMAGE_TAG="$(IMAGE_TAG)" \
docker compose -f docker-compose-latest.test.yml up --exit-code-from=sut --abort-on-container-exit

cleanup-test:
@echo "Stopping and removing the container"
TEST_ADDR="${TEST_ADDR}" \
IMAGE_TAG="${IMAGE_TAG}" \
DMARC_SRG_UI_PASSWORD="public" \
# Random port maybe free ?
DMARC_SRG_HTTP_ADDRESS="8912" \
docker-compose -f docker-compose-latest.test.yml down
IMAGE_TAG="$(IMAGE_TAG)" \
docker compose -f docker-compose-latest.test.yml down
7 changes: 3 additions & 4 deletions docker-compose-latest.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
container_name: test-bench
image: ${IMAGE_TAG}
environment:
TEST_ADDR: ${TEST_ADDR}
TEST_ADDR: dmarc-srg
volumes:
- ./test.sh:/test.sh:ro
entrypoint: ["/test.sh"]
Expand All @@ -16,6 +16,7 @@ services:
dmarc-srg:
image: ${IMAGE_TAG}
container_name: dmarc-srg
user: application
healthcheck:
test:
[
Expand All @@ -36,7 +37,5 @@ services:
IMAP_HOST: $DMARC_SRG_IMAP_HOST
IMAP_USER: $DMARC_SRG_IMAP_USER
IMAP_PASSWORD: $DMARC_SRG_IMAP_PASSWORD
UI_PASSWORD: $DMARC_SRG_UI_PASSWORD
ports:
- ${DMARC_SRG_HTTP_ADDRESS:-8082}:80
UI_PASSWORD: public
restart: on-failure:2
4 changes: 1 addition & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ checkUrl() {
set +e
if [ "${2:-}" = "form" ]; then
curl -# --cookie-jar /tmp/test.cookie-jar -b /tmp/test.cookie-jar --show-error --fail-with-body \
-s \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-L \
--data-raw "${3}" \
"$1"
else
curl -# --cookie-jar /tmp/test.cookie-jar -b /tmp/test.cookie-jar --show-error --fail-with-body \
-s \
${2:-} \
-H 'Content-Type: application/json' \
"$1"
Expand All @@ -40,7 +38,7 @@ checkUrl "http://${TEST_ADDR}/robots.txt" -I
checkUrl "http://${TEST_ADDR}/css/main.css" -I | grep -F "Cache-Control: max-age=86400"

checkUrl "http://${TEST_ADDR}/index.php" | grep -q -F "DMARC Reports"
checkUrl "http://${TEST_ADDR}/login.php" "form" "{"password":"public"}" | grep -q -F "Successfully logged into server."
checkUrl "http://${TEST_ADDR}/login.php" "form" '{"password":"public"}' | grep -q -F "Authentication succeeded"

if [ $DID_FAIL -gt 0 ]; then
echo "Some URLs failed"
Expand Down

0 comments on commit ccc4fb8

Please sign in to comment.