diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 0a00e64c6..c7defdfdc 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -11,7 +11,6 @@ on: jobs: build: - runs-on: ubuntu-20.04 steps: @@ -23,5 +22,15 @@ jobs: distribution: 'adopt' - name: Maven version run: mvn -version - - name: Build with Maven - run: mvn -B package + - name: API testing with Maven + run: mvn clean install -Prun-api-tests + env: + OAUTH_CLIENTID: "${{secrets.OAUTH_CLIENTID}}" + OAUTH_CLIENTSECRET: "${{secrets.OAUTH_CLIENTSECRET}}" + OAUTH_AUDIENCE: "${{secrets.OAUTH_AUDIENCE}}" + OAUTH_ISSUER: "${{secrets.OAUTH_ISSUER}}" + OKTA_USERNAME: "${{secrets.OKTA_USERNAME}}" + OKTA_PASSWORD: "${{secrets.OKTA_PASSWORD}}" + OKTA_URL: "${{secrets.OKTA_URL}}" + BASE_URL: "http://localhost:8080" + APP_START_CHECK_RETRY_LIMIT: 100 diff --git a/osmt_cli.sh b/osmt_cli.sh index 145e9a383..07e5cf838 100755 --- a/osmt_cli.sh +++ b/osmt_cli.sh @@ -18,6 +18,10 @@ declare -r MYSQL_USER="${MYSQL_USER:-osmt_db_user}" declare -r MYSQL_PASSWORD="${MYSQL_PASSWORD:-password}" declare -r ELASTICSEARCH_HTTP_PORT="${ELASTICSEARCH_HTTP_PORT:-9200}" declare -r ELASTICSEARCH_TRANSPORT_PORT="${ELASTICSEARCH_TRANSPORT_PORT:-9300}" +declare OAUTH_ISSUER="${OAUTH_ISSUER:-}" +declare OAUTH_CLIENTID="${OAUTH_CLIENTID:-}" +declare OAUTH_CLIENTSECRET="${OAUTH_CLIENTSECRET:-}" +declare OAUTH_AUDIENCE="${OAUTH_AUDIENCE:-}" # new line formatted to indent with echo_err / echo_info etc @@ -47,6 +51,17 @@ _cd_osmt_project_dir() { _source_osmt_env_file() { local env_file="${1}" + # gracefully bypass sourcing env file if these 4 OAUTH values are provided + if [[ \ + -n "${OAUTH_ISSUER}" && \ + -n "${OAUTH_CLIENTID}" &&\ + -n "${OAUTH_CLIENTSECRET}" && \ + -n "${OAUTH_AUDIENCE}" \ + ]]; then + echo_info "Using OAUTH environment variables, not using ${env_file} env file." + return 0 + fi + if [[ ! -f "${env_file}" || ! -r "${env_file}" ]]; then echo_err "Can not access ${env_file}. You can initialize the environment files by running $(basename "${0}") -i$" return 1 diff --git a/test/bin/pre_test_setup.sh b/test/bin/pre_test_setup.sh index 33ec87d65..148bfa6db 100755 --- a/test/bin/pre_test_setup.sh +++ b/test/bin/pre_test_setup.sh @@ -21,6 +21,7 @@ export BASE_URL="http://${BASE_DOMAIN}" export OSMT_FRONT_END_PORT="${APP_PORT}" declare -ri LOAD_CI_DATASET="${LOAD_CI_DATASET:-0}" +declare -i APP_START_CHECK_RETRY_LIMIT="${APP_START_CHECK_RETRY_LIMIT:-12}" _get_osmt_project_dir() { local project_dir; project_dir="$(git rev-parse --show-toplevel 2> /dev/null)" @@ -51,10 +52,12 @@ inject_tests() { } curl_with_retry() { + local log_file; log_file="${project_dir}/test/target/osmt_spring_app.log" local -i rc=-1 - local -i retry_limit=12 + local -i retry_limit=${APP_START_CHECK_RETRY_LIMIT} until [ ${rc} -eq 0 ] && [ ${retry_limit} -eq 0 ]; do echo_info "Attempting to request the index page of the OSMT Spring app with curl..." + echo_info "${BASE_URL}" curl -s "${BASE_URL}" 1>/dev/null 2>/dev/null rc=$? if [[ ${rc} -eq 0 ]]; then @@ -62,7 +65,11 @@ curl_with_retry() { return 0 fi if [[ ${retry_limit} -eq 0 ]]; then + echo + echo_info "osmt_spring_app log file below..." + echo echo_err "Could not load the index page." + cat "${log_file}" return 1 fi if [[ ${rc} -ne 0 ]]; then @@ -116,7 +123,7 @@ error_handler() { main() { local project_dir; project_dir="$(_get_osmt_project_dir)" || exit 135 - local log_file; log_file="${project_dir}/api/target/osmt_spring_app.log" + local log_file; log_file="${project_dir}/test/target/osmt_spring_app.log" # Adding docker clean up at the beginning to keep previous test state # in case we need to debug and cleaning up docker could remove logs. diff --git a/test/bin/run_api_tests.sh b/test/bin/run_api_tests.sh index 048f59f10..5557f07fb 100755 --- a/test/bin/run_api_tests.sh +++ b/test/bin/run_api_tests.sh @@ -15,11 +15,14 @@ _get_osmt_project_dir() { } function source_osmt_apitest_env_file() { - echo "Sourcing $apitest_env_file" - set -o allexport - # shellcheck source="test/osmt-apitest.env" - source "$apitest_env_file" - set +o allexport + # Checks to see if osmt-apitest.env file exists + if [[ -f "${apitest_env_file}" || -r "${apitest_env_file}" ]]; then + echo "Sourcing $apitest_env_file" + set -o allexport + # shellcheck source="test/osmt-apitest.env" + source "$apitest_env_file" + set +o allexport + fi } function get_bearer_token() { diff --git a/test/postman/test-injector.js b/test/postman/test-injector.js index b71ec02f3..5f42284d6 100644 --- a/test/postman/test-injector.js +++ b/test/postman/test-injector.js @@ -97,6 +97,7 @@ function main() { console.log(`\nERROR: Could not parse test information for the following ` + `${failedEndpoints.length} endpoint(s):`); console.log(failedEndpoints); + throw 135 } else { console.log("INFO: All collection endpoints successfully populated with tests.");