Skip to content

Commit

Permalink
Fix: Issue #901 Add auth0 environment variables for integrations test (
Browse files Browse the repository at this point in the history
…#902)

* Fix: Issue #901 Add auth0 environment variables for integrations test

Added explicit calls to the run script with the environment variable
Added the `GOBIN` to the path for sake of the script
Added clear instructions to CONTRIBUTING.md

* Fix: Issue 901 - Unified Environment Variables

* Ensure the `gobin` is before path

Ensures that the new binaries will be used if a developer has releases installed previously.

* Remove unused env variable

* Revert environment name changes

* Update CONTRIBUTING.md

Co-authored-by: Will Vedder <[email protected]>

* Conditionally include environment variables in Makefile

---------

Co-authored-by: Will Vedder <[email protected]>
  • Loading branch information
m3talsmith and willvedd authored Nov 8, 2023
1 parent 8485181 commit f7d4c0c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ jobs:
shell: bash
run: make test-integration
env:
AUTH0_CLI_CLIENT_NAME: ${{ secrets.AUTH0_CLI_CLIENT_NAME }}
AUTH0_CLI_CLIENT_DOMAIN: ${{ secrets.AUTH0_CLI_CLIENT_DOMAIN }}
AUTH0_CLI_CLIENT_ID: ${{ secrets.AUTH0_CLI_CLIENT_ID }}
AUTH0_CLI_CLIENT_SECRET: ${{ secrets.AUTH0_CLI_CLIENT_SECRET }}
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
AUTH0_CLIENT_ID: ${{ secrets.AUTH0_CLIENT_ID }}
AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_CLIENT_SECRET }}

- name: Download unit test coverage
uses: actions/download-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ tags
.vscode
.DS_Store
.idea
.env

# Vendor
vendor
Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
2. Clone this repo: `git clone [email protected]:auth0/auth0-cli`
3. `make test` - ensure everything works correctly. Should see things pass.

### Adjusting your Development Environment (Optional)

To pass the integration tests, you must have the `AUTH0_DOMAIN`, `AUTH0_CLIENT_ID` and `AUTH0_CLIENT_SECRET` environment variable set. To get these values, you can:

1. Install [jq](https://jqlang.github.io/jq/)
2. [Setup a Machine-to-Machine application](https://auth0.com/docs/get-started/auth0-overview/create-applications/machine-to-machine-apps)
3. Use the resulting **Client Secret** values

#### Setting up your Environment Variables

You can set these variables in a `.env` file at the root of the project (replace the values with your own):

```shell
export AUTH0_DOMAIN="travel0.us.auth0.com"
export AUTH0_CLIENT_ID="tUIvPH7g2ykVm4lGriYEQ6BKV3je24Ka"
export AUTH0_CLIENT_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
```

## Build and run on native platform

From the top-level directory:
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#-----------------------------------------------------------------------------------------------------------------------
# Variables (https://www.gnu.org/software/make/manual/html_node/Using-Variables.html#Using-Variables)
#-----------------------------------------------------------------------------------------------------------------------
-include .env

.DEFAULT_GOAL := help

NAME := auth0-cli
Expand Down Expand Up @@ -164,10 +166,11 @@ test-unit: ## Run unit tests
${call print, "Running unit tests"}
@go test -v -race ${GO_PACKAGES} -coverprofile="coverage-unit-tests.out"

test-integration: install-with-cover $(GO_BIN)/commander ## Run integration tests. To run a specific test pass the FILTER var. Usage: `make test-integration FILTER="attack protection"`
test-integration: install-with-cover $(GO_BIN)/auth0 $(GO_BIN)/commander ## Run integration tests. To run a specific test pass the FILTER var. Usage: `make test-integration FILTER="attack protection"`
${call print, "Running integration tests"}
@mkdir -p "coverage"
@GOCOVERDIR=coverage bash ./test/integration/scripts/run-test-suites.sh
@PATH=$(GO_BIN):$$PATH \
GOCOVERDIR=coverage bash ./test/integration/scripts/run-test-suites.sh
@go tool covdata textfmt -i "coverage" -o "coverage-integration-tests.out"

test-mocks: $(GO_BIN)/mockgen ## Generate testing mocks using mockgen
Expand Down
12 changes: 6 additions & 6 deletions test/integration/scripts/run-test-suites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

set -e

if [[ -z "${AUTH0_CLI_CLIENT_DOMAIN}" || -z "${AUTH0_CLI_CLIENT_ID}" || -z "${AUTH0_CLI_CLIENT_SECRET}" ]]; then
echo "Error: AUTH0_CLI_CLIENT_DOMAIN, AUTH0_CLI_CLIENT_ID and AUTH0_CLI_CLIENT_SECRET environment variables need to be set"
if [[ -z "${AUTH0_DOMAIN}" || -z "${AUTH0_CLIENT_ID}" || -z "${AUTH0_CLIENT_SECRET}" ]]; then
echo "Error: AUTH0_DOMAIN, AUTH0_CLIENT_ID and AUTH0_CLIENT_SECRET environment variables need to be set"
exit 1
fi

auth0 login \
--domain "${AUTH0_CLI_CLIENT_DOMAIN}" \
--client-id "${AUTH0_CLI_CLIENT_ID}" \
--client-secret "${AUTH0_CLI_CLIENT_SECRET}"
--domain "${AUTH0_DOMAIN}" \
--client-id "${AUTH0_CLIENT_ID}" \
--client-secret "${AUTH0_CLIENT_SECRET}"

set +e

Expand All @@ -20,6 +20,6 @@ exit_code=$?

bash ./test/integration/scripts/test-cleanup.sh

auth0 logout "$AUTH0_CLI_CLIENT_DOMAIN"
auth0 logout "$AUTH0_DOMAIN"

exit $exit_code
6 changes: 3 additions & 3 deletions test/integration/terraform-test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ config:
inherit-env: true
retries: 1
env:
AUTH0_DOMAIN: $AUTH0_CLI_CLIENT_DOMAIN
AUTH0_CLIENT_ID: $AUTH0_CLI_CLIENT_ID
AUTH0_CLIENT_SECRET: $AUTH0_CLI_CLIENT_SECRET
AUTH0_DOMAIN: $AUTH0_DOMAIN
AUTH0_CLIENT_ID: $AUTH0_CLIENT_ID
AUTH0_CLIENT_SECRET: $AUTH0_CLIENT_SECRET
tests:
001.0 - setup:
command: rm -rdf tmp-tf-gen
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ tests:
exit-code: 0

tenants use:
command: auth0 tenants use $AUTH0_CLI_CLIENT_DOMAIN
command: auth0 tenants use $AUTH0_DOMAIN
exit-code: 0
stderr:
contains:
- "Default tenant switched to:"

tenants open:
command: auth0 tenants open $AUTH0_CLI_CLIENT_DOMAIN --no-input
command: auth0 tenants open $AUTH0_DOMAIN --no-input
exit-code: 0
stderr:
contains:
Expand Down

0 comments on commit f7d4c0c

Please sign in to comment.