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

chore(ui): use keycloak for e2es in workflow #909

Merged
merged 68 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f63ef7f
init
andrewrisse Aug 14, 2024
442ffcb
remove ./uds
andrewrisse Aug 14, 2024
2ae86d2
add insecure keycloak admin user
andrewrisse Aug 14, 2024
89ef006
add wait for keycloak secret
andrewrisse Aug 14, 2024
c6ca7df
trigger
andrewrisse Aug 14, 2024
72c079e
Test trigger
andrewrisse Aug 14, 2024
4f8323d
Test trigger 2
andrewrisse Aug 14, 2024
7d002c1
Add debug statements
andrewrisse Aug 14, 2024
f3483cc
try workflow var
andrewrisse Aug 14, 2024
8a68a62
try hardcoding command
andrewrisse Aug 14, 2024
aa67235
Merge branch 'main' into workflow-keycloak
andrewrisse Aug 15, 2024
5b9e9f0
change nltk version
andrewrisse Aug 15, 2024
621ca63
fix csp
andrewrisse Aug 15, 2024
de4433a
revert to older setup
andrewrisse Aug 15, 2024
884edf8
Remove wait
andrewrisse Aug 15, 2024
22a7de3
add uds-config
andrewrisse Aug 15, 2024
d47d629
Remove line
andrewrisse Aug 15, 2024
5e0387f
Revert playwright e2e
andrewrisse Aug 15, 2024
1bdcbe8
revert action
andrewrisse Aug 15, 2024
83cd7c7
merge main and delete uds config
andrewrisse Aug 15, 2024
7b54202
add uds-config 2
andrewrisse Aug 15, 2024
5308f5e
add config back in
andrewrisse Aug 15, 2024
4c5ee86
Add debugs and single quote
andrewrisse Aug 15, 2024
492fdc5
Back to double quote
andrewrisse Aug 15, 2024
e43545c
Trigger test 1
andrewrisse Aug 15, 2024
fc72123
Trigger test 2
andrewrisse Aug 15, 2024
e2d8338
merge main
andrewrisse Aug 15, 2024
17b90dd
remove duplicate header
andrewrisse Aug 15, 2024
c68ce6b
use createUser script
andrewrisse Aug 15, 2024
eedff06
use make command and cleanup
andrewrisse Aug 15, 2024
87abf37
change order of dep install
andrewrisse Aug 15, 2024
ade6ba9
Explicitly enable keycloak
andrewrisse Aug 15, 2024
b893039
disable keycloak in build step
andrewrisse Aug 15, 2024
3a51045
fix var name
andrewrisse Aug 15, 2024
e88d4ea
double fill user pass
andrewrisse Aug 16, 2024
c7d8213
Remove --http flag
andrewrisse Aug 16, 2024
42a018a
Debug statements
andrewrisse Aug 16, 2024
680b126
Debug statements 2
andrewrisse Aug 16, 2024
d3e8206
Merge branch 'main' into workflow-keycloak
andrewrisse Aug 16, 2024
aab3691
more debugging
andrewrisse Aug 16, 2024
608c3c7
Merge branch 'main' into workflow-keycloak
justinthelaw Aug 16, 2024
90b9c00
more debugging
andrewrisse Aug 16, 2024
bb26910
add statement to print out created user
andrewrisse Aug 16, 2024
b567243
add http1.1 flag
andrewrisse Aug 20, 2024
f121cea
Debug statements
andrewrisse Aug 20, 2024
60c7397
--data
andrewrisse Aug 20, 2024
754fb41
debug 2
andrewrisse Aug 20, 2024
1d94b68
tac tac
andrewrisse Aug 20, 2024
5fd43c3
echo into new var
andrewrisse Aug 20, 2024
2730e2e
echo curl result
andrewrisse Aug 20, 2024
cb5028d
bump uds cli to v14
andrewrisse Aug 20, 2024
c0313d3
cleanup
andrewrisse Aug 20, 2024
ced7cca
Merge branch 'main' into workflow-keycloak
andrewrisse Aug 20, 2024
8538132
use env var and remove extra echo step
andrewrisse Aug 20, 2024
50553a0
Test password mask
andrewrisse Aug 20, 2024
eec0b1c
add echo tests for createUser.sh
andrewrisse Aug 20, 2024
6481be3
Test echo without mask
andrewrisse Aug 21, 2024
fdabb8d
use var directly
andrewrisse Aug 21, 2024
0e410c9
add missing quote
andrewrisse Aug 22, 2024
b870514
merge main and adjust password so it always has special characters
andrewrisse Aug 22, 2024
ff9deb6
update password generator
andrewrisse Aug 22, 2024
adec79a
Delete test file
andrewrisse Aug 22, 2024
699c230
Merge branch 'main' into workflow-keycloak
andrewrisse Aug 22, 2024
d38b689
new debug 1
andrewrisse Aug 22, 2024
0d251f6
use github env
andrewrisse Aug 22, 2024
78fe2e8
add and test password mask
andrewrisse Aug 22, 2024
5550d2a
Remove echos
andrewrisse Aug 22, 2024
05b240f
Remove test files
andrewrisse Aug 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
8 changes: 6 additions & 2 deletions .github/actions/uds-cluster/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ runs:
using: composite
steps:
- name: Setup UDS Environment
uses: defenseunicorns/uds-common/.github/actions/setup@05f42bb3117b66ebef8c72ae050b34bce19385f5
uses: defenseunicorns/uds-common/.github/actions/setup@822dac4452e6815aadcf09f487406ff258756a0c # v0.14.0
with:
username: ${{ inputs.registry1Username }}
password: ${{ inputs.registry1Password }}
udsCliVersion: 0.14.0

- name: Checkout Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Create UDS Cluster
shell: bash
run: |
make create-uds-cpu-cluster
UDS_CONFIG=.github/config/uds-config.yaml make create-uds-cpu-cluster
3 changes: 3 additions & 0 deletions .github/config/uds-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variables:
core-slim-dev:
INSECURE_ADMIN_PASSWORD_GENERATION: "true"
57 changes: 57 additions & 0 deletions .github/scripts/createUser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
KEYCLOAK_ADMIN_PASSWORD=$(uds zarf tools kubectl get secret -n keycloak keycloak-admin-password -o jsonpath={.data.password} | base64 -d)
echo "::add-mask::$KEYCLOAK_ADMIN_PASSWORD"

KEYCLOAK_ADMIN_TOKEN=$(curl --location "https://keycloak.admin.uds.dev/realms/master/protocol/openid-connect/token" \
--http1.1 \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "username=admin" \
--data-urlencode "password=${KEYCLOAK_ADMIN_PASSWORD}" \
--data-urlencode "client_id=admin-cli" \
--data-urlencode "grant_type=password" | uds zarf tools yq .access_token)
echo "::add-mask::$KEYCLOAK_ADMIN_TOKEN"


curl --location "https://keycloak.admin.uds.dev/admin/realms/uds/users" \
--http1.1 \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${KEYCLOAK_ADMIN_TOKEN}" \
--data "{
\"username\": \"doug\",
\"firstName\": \"Doug\",
\"lastName\": \"Unicorn\",
\"email\": \"[email protected]\",
\"attributes\": {
\"mattermostid\": \"1\"
},
\"emailVerified\": true,
\"enabled\": true,
\"requiredActions\": [],
\"credentials\": [
{
\"type\": \"password\",
\"value\": \"${FAKE_E2E_USER_PASSWORD}\",
\"temporary\": false
}
]
}"

CONDITIONAL_OTP_ID=$(curl --location "https://keycloak.admin.uds.dev/admin/realms/uds/authentication/flows/Authentication/executions" \
--http1.1 \
--header "Authorization: Bearer ${KEYCLOAK_ADMIN_TOKEN}" | uds zarf tools yq '.[] | select(.displayName == "Conditional OTP") | .id')

curl --location --request PUT "https://keycloak.admin.uds.dev/admin/realms/uds/authentication/flows/Authentication/executions" \
--http1.1 \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${KEYCLOAK_ADMIN_TOKEN}" \
--data "{
\"id\": \"${CONDITIONAL_OTP_ID}\",
\"requirement\": \"DISABLED\"
}"

USER=$(curl --location "https://keycloak.admin.uds.dev/admin/realms/uds/users?user=doug" \
--http1.1 \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${KEYCLOAK_ADMIN_TOKEN}" \
)

echo "User: $USER"
29 changes: 22 additions & 7 deletions .github/workflows/e2e-playwright.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ on:
- "!.github/**"
- ".github/workflows/e2e-playwright.yaml"
- ".github/actions/uds-cluster/action.yaml"
- ".github/actions/scripts/createUser.sh"
- ".github/actions/config/uds-config.yaml"

# Ignore docs and website things
- "!**.md"
Expand Down Expand Up @@ -64,20 +66,27 @@ jobs:
with:
node-version-file: 'src/leapfrogai_ui/package.json'

- name: Install UI/Playwright Dependencies
run: |
npm --prefix src/leapfrogai_ui ci
npx --prefix src/leapfrogai_ui playwright install

- name: Setup Python
uses: ./.github/actions/python

- name: Generate Fake Playwright User Password
id: generate-password
run: |
PASSWORD=$(cat <(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9!@#$%^&*()_+-=[]{}|;:,.<>?' | head -c 20 | sed 's/\(.\{5\}\)/\1!@/g' | head -c 22))
echo "::add-mask::$PASSWORD"
echo "FAKE_E2E_USER_PASSWORD=$PASSWORD" >> $GITHUB_ENV

- name: Setup UDS Cluster
uses: ./.github/actions/uds-cluster
with:
registry1Username: ${{ secrets.IRON_BANK_ROBOT_USERNAME }}
registry1Password: ${{ secrets.IRON_BANK_ROBOT_PASSWORD }}

- name: Create Test User
run: |
chmod +x ./.github/scripts/createUser.sh
./.github/scripts/createUser.sh

- name: Setup LFAI-API and Supabase
uses: ./.github/actions/lfai-core

Expand All @@ -89,14 +98,20 @@ jobs:
run: |
python -m pytest ./tests/e2e/test_api.py -v


##########
# UI
##########
- name: Install UI/Playwright Dependencies
run: |
npm --prefix src/leapfrogai_ui ci
npx --prefix src/leapfrogai_ui playwright install

- name: Deploy LFAI-UI
run: |
make build-ui LOCAL_VERSION=e2e-test
docker image prune -af
uds zarf package deploy packages/ui/zarf-package-leapfrogai-ui-amd64-e2e-test.tar.zst --confirm
uds zarf package deploy packages/ui/zarf-package-leapfrogai-ui-amd64-e2e-test.tar.zst --set DISABLE_KEYCLOAK=false --confirm
rm packages/ui/zarf-package-leapfrogai-ui-amd64-e2e-test.tar.zst

# Run the playwright UI tests using the deployed Supabase endpoint and upload report as an artifact
Expand All @@ -105,7 +120,7 @@ jobs:
cp src/leapfrogai_ui/.env.example src/leapfrogai_ui/.env
mkdir -p playwright/auth
touch playwright/auth.user.json
SERVICE_ROLE_KEY=$(uds zarf tools kubectl get secret -n leapfrogai supabase-bootstrap-jwt -o jsonpath={.data.service-key} | base64 -d) TEST_ENV=CI PUBLIC_DISABLE_KEYCLOAK=true PUBLIC_SUPABASE_ANON_KEY=$ANON_KEY npm --prefix src/leapfrogai_ui run test:integration:ci
SERVICE_ROLE_KEY=$(uds zarf tools kubectl get secret -n leapfrogai supabase-bootstrap-jwt -o jsonpath={.data.service-key} | base64 -d) TEST_ENV=CI USERNAME=doug PASSWORD=$FAKE_E2E_USER_PASSWORD PUBLIC_SUPABASE_ANON_KEY=$ANON_KEY npm --prefix src/leapfrogai_ui run test:integration:ci

# Upload the Playwright report as an artifact
- name: Archive Playwright Report
Expand Down
2 changes: 1 addition & 1 deletion packages/k3d-gpu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ create-uds-gpu-cluster: build-k3d-gpu
--set K3D_EXTRA_ARGS="--gpus=all \
--image=ghcr.io/defenseunicorns/leapfrogai/k3d-gpu:${LOCAL_VERSION}" --confirm

create-uds-cpu-cluster: build-k3d-gpu
create-uds-cpu-cluster:
@uds deploy k3d-core-slim-dev:${UDS_VERSION} \
${ZARF_FLAGS} \
--confirm
Expand Down
3 changes: 2 additions & 1 deletion src/leapfrogai_ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ zarf-sbom/


playwright/.auth
test-results/
test-results/
e2e-report/
22 changes: 12 additions & 10 deletions src/leapfrogai_ui/tests/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ const doKeycloakLogin = async (page: Page) => {
await page.getByLabel('Password').fill(process.env.PASSWORD!);
await page.getByRole('button', { name: 'Log In' }).click();

const totp = new OTPAuth.TOTP({
issuer: 'Unicorn Delivery Service',
algorithm: 'SHA1',
digits: 6,
period: 30,
secret: process.env.MFA_SECRET!
});
const code = totp.generate();
await page.getByLabel('Six digit code').fill(code);
await page.getByRole('button', { name: 'Log In' }).click();
if (process.env.TEST_ENV !== 'CI') {
const totp = new OTPAuth.TOTP({
issuer: 'Unicorn Delivery Service',
algorithm: 'SHA1',
digits: 6,
period: 30,
secret: process.env.MFA_SECRET!
});
const code = totp.generate();
await page.getByLabel('Six digit code').fill(code);
await page.getByRole('button', { name: 'Log In' }).click();
}
};

const login = async (page: Page) => {
Expand Down
Loading