Skip to content

Commit

Permalink
Added tests for oauth login redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Mar 27, 2024
1 parent fc23823 commit 484564f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions tests/disk_usage/config_gen.lock

This file was deleted.

19 changes: 19 additions & 0 deletions tests/run_cli_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export CL_CONFIG_FILE=clace.toml
cat <<EOF > $CL_CONFIG_FILE
[security]
admin_password_bcrypt = "\$2a\$10\$PMaPsOVMBfKuDG04RsqJbeKIOJjlYi1Ie1KQbPCZRQx38bqYfernm"
callback_url = "https://localhost:25223"
EOF

if [[ -n "$CL_INFOCLACE_SSH" ]]; then
Expand All @@ -70,16 +71,34 @@ 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 <<EOF >> $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/

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"
45 changes: 45 additions & 0 deletions tests/test_oauth.yaml
Original file line number Diff line number Diff line change
@@ -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: '<a href="/_clace/auth/github_test">Temporary Redirect</a>.' # 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

0 comments on commit 484564f

Please sign in to comment.