Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test OAuth2 #1665

Merged
merged 42 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6d4ad00
poetry add pytest-iam==0.0.11
ychiucco Jul 18, 2024
98e8955
Merge branch 'main' into 1652-test-oauth2-integration-within-ci
tcompa Jul 19, 2024
7571035
add docker compose [skip ci]
ychiucco Jul 19, 2024
d23d03b
Merge remote-tracking branch 'refs/remotes/origin/1652-test-oauth2-in…
ychiucco Jul 19, 2024
8c199a5
remove pytest-iam
ychiucco Jul 19, 2024
492bf70
comments
ychiucco Jul 19, 2024
66225f9
build auth router in a function
ychiucco Jul 19, 2024
19a88c6
BROKEN missing service
ychiucco Jul 19, 2024
7120171
BROKEN missing service 2
ychiucco Jul 19, 2024
1c7fa84
test oauth with shell script
ychiucco Jul 20, 2024
29118a1
git checkout main -- fractal_server
ychiucco Jul 20, 2024
8580e1f
working script with recursive curl
ychiucco Jul 22, 2024
2cf17e0
github action 🍪
ychiucco Jul 22, 2024
a92dbd6
rm leftover line
ychiucco Jul 22, 2024
45d893e
Update oauth.yaml
tcompa Jul 22, 2024
7817068
Update oauth.yaml
tcompa Jul 22, 2024
67786c7
Update oauth.yaml
tcompa Jul 22, 2024
7809161
Update oauth.yaml
tcompa Jul 22, 2024
dd905b9
Update oauth.yaml
tcompa Jul 22, 2024
d238705
Update oauth.yaml
tcompa Jul 22, 2024
3cb62f4
Update oauth.yaml
tcompa Jul 22, 2024
bd8eb1c
Update oauth.yaml
tcompa Jul 22, 2024
169ebc8
Update oauth.yaml
tcompa Jul 22, 2024
95074f4
Update oauth.yaml
tcompa Jul 22, 2024
e775b06
Update oauth.yaml
tcompa Jul 22, 2024
091882e
Update oauth.yaml
tcompa Jul 22, 2024
3b016ff
Update oauth.yaml
tcompa Jul 22, 2024
1bf5ab3
Update oauth.yaml
tcompa Jul 22, 2024
3fd009a
Update oauth.yaml
tcompa Jul 22, 2024
64e6d1c
Update serve.sh
tcompa Jul 22, 2024
83e6686
Update serve.sh
tcompa Jul 22, 2024
2db3d50
Update oauth.yaml
tcompa Jul 22, 2024
6c01be3
Update serve.sh
tcompa Jul 22, 2024
8d1eb8c
Update oauth.yaml
tcompa Jul 22, 2024
497fefc
Update oauth.sh
tcompa Jul 22, 2024
572edf5
Update serve.sh
tcompa Jul 22, 2024
0a48fa7
Update oauth.sh
tcompa Jul 22, 2024
7330caa
use fractal-container image
ychiucco Jul 22, 2024
be80c87
move to scripts folder
ychiucco Jul 22, 2024
de906af
simplify script
ychiucco Jul 22, 2024
81b631c
changelog
ychiucco Jul 22, 2024
bd90b3a
remove blank space [skip ci]
ychiucco Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions tests/oauth/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Documentation: https://dexidp.io/docs

issuer: http://127.0.0.1:5556/dex

storage:
type: memory

web:
http: 0.0.0.0:5556

oauth2:
skipApprovalScreen: true

staticClients:
- name: TestClient
id: client_test_id
secret: client_test_secret
redirectURIs:
- http://localhost:8001/auth/test/callback/

connectors:
# mockCallback connector always returns the user 'kilgore@kilgore.trout'.
- type: mockCallback
id: mock
name: Mock
10 changes: 10 additions & 0 deletions tests/oauth/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.1'
services:
dex:
image: dexidp/dex
container_name: dex
ports:
- "5556:5556"
volumes:
- ./config.yaml:/etc/dex/cfg/config.yaml
entrypoint: ["dex","serve","/etc/dex/cfg/config.yaml"]
75 changes: 75 additions & 0 deletions tests/oauth/run_test_oauth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
export FRACTAL_TASKS_DIR=/tmp/fractal/task
export FRACTAL_RUNNER_WORKING_BASE_DIR=/tmp/fractal/wbd
export FRACTAL_RUNNER_BACKEND=local

export JWT_SECRET_KEY=xxx
export JWT_EXPIRE_SECONDS=600000

export DB_ENGINE=sqlite
export SQLITE_PATH=test_oauth.sql

export OAUTH_TEST_CLIENT_ID=client_test_id
export OAUTH_TEST_CLIENT_SECRET=client_test_secret
export OAUTH_TEST_REDIRECT_URL=http://localhost:8001/auth/test/callback/
export OAUTH_TEST_OIDC_CONFIGURATION_ENDPOINT=http://127.0.0.1:5556/dex/.well-known/openid-configuration


cleanup() {
kill $(jobs -p)
docker compose down
rm ${SQLITE_PATH}
}
trap cleanup EXIT

docker compose up -d
sleep 2

poetry run fractalctl set-db
poetry run fractalctl start -p 8001 &
sleep 5

# ----

AUTHORIZATION_URL=$(curl \
http://127.0.0.1:8001/auth/test/authorize/ \
| jq -r ".authorization_url"
)
TOKEN=$(
curl -L --silent --output /dev/null --cookie-jar - $AUTHORIZATION_URL \
| grep "fastapiusersauth" | awk '{print $NF}'
)
WHOAMI=$(
curl -H "Authorization: Bearer $TOKEN" \
http://127.0.0.1:8001/auth/current-user/
)

# ----

assert_equal() {
if [ "$1" != "$2" ]; then
echo "Error: $1 != $2"
exit 1
fi
}

USER_ID=$(echo $WHOAMI | jq -r ".id")
EMAIL=$(echo $WHOAMI | jq -r ".email")
IS_ACTIVE=$(echo $WHOAMI | jq -r ".is_active")
IS_SUPERUSER=$(echo $WHOAMI | jq -r ".is_superuser")
IS_VERIFIED=$(echo $WHOAMI | jq -r ".is_verified")
SLURM_USER=$(echo $WHOAMI | jq -r ".slurm_user")
CACHE_DIR=$(echo $WHOAMI | jq -r ".cache_dir")
USER_NAME=$(echo $WHOAMI | jq -r ".user_name")
SLURM_ACCOUNTS=$(echo $WHOAMI | jq -r ".slurm_accounts")


assert_equal $USER_ID "2"
assert_equal $EMAIL "kilgore@kilgore.trout"
assert_equal $IS_ACTIVE "true"
assert_equal $IS_SUPERUSER "false"
assert_equal $IS_VERIFIED "false"
assert_equal $SLURM_USER "null"
assert_equal $CACHE_DIR "null"
assert_equal $USER_NAME "null"
assert_equal $SLURM_ACCOUNTS "[]"
ychiucco marked this conversation as resolved.
Show resolved Hide resolved
Loading