diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e008d1b..5463f14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,7 @@ jobs: - name: Test CLI env: CL_INFOCLACE_SSH: ${{ secrets.CL_INFOCLACE_SSH }} + CL_GITHUB_SECRET: ${{ secrets.CL_GITHUB_SECRET }} run: | export CL_HOME=`pwd` go install github.com/commander-cli/commander/v2/cmd/commander@latest diff --git a/tests/disk_usage/config_gen.lock b/tests/disk_usage/config_gen.lock deleted file mode 100644 index 9af7b88..0000000 --- a/tests/disk_usage/config_gen.lock +++ /dev/null @@ -1,14 +0,0 @@ -{ - "routing": { - "template_locations": [ - "*.go.html" - ], - "static_dir": "static", - "static_root_dir": "static_root", - "push_events": false, - "early_hints": true - }, - "htmx": { - "version": "1.9.2" - } -} \ No newline at end of file diff --git a/tests/run_cli_tests.sh b/tests/run_cli_tests.sh index 6f46d83..81f7725 100755 --- a/tests/run_cli_tests.sh +++ b/tests/run_cli_tests.sh @@ -57,6 +57,7 @@ export CL_CONFIG_FILE=clace.toml cat < $CL_CONFIG_FILE [security] admin_password_bcrypt = "\$2a\$10\$PMaPsOVMBfKuDG04RsqJbeKIOJjlYi1Ie1KQbPCZRQx38bqYfernm" +callback_url = "https://localhost:25223" EOF if [[ -n "$CL_INFOCLACE_SSH" ]]; then @@ -70,6 +71,18 @@ if [[ -n "$CL_INFOCLACE_SSH" ]]; then EOF fi +if [[ -n "$CL_GITHUB_SECRET" ]]; then + # CL_GITHUB_SECRET env is set, test github oauth login redirect + + cat <> $CL_CONFIG_FILE + +[auth.github_test] +key = "02507afb0ad9056fab09" +secret = "$CL_GITHUB_SECRET" + +EOF +fi + ../clace server start -l trace & sleep 2 commander test $CL_TEST_VERBOSE --dir ./commander/ @@ -77,9 +90,15 @@ commander test $CL_TEST_VERBOSE --dir ./commander/ echo $? if [[ -n "$CL_INFOCLACE_SSH" ]]; then + # test git ssh key access commander test $CL_TEST_VERBOSE test_github_auth.yaml rm ./infoclace_ssh fi +if [[ -n "$CL_GITHUB_SECRET" ]]; then + # test git oauth access are tested + commander test $CL_TEST_VERBOSE test_oauth.yaml +fi + cleanup echo "All tests passed" diff --git a/tests/test_oauth.yaml b/tests/test_oauth.yaml new file mode 100644 index 0000000..d57ef1a --- /dev/null +++ b/tests/test_oauth.yaml @@ -0,0 +1,45 @@ +config: + env: + CL_CONFIG_FILE: clace.toml + CL_GITHUB_SECRET: ${CL_GITHUB_SECRET} +tests: + oauth0010: # copy sample app + command: cp -r ../examples/disk_usage . + + oauth0020: ## create app with oauth auth + command: ../clace app create --auth-type=github_test --approve /oauth1 ./disk_usage + + oauth0030: # check curl redirect to oauth provider + command: curl localhost:25222/oauth1 + stdout: + exactly: 'Temporary Redirect.' # redirect to the auth url + + oauth0031: # update app to no auth + command: ../clace app update auth-type /oauth1 none + + oauth0032: # check curl + command: curl localhost:25222/oauth1 + stdout: "Disk Usage" + + oauth0040: ## create app with invalid auth + command: ../clace app create --auth-type=github --approve /oauth2 ./disk_usage + stderr: "error: invalid authentication type github" + exit-code: 1 + + oauth0050: ## create app with invalid auth + command: ../clace app create --auth-type=abc --approve /oauth2 ./disk_usage + stderr: "error: invalid authentication type abc" + exit-code: 1 + + oauth0060: ## create app with invalid auth + command: ../clace app create --auth-type=github_abc --approve /oauth2 ./disk_usage + stderr: "error: invalid authentication type github_abc" + exit-code: 1 + + oauth0070: # update app to invalid + command: ../clace app update auth-type /oauth1 abc + stderr: "error: invalid authentication type abc" + exit-code: 1 + + oauth9999: # cleanup + command: rm -rf ./disk_usage || true