Skip to content

Commit

Permalink
ci: run AS java test (#5775)
Browse files Browse the repository at this point in the history
* ci: add gh test for as

* ci: modify test installation

* ci: fix folder location

* ci: execute java tests

* ci: execute java tests

* ci: add auth server test

* ci: fix auth test runs

* ci: pass load test though setup.properties

* ci: update test logic

* ci: run mvn test command from workflow

* ci: run mvn test command from testendpoints.sh

* ci: run docker compose tty

* ci: rm -ti

* ci: remove override for java test prep

* ci: set prepare java tests true

* ci: remove unnecessary env PREPARE_JAVA_TESTS

* ci: use jans build commit

* chore: install maven

* chore: update wait for

* chore: update wait for

* chore: update wait for services

* ci: fix $JANS_FQDN

* ci: cd /tmp/jans/jans-auth-server

* ci: fix docker exec using -w

* ci: fix docker exec using -w

* ci: do not fail container on java test preparations

* fix: keytool command
  • Loading branch information
moabu committed Aug 3, 2023
1 parent d8cea00 commit 6bdf10b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ jobs:
with:
artifact: go-test-results
name: Go Tests
path: '*.xml'
reporter: java-junit
path: '*report.xml'
reporter: java-junit
- name: Publish Test Report
uses: scacap/action-surefire-report@v1
report_paths: '*testng-results.xml'
11 changes: 10 additions & 1 deletion .github/workflows/test_docker_linux_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ jobs:
go install github.com/jstemmer/go-junit-report/v2@latest
go test -v 2>&1 ./... | go-junit-report > ${{ matrix.persistence-backends }}report.xml
- uses: actions/upload-artifact@v2 # upload test results
id: upload-go-test-results
if: success() || failure() # run this step even if previous step failed
with:
name: go-test-results
path: ./terraform-provider-jans/${{ matrix.persistence-backends }}report.xml

- uses: actions/upload-artifact@v2 # upload test results
id: upload-java-test-results
if: success() || failure() # run this step even if previous step failed
with:
name: go-test-results
path: ./terraform-provider-jans/${{ matrix.persistence-backends }}report.xml
path: ./tmp/reports/*.xml
33 changes: 30 additions & 3 deletions automation/startjanssenmonolithdemo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ if [[ -z $EXT_IP ]]; then
EXT_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
fi

wait_for_services() {
code=404
while [[ "$code" != "200" ]]; do
echo "Waiting for https://${JANS_FQDN}/$1 to respond with 200"
code=$(curl -s -o /dev/null -w ''%{http_code}'' -k https://"${JANS_FQDN}"/"$1")
sleep 5
done
}

sudo apt-get update
# Install Docker and Docker compose plugin
sudo apt-get remove docker docker-engine docker.io containerd runc -y || echo "Docker doesn't exist..installing.."
Expand All @@ -41,7 +50,7 @@ rm -rf /tmp/jans || echo "/tmp/jans doesn't exist"
git clone --filter blob:none --no-checkout https://github.com/janssenproject/jans /tmp/jans \
&& cd /tmp/jans \
&& git sparse-checkout init --cone \
&& git checkout main \
&& git checkout "$JANS_BUILD_COMMIT" \
&& git sparse-checkout set docker-jans-monolith \
&& cd "$WORKING_DIRECTORY"

Expand All @@ -59,6 +68,7 @@ if [[ "$JANS_BUILD_COMMIT" ]]; then
# and use the respective image instead of the default image
python3 -c "from pathlib import Path ; import ruamel.yaml ; compose = Path('/tmp/jans/docker-jans-monolith/jans-mysql-compose.yml') ; yaml = ruamel.yaml.YAML() ; data = yaml.load(compose) ; data['services']['jans']['build'] = '.' ; del data['services']['jans']['image'] ; yaml.dump(data, compose)"
python3 -c "from pathlib import Path ; import ruamel.yaml ; compose = Path('/tmp/jans/docker-jans-monolith/jans-postgres-compose.yml') ; yaml = ruamel.yaml.YAML() ; data = yaml.load(compose) ; data['services']['jans']['build'] = '.' ; del data['services']['jans']['image'] ; yaml.dump(data, compose)"
python3 -c "from pathlib import Path ; import ruamel.yaml ; compose = Path('/tmp/jans/docker-jans-monolith/jans-ldap-compose.yml') ; yaml = ruamel.yaml.YAML() ; data = yaml.load(compose) ; data['services']['jans']['build'] = '.' ; del data['services']['jans']['image'] ; yaml.dump(data, compose)"
fi
# --
if [[ $JANS_PERSISTENCE == "MYSQL" ]]; then
Expand Down Expand Up @@ -88,15 +98,32 @@ if [ "$jans_status" == '"unhealthy"' ]; then
docker logs docker-jans-monolith-jans-1
exit 1
fi
echo "Will be ready in exactly 3 mins"
sleep 180
wait_for_services jans-config-api/api/v1/health/ready
wait_for_services jans-scim/sys/health-check
wait_for_services jans-fido2/sys/health-check

cat << EOF > testendpoints.sh
echo -e "Testing openid-configuration endpoint.. \n"
docker exec docker-jans-monolith-jans-1 curl -f -k https://localhost/.well-known/openid-configuration
echo -e "Testing scim-configuration endpoint.. \n"
docker exec docker-jans-monolith-jans-1 curl -f -k https://localhost/.well-known/scim-configuration
echo -e "Testing fido2-configuration endpoint.. \n"
docker exec docker-jans-monolith-jans-1 curl -f -k https://localhost/.well-known/fido2-configuration
mkdir -p /tmp/reports || echo "reports folder exists"
while ! docker exec docker-jans-monolith-jans-1 test -f "/tmp/httpd.crt"; do
echo "Waiting for the container to run java test preparations"
sleep 5
done
echo -e "Running build.. \n"
docker exec -w /tmp/jans/jans-auth-server docker-jans-monolith-jans-1 mvn -Dcfg="$JANS_FQDN" -Dmaven.test.skip=true -fae clean compile install
echo -e "Running tests.. \n"
docker exec -w /tmp/jans/jans-auth-server docker-jans-monolith-jans-1 mvn -Dcfg="$JANS_FQDN" -Dmaven.test.skip=false test
echo -e "copying reports.. \n"
docker cp docker-jans-monolith-jans-1:/tmp/jans/jans-auth-server/client/target/surefire-reports/testng-results.xml /tmp/reports/$JANS_PERSISTENCE-jans-auth-client-testng-results.xml
docker cp docker-jans-monolith-jans-1:/tmp/jans/jans-auth-server/agama/model/target/surefire-reports/testng-results.xml /tmp/reports/$JANS_PERSISTENCE-jans-auth-agama-model-testng-results.xml
docker cp docker-jans-monolith-jans-1:/tmp/jans/jans-auth-server/test-model/target/surefire-reports/testng-results.xml /tmp/reports/$JANS_PERSISTENCE-jans-auth-test-model-testng-results.xml
docker cp docker-jans-monolith-jans-1:/tmp/jans/jans-auth-server/model/target/surefire-reports/testng-results.xml /tmp/reports/$JANS_PERSISTENCE-jans-auth-model-testng-results.xml
EOF
sudo bash testendpoints.sh
echo -e "You may re-execute bash testendpoints.sh to do a quick test to check the configuration endpoints."
Expand Down
2 changes: 1 addition & 1 deletion docker-jans-monolith/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/00-docker \
# Prevent prompt errors during package installation
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update \
&& apt-get install -y python3 tini curl ca-certificates dbus systemd iproute2 gpg python3-pip python3-dev libpq-dev gcc python3-psycopg2 python3-ldap3 \
&& apt-get install -y python3 tini curl ca-certificates dbus systemd iproute2 gpg python3-pip python3-dev libpq-dev gcc python3-psycopg2 python3-ldap3 git maven \
&& apt-get clean \
# Cleaning up package lists
&& rm -rf /var/lib/apt/lists/*
Expand Down
47 changes: 46 additions & 1 deletion docker-jans-monolith/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ install_jans() {
echo "test_client_id=${TEST_CLIENT_ID}"| tee -a setup.properties > /dev/null
echo "test_client_pw=${TEST_CLIENT_SECRET}" | tee -a setup.properties > /dev/null1
echo "test_client_trusted=""$([[ ${TEST_CLIENT_TRUSTED} == true ]] && echo True || echo True)" | tee -a setup.properties > /dev/null
echo "loadTestData=True" | tee -a setup.properties > /dev/null
if [[ "${CN_INSTALL_MYSQL}" == "true" ]] || [[ "${CN_INSTALL_PGSQL}" == "true" ]]; then
echo "Installing with RDBMS"
echo "rdbm_install=2" | tee -a setup.properties > /dev/null
Expand All @@ -65,7 +66,7 @@ install_jans() {
echo "***** PLEASE NOTE THAT THIS MAY TAKE A WHILE TO FINISH. PLEASE BE PATIENT!! *****"
echo "Executing https://raw.githubusercontent.com/JanssenProject/jans/${JANS_SOURCE_VERSION}/jans-linux-setup/jans_setup/install.py > install.py"
curl https://raw.githubusercontent.com/JanssenProject/jans/"${JANS_SOURCE_VERSION}"/jans-linux-setup/jans_setup/install.py > install.py
echo "Executing python3 install.py -yes --args=-f setup.properties -n -test-client-id=${TEST_CLIENT_ID} -test-client-secret=${TEST_CLIENT_SECRET} --test-client-trusted"
echo "Executing python3 install.py -yes --args=-f setup.properties -n"
python3 install.py -yes --args="-f setup.properties -n"
echo "***** Setup script completed!! *****"

Expand All @@ -81,6 +82,49 @@ check_installed_jans() {
fi
}

prepare_auth_server_test() {
WORKING_DIRECTORY=$PWD
echo "***** cloning jans auth server folder!! *****"
rm -rf /tmp/jans || echo "Jans isn't cloned yet..Cloning"\
&& git clone --filter blob:none --no-checkout https://github.com/janssenproject/jans /tmp/jans \
&& cd /tmp/jans \
&& git sparse-checkout init --cone \
&& git checkout "${JANS_SOURCE_VERSION}" \
&& git sparse-checkout set jans-auth-server \
&& cd jans-auth-server \
&& echo "Copying auth server test profiles from ephemeral server" \
&& cp -R /opt/jans/jans-setup/output/test/jans-auth ./ \
&& echo "Creating auth server profile folders" \
&& mkdir -p ./client/profiles/"${CN_HOSTNAME}" \
&& mkdir -p ./server/profiles/"${CN_HOSTNAME}" \
&& echo "Copying auth server profile files" \
&& cp ./jans-auth/client/* ./client/profiles/"${CN_HOSTNAME}" \
&& cp ./jans-auth/server/* ./server/profiles"/${CN_HOSTNAME}" \
&& echo "Copying auth server keystores from default profile" \
&& cp -f ./client/profiles/default/client_keystore.p12 ./client/profiles/"${CN_HOSTNAME}" \
&& cp -f ./server/profiles/default/client_keystore.p12 ./server/profiles/"${CN_HOSTNAME}" \
&& echo "Removing test profile folder" \
&& rm -rf ./jans-auth \
&& cd agama \
&& cp /opt/jans/jans-setup/output/test/jans-auth/config-agama-test.properties . \
&& mkdir -p ./engine/profiles/"${CN_HOSTNAME}" \
&& mv config-agama-test.properties ./engine/profiles/"${CN_HOSTNAME}"/config-agama-test.properties \
&& cd .. \
&& echo "Checking if the compilation and install is ok without running the tests" \
&& echo "Installing the jans cert in local keystore" \
&& openssl s_client -connect "${CN_HOSTNAME}":443 2>&1 |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/httpd.crt \
&& TrustStorePW=$(grep -Po '(?<=defaultTrustStorePW=)\S+' /opt/jans/jans-setup/setup.properties.last) \
&& keytool -import -trustcacerts -noprompt -storepass "${TrustStorePW}" -alias "${CN_HOSTNAME}" -keystore /usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts -file /tmp/httpd.crt \
&& cd "$WORKING_DIRECTORY"
}

prepare_java_tests() {
echo "***** Running Java tests!! *****"
echo "***** Running Auth server tests!! *****"
prepare_auth_server_test
echo "***** Java tests completed!! *****"
}

start_services() {
/etc/init.d/apache2 start
/opt/dist/scripts/jans-auth start
Expand All @@ -91,6 +135,7 @@ start_services() {

check_installed_jans
start_services
prepare_java_tests || "Java test preparations failed!!"

# use -F option to follow (and retry) logs
tail -F /opt/jans/jetty/jans-auth/logs/*.log \
Expand Down

0 comments on commit 6bdf10b

Please sign in to comment.