Skip to content

Commit

Permalink
Run Integration Tests via GHA (#84)
Browse files Browse the repository at this point in the history
* Create integration-tests.yml

* setting TERM

* adding debugging

* fix order of parameters passed to docker-compose

* checking docker and docker compose version

* separating build and test to make output a little cleaner

* fixing errors to bubble up; moving to docker compose instead of docker-compose

* Removing debug

* adding badge
  • Loading branch information
jonmchan committed Apr 29, 2023
1 parent 18eaf22 commit b0a4ff1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Integration Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build test harness
run: make buildtest

- name: Run tests
run: make test
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export DOCKER_IMAGE_NAME ?= $(DOCKER_IMAGE):$(DOCKER_TAG)
export DOCKER_BUILD_FLAGS =
COPYRIGHT_SOFTWARE_DESCRIPTION := A secure Bastion host implemented as Docker Container running Alpine Linux with Google Authenticator & DUO MFA support

.PHONY: test
.PHONY: test buildtest

include $(shell curl --silent -O "https://raw.githubusercontent.com/cloudposse/build-harness/master/templates/Makefile.build-harness"; echo Makefile.build-harness)

Expand All @@ -29,5 +29,9 @@ run: reset
-e SLACK_ENABLED=true \
$(DOCKER_IMAGE_NAME)

buildtest:
cd test > /dev/null; ./build.sh


test:
pushd test > /dev/null; ./test.sh; popd > /dev/null
cd test > /dev/null; ./test.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!-- markdownlint-disable -->
# bastion [![Latest Release](https://img.shields.io/github/release/cloudposse/bastion.svg)](https://github.com/cloudposse/bastion/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
# bastion [![Latest Release](https://img.shields.io/github/release/cloudposse/bastion.svg)](https://github.com/cloudposse/bastion/releases/latest) [![Build & Test Status](https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml/badge.svg)](https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
<!-- markdownlint-restore -->

[![README Header][readme_header_img]][readme_header_link]
Expand Down
3 changes: 3 additions & 0 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/bastion.svg"
url: "https://github.com/cloudposse/bastion/releases/latest"
- name: "Build & Test Status"
image: "https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml/badge.svg"
url: "https://github.com/cloudposse/bastion/actions/workflows/integration-tests.yml"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"
Expand Down
12 changes: 12 additions & 0 deletions test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

export TERM=linux

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

docker -v
docker-compose -v

docker compose build
17 changes: 9 additions & 8 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

export TERM=linux

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
Expand All @@ -9,10 +11,10 @@ rm -rf fixtures/auth/ida_rsa*
ssh-keygen -q -f fixtures/auth/ida_rsa -N ""
chmod 600 fixtures/auth/ida_rsa

docker-compose down
docker-compose up --build bastion -d
docker-compose exec bastion /scripts/setup.sh
docker-compose run --build test /scripts/google_auth_test.sh
docker compose down
docker compose up -d --build bastion
docker compose exec bastion /scripts/setup.sh
docker compose run --build test /scripts/google_auth_test.sh

retVal=$?

Expand All @@ -24,10 +26,9 @@ else
fi


docker-compose exec bastion ls /var/log/sudo-io/00/00/01/
docker compose exec bastion ls /var/log/sudo-io/00/00/01/

retVal=$?

if [ $retVal -ne 0 ]; then
echo "${red}* sudosh Audit Failed - no logs created!${reset}"
exit $retVal
Expand All @@ -36,7 +37,7 @@ else
fi


docker-compose exec bastion curl https://hooks.slack.com
docker compose exec bastion curl https://hooks.slack.com

retVal=$?

Expand All @@ -47,7 +48,7 @@ else
echo "${green}* Slack API Connection Test Succeeded${reset}"
fi

export SSHRC_KILL_OUTPUT=`docker-compose run --build test /scripts/sshrc_kill_test.sh`
export SSHRC_KILL_OUTPUT=`docker compose run --build test /scripts/sshrc_kill_test.sh`

if [[ "$SSHRC_KILL_OUTPUT" == *"this output should never print"* ]]; then
echo "${red}* Failure to quit after non-zero exit code in sshrc${reset}"
Expand Down

0 comments on commit b0a4ff1

Please sign in to comment.