Repository navigation
feat(CI-OAuth2): add Keycloak IdP setup and OAuth2 state validation e2e tests #8922
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
Merged
sanish-bruno
merged 25 commits into
usebruno:main
from
abhishekp-bruno:feat/oauth2-keyclock-cicd-setup-zip-v2
Nov 23, 2026
+791
−16
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
cc1c797
feat(oauth2): add Keycloak-backed OAuth2 e2e tests and CI setup
abhishekp-bruno 5c8b4e4
ci(oauth2): extract Keycloak zip with unzip, fall back to tar
abhishekp-bruno 4563b94
ci(oauth2): switch from Keycloak zip to tar.gz for extraction
abhishekp-bruno 91a48fd
ci(oauth2): refine Keycloak setup action for tar.gz extraction
abhishekp-bruno 8164293
update comments
abhishekp-bruno e58f084
update test files from .bru to .yml
abhishekp-bruno 4d100a2
refactor(oauth2): remove outdated comments and streamline state gener…
abhishekp-bruno b7f37a4
docs(oauth2): update local Keycloak setup instructions for state vali…
abhishekp-bruno 233c52e
Resolve review comments
abhishekp-bruno cd1b63c
resolve code review suggestions
abhishekp-bruno 4dd10db
refactor(oauth2): modularize OAuth2 flow helpers and clean up test setup
abhishekp-bruno 5390526
refactor(oauth2): clean up action.yml files and enhance documentation
abhishekp-bruno 77cef4d
fix(oauth2): improve state mismatch handling in tests
abhishekp-bruno 92eb022
- Added data-testid attributes to the OAuth2 token viewer for improve…
abhishekp-bruno 33a209f
feat(oauth2): add data-testid for Get Access Token button and update …
abhishekp-bruno 8f40eaa
refactor(oauth2): update variable exports to constants in test helpers
abhishekp-bruno 01b425a
fix(oauth2): change log handling in Keycloak log collection action
abhishekp-bruno cb7954e
fixed lint error
abhishekp-bruno 98bade1
test(oauth2): drive implicit grant tests through a real Keycloak login
abhishekp-bruno c4eec29
ci(oauth2): kill the Keycloak process tree on Windows
abhishekp-bruno 579485e
ci(oauth2): drop the unused port input from run-oauth2-e2e-tests
abhishekp-bruno 1d25b48
chore(oauth2): restore the state rationale at the auth-code call site
abhishekp-bruno 9ce5cc3
resolved review comments
abhishekp-bruno 2ced57e
ci(oauth2): tidy the log-staging script and add missing trailing newl…
abhishekp-bruno 7325bb9
moved to e2e folder and fixed imports
abhishekp-bruno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
.github/actions/auth/oauth2/collect-keycloak-logs/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: 'Collect Keycloak Logs' | ||
| description: 'Stage and upload the Keycloak server logs from an OAuth2 e2e run (Linux, macOS, Windows)' | ||
|
|
||
| inputs: | ||
| artifact-suffix: | ||
| description: 'Suffix for the uploaded log artifact name (linux, macos, windows)' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Stage Keycloak logs | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p keycloak-logs | ||
| shopt -s nullglob | ||
| logs=("$RUNNER_TEMP"/keycloak*.log) | ||
| if (( ${#logs[@]} )); then | ||
| cp "${logs[@]}" keycloak-logs/ | ||
| else | ||
| # Keycloak is started by run-oauth2-e2e-tests, so a missing log usually means | ||
| # setup-keycloak failed first; that failure is the one worth surfacing. | ||
| echo "::warning::No Keycloak logs found in $RUNNER_TEMP." | ||
| fi | ||
| - name: Upload Keycloak logs | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: keycloak-logs-oauth2-${{ inputs.artifact-suffix }} | ||
| path: keycloak-logs/ | ||
| retention-days: 30 | ||
76 changes: 76 additions & 0 deletions
76
.github/actions/auth/oauth2/run-oauth2-e2e-tests/action.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: 'Run OAuth2 E2E Tests' | ||
| description: 'Start Keycloak and run the OAuth2 (Keycloak) E2E tests on Linux, macOS and Windows' | ||
|
|
||
| inputs: | ||
| artifact-suffix: | ||
| description: 'Suffix for the uploaded Playwright report artifact name (linux, macos, windows)' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| # Keycloak is started and the tests run in the same step because GitHub Actions kills | ||
| # background processes when a step ends. KC_HOME comes from the setup-keycloak step. | ||
| - name: Start Keycloak and run OAuth2 E2E tests | ||
| shell: bash | ||
| env: | ||
| KEYCLOAK_PORT: '8090' | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -z "${KC_HOME:-}" ]; then | ||
| echo "::error::KC_HOME is not set; setup-keycloak must run first" | ||
| exit 1 | ||
| fi | ||
| if [ "${RUNNER_OS}" = "Windows" ]; then | ||
| kc_bin="${KC_HOME}/bin/kc.bat" | ||
| else | ||
| kc_bin="${KC_HOME}/bin/kc.sh" | ||
| fi | ||
| log="${RUNNER_TEMP}/keycloak.log" | ||
| "${kc_bin}" start-dev --http-port="${KEYCLOAK_PORT}" --import-realm > "${log}" 2>&1 & | ||
| kc_pid=$! | ||
| # On Windows, kc_pid belongs to the kc.bat wrapper (cmd.exe), not to Java. | ||
| # `kill` would stop only the wrapper and leave Keycloak running, so use | ||
| # taskkill /T to kill the whole tree. | ||
| if [ "${RUNNER_OS}" = "Windows" ]; then | ||
| kc_winpid="$(cat "/proc/${kc_pid}/winpid")" | ||
| trap 'taskkill //PID "${kc_winpid}" //T //F > /dev/null 2>&1 || true' EXIT | ||
| else | ||
| trap 'kill "${kc_pid}" 2>/dev/null || true' EXIT | ||
| fi | ||
| echo "Waiting for Keycloak (realm bruno) on :${KEYCLOAK_PORT} ..." | ||
| ready=false | ||
| for i in $(seq 1 60); do | ||
| if curl -fsS "http://127.0.0.1:${KEYCLOAK_PORT}/realms/bruno/.well-known/openid-configuration" > /dev/null 2>&1; then | ||
| ready=true | ||
| break | ||
| fi | ||
| sleep 2 | ||
| done | ||
| if [ "${ready}" != "true" ]; then | ||
| echo "::error::Keycloak did not become ready in time" | ||
| tail -n 100 "${log}" || true | ||
| exit 1 | ||
| fi | ||
| echo "Keycloak is ready." | ||
| # Linux runners are headless, so Electron needs a virtual display. | ||
| if [ "${RUNNER_OS}" = "Linux" ]; then | ||
| xvfb-run npm run test:e2e:auth:oauth2 | ||
| else | ||
| npm run test:e2e:auth:oauth2 | ||
| fi | ||
| - name: Upload Playwright Report | ||
| if: ${{ !cancelled() }} | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: playwright-report-oauth2-${{ inputs.artifact-suffix }} | ||
| path: | | ||
| playwright-report/ | ||
| test-results/ | ||
| retention-days: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: 'Setup Keycloak' | ||
| description: 'Provision Keycloak (download + realm import prep) for the OAuth2 e2e tests on Linux, macOS and Windows' | ||
|
|
||
| inputs: | ||
| keycloak-version: | ||
| description: 'Keycloak release to download' | ||
| required: false | ||
| default: '26.3.3' | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Setup Java 21 (Temurin) | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '21' | ||
| - name: Download and prepare Keycloak | ||
| shell: bash | ||
| working-directory: ${{ runner.temp }} | ||
| env: | ||
| KEYCLOAK_VERSION: ${{ inputs.keycloak-version }} | ||
| run: | | ||
|
abhishekp-bruno marked this conversation as resolved.
Resolved
|
||
| set -euo pipefail | ||
| curl -fsSL -o keycloak.tar.gz \ | ||
| "https://github.com/keycloak/keycloak/releases/download/${KEYCLOAK_VERSION}/keycloak-${KEYCLOAK_VERSION}.tar.gz" | ||
| tar -xzf keycloak.tar.gz | ||
| KC_HOME="${RUNNER_TEMP}/keycloak-${KEYCLOAK_VERSION}" | ||
| mkdir -p "${KC_HOME}/data/import" | ||
| cp "${GITHUB_WORKSPACE}/e2e/tests/auth/oauth2/fixtures/keycloak/realm-export.json" \ | ||
| "${KC_HOME}/data/import/realm-export.json" | ||
| echo "KC_HOME=${KC_HOME}" >> "${GITHUB_ENV}" | ||
| echo "Keycloak prepared at ${KC_HOME}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # OAuth2 e2e tests | ||
|
|
||
| The `oauth2` Playwright project drives real OAuth2 flows against a local Keycloak instance, | ||
| so Keycloak must be running before the specs start. | ||
|
|
||
| ## What the specs expect | ||
|
|
||
| - Keycloak reachable at `http://127.0.0.1:8090` | ||
| - The `bruno` realm imported from `fixtures/keycloak/realm-export.json` | ||
|
|
||
| CI provisions this through `.github/actions/auth/oauth2/setup-keycloak` and | ||
| `.github/actions/auth/oauth2/run-oauth2-e2e-tests`; keep the local setup below in step with them. | ||
|
|
||
| ## Running locally | ||
|
|
||
| Start Keycloak with the fixture realm imported: | ||
|
|
||
| ```bash | ||
| docker run -d --name bruno-keycloak -p 8090:8080 \ | ||
| -v "$PWD/e2e/tests/auth/oauth2/fixtures/keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro" \ | ||
| quay.io/keycloak/keycloak:26.3.3 start-dev --http-port=8080 --import-realm | ||
| ``` | ||
|
|
||
| Wait until `http://127.0.0.1:8090/realms/bruno` responds, then run the suite: | ||
|
|
||
| ```bash | ||
| npm run test:e2e:auth:oauth2 | ||
| ``` | ||
|
|
||
| Stop and remove the container when you are done: | ||
|
|
||
| ```bash | ||
| docker rm -f bruno-keycloak | ||
| ``` |
37 changes: 37 additions & 0 deletions
37
e2e/tests/auth/oauth2/fixtures/collection/AuthCodeUserSuppliedState.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| info: | ||
| name: AuthCodeUserSuppliedState | ||
| type: http | ||
| seq: 3 | ||
|
|
||
| http: | ||
| method: GET | ||
| url: "{{userinfo_url}}" | ||
| auth: | ||
| type: oauth2 | ||
| flow: authorization_code | ||
| authorizationUrl: "{{host}}/realms/{{realm}}/protocol/openid-connect/auth" | ||
| accessTokenUrl: "{{host}}/realms/{{realm}}/protocol/openid-connect/token" | ||
| callbackUrl: bruno://app/oauth2/callback | ||
| credentials: | ||
| clientId: bruno | ||
| clientSecret: "{{client_secret}}" | ||
| placement: body | ||
| scope: openid | ||
| state: brunoUserState | ||
| pkce: | ||
| disabled: true | ||
| tokenConfig: | ||
| id: credentials | ||
| placement: | ||
| header: Bearer | ||
| source: access_token | ||
| settings: | ||
| autoFetchToken: true | ||
| autoRefreshToken: false | ||
|
|
||
| settings: | ||
| encodeUrl: true | ||
| timeout: 0 | ||
| followRedirects: true | ||
| maxRedirects: 5 | ||
| forwardAuthorizationHeader: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.