Skip to content

Feat/oauth2 keyclock cicd setup zip - #8572

Closed
abhishekp-bruno wants to merge 21 commits into
usebruno:mainfrom
abhishekp-bruno:feat/oauth2-keyclock-cicd-setup-zip
Closed

abhishekp-bruno wants to merge 21 commits into
usebruno:mainfrom
abhishekp-bruno:feat/oauth2-keyclock-cicd-setup-zip

Conversation

@abhishekp-bruno

@abhishekp-bruno abhishekp-bruno commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

BRU-3817

Description

Adds CI/CD infrastructure to run OAuth2 end-to-end tests against a real Keycloak identity provider across Linux, macOS, and Windows. This gives us a reproducible, containerized auth server in CI so OAuth2 flows can be validated automatically on every run.

CI/CD & Keycloak Setup
Added a Keycloak realm export (realm-export.json) that provisions the clients, users, and settings needed to exercise the OAuth2 flows — no manual auth-server configuration required.
Wired the Keycloak setup and test execution into the CI pipeline, with dedicated handling for the Windows environment.
Standardized the Keycloak URL to use IPv4 for consistent behavior across all three platforms.
Added collection fixtures, environments, and preferences to drive the flows against the Keycloak instance.
Updated playwright.config.ts to include the new OAuth2 suite.

Tests
Added OAuth2 Authorization Code and Implicit flow tests for CSRF testing.

Testing
OAuth2 e2e suite runs against Keycloak and passes across Linux, macOS, and Windows CI runners.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features
    • Added Playwright OAuth 2.0 E2E coverage for authorization code and implicit grant flows, including OAuth2 state validation.
    • Introduced a new dedicated oauth2 Playwright project and test:e2e:auth:oauth2 script.
    • Added cross-platform (Linux, macOS, Windows) local Keycloak setup and automated OAuth2 E2E execution, with Playwright report artifacts uploaded per OS.
  • Bug Fixes
    • Clears any prior OAuth2 error state when token fetching succeeds (before showing the success toast).

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 25e968ec-e1fc-4748-a2a8-c49d23e0a342

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This change adds OAuth2 Playwright coverage for authorization-code and implicit flows, Bruno fixtures, a Keycloak realm fixture, platform-specific setup actions, CI jobs, and OAuth2 response-state clearing.

Changes

OAuth2 E2E validation

Layer / File(s) Summary
OAuth2 project and test data
package.json, playwright.config.ts, tests/auth/oauth2/fixtures/..., tests/auth/oauth2/init-user-data/preferences.json
Adds the OAuth2 Playwright project and npm script, Bruno fixtures, Keycloak realm data, and initial Electron preferences.
Cross-platform Keycloak provisioning
.github/actions/auth/oauth2/{linux,macos,windows}/setup-keycloak/action.yml
Installs or verifies Java 21, prepares Keycloak, imports the bruno realm, and waits for realm readiness.
CI execution and reporting
.github/actions/auth/oauth2/{linux,macos,windows}/run-oauth2-e2e-tests/action.yml, .github/workflows/tests-{linux,macos,windows}.yml
Adds OAuth2 test jobs and platform-specific actions that run tests and upload reports.
State handling and validation
packages/bruno-app/.../Oauth2ActionButtons/index.js, tests/auth/oauth2/oauth2-state-validation.spec.ts, packages/bruno-electron/src/utils/oauth2.js
Clears prior OAuth2 errors after successful token retrieval and tests matching or mismatched state values for authorization-code and implicit flows.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI
  participant Keycloak
  participant Bruno
  participant Playwright
  CI->>Keycloak: Provision realm and wait for readiness
  CI->>Playwright: Run OAuth2 E2E project
  Playwright->>Bruno: Trigger OAuth2 token retrieval
  Bruno->>Keycloak: Open authorization flow
  Keycloak-->>Playwright: Return authorization response
  Playwright->>Bruno: Deliver callback URL
  Bruno-->>Playwright: Display success or state mismatch
Loading

Possibly related PRs

Suggested reviewers: helloanoop, naman-bruno, bijin-bruno, lohit-bruno, sid-bruno

Poem

Keycloak wakes, the tests take flight,
Across three platforms, day and night.
States agree—or errors show,
Callbacks dance in ordered flow,
Reports return in artifact light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references the OAuth2 Keycloak CI/CD setup, which matches the main change, though it is terse and misspelled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@abhishekp-bruno
abhishekp-bruno force-pushed the feat/oauth2-keyclock-cicd-setup-zip branch from 8df9b8c to 1664fcd Compare July 11, 2026 09:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
tests/auth/oauth2/oauth2-state-validation.spec.ts (2)

163-170: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the commented-out assertion referencing an undefined constant.

Line 168 references STATE_NONCE_HEX_LENGTH which is not defined anywhere in the file. This is dead code that should be removed or documented with context.

🧹 Proposed fix
 const getIssuedState = async (app: ElectronApplication): Promise<string> => {
   const authUrl = await getCapturedAuthUrl(app);
   expect(authUrl, 'authorization URL should have been opened').toBeTruthy();
   const state = stateFromAuthorizationUrl(authUrl as string);
   expect(state, 'issued state should be present on the authorization URL').toBeTruthy();
-  // expect((state as string).length).toBeGreaterThanOrEqual(STATE_NONCE_HEX_LENGTH);
   return state as string;
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/auth/oauth2/oauth2-state-validation.spec.ts` around lines 163 - 170,
Remove the commented-out STATE_NONCE_HEX_LENGTH assertion from getIssuedState,
leaving the existing state presence validation and return behavior unchanged.

1-8: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the Docker quick-start comment to match the CI Keycloak version and port.

The comment references quay.io/keycloak/keycloak:26.0 but the CI actions use 26.3.3. The Docker command also maps -p 8090:8080 with --http-port=8080, while the CI uses --http-port=8090 directly. A developer following this comment locally would run a different Keycloak version and port mapping than CI.

📝 Proposed fix for Docker comment
 // docker run -d --name bruno-keycloak \
-//   -p 8090:8080 \
+//   -p 8090:8090 \
 //   -e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
 //   -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
 //   -v <paste path of the file here>:/opt/keycloak/data/import/realm-export.json:ro \
-//   quay.io/keycloak/keycloak:26.0 \
-//   start-dev --http-port=8080 --import-realm
+//   quay.io/keycloak/keycloak:26.3.3 \
+//   start-dev --http-port=8090 --import-realm
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/auth/oauth2/oauth2-state-validation.spec.ts` around lines 1 - 8, Update
the Docker quick-start comment in the OAuth2 state validation test to use
Keycloak version 26.3.3, run with --http-port=8090, and remove the 8090:8080
port mapping so the command matches CI. Keep the remaining startup and realm
import options unchanged.
.github/actions/auth/oauth2/macos/run-oauth2-e2e-tests/action.yml (1)

8-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add set -euo pipefail for consistency with the Linux action.

The Linux counterpart uses set -euo pipefail but this macOS action does not. Currently failures propagate because npm is the sole command, but adding more commands later without set -e could silently mask failures.

♻️ Proposed fix
       run: |
+        set -euo pipefail
+
         npm run test:e2e:auth:oauth2
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/auth/oauth2/macos/run-oauth2-e2e-tests/action.yml around
lines 8 - 9, Update the shell script in the macOS OAuth2 E2E test action’s run
step to begin with set -euo pipefail, matching the Linux counterpart while
preserving the existing npm test command.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/actions/auth/oauth2/windows/run-oauth2-e2e-tests/action.yml:
- Around line 44-48: Update the test execution flow around the npm command and
its finally cleanup so a non-zero $LASTEXITCODE from npm run
test:e2e:auth:oauth2 is explicitly propagated after Keycloak cleanup. Preserve
the existing Stop-Process behavior, but ensure the PowerShell step exits with
the npm failure code instead of reporting success.

In `@tests/auth/oauth2/oauth2-state-validation.spec.ts`:
- Around line 272-303: Add test.setTimeout(60_000) at the start of both
state-mismatch tests, including the authorization-code test and the other
mismatch test around the corresponding state-validation case. Keep the existing
test steps and assertions unchanged.

---

Nitpick comments:
In @.github/actions/auth/oauth2/macos/run-oauth2-e2e-tests/action.yml:
- Around line 8-9: Update the shell script in the macOS OAuth2 E2E test action’s
run step to begin with set -euo pipefail, matching the Linux counterpart while
preserving the existing npm test command.

In `@tests/auth/oauth2/oauth2-state-validation.spec.ts`:
- Around line 163-170: Remove the commented-out STATE_NONCE_HEX_LENGTH assertion
from getIssuedState, leaving the existing state presence validation and return
behavior unchanged.
- Around line 1-8: Update the Docker quick-start comment in the OAuth2 state
validation test to use Keycloak version 26.3.3, run with --http-port=8090, and
remove the 8090:8080 port mapping so the command matches CI. Keep the remaining
startup and realm import options unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dca97fa7-8fd2-458b-a1c1-8dfb4c84f832

📥 Commits

Reviewing files that changed from the base of the PR and between 5346a72 and 1664fcd.

📒 Files selected for processing (21)
  • .github/actions/auth/oauth2/linux/run-oauth2-e2e-tests/action.yml
  • .github/actions/auth/oauth2/linux/setup-keycloak/action.yml
  • .github/actions/auth/oauth2/macos/run-oauth2-e2e-tests/action.yml
  • .github/actions/auth/oauth2/macos/setup-keycloak/action.yml
  • .github/actions/auth/oauth2/windows/run-oauth2-e2e-tests/action.yml
  • .github/actions/auth/oauth2/windows/setup-keycloak/action.yml
  • .github/workflows/tests-linux.yml
  • .github/workflows/tests-macos.yml
  • .github/workflows/tests-windows.yml
  • package.json
  • packages/bruno-electron/src/utils/oauth2.js
  • playwright.config.ts
  • tests/auth/oauth2/fixtures/collection/AuthCodeUserSuppliedState.bru
  • tests/auth/oauth2/fixtures/collection/AuthorizationCode.bru
  • tests/auth/oauth2/fixtures/collection/AuthorizationImplicit.bru
  • tests/auth/oauth2/fixtures/collection/ImplicitUserSuppliedState.bru
  • tests/auth/oauth2/fixtures/collection/bruno.json
  • tests/auth/oauth2/fixtures/collection/environments/Local.bru
  • tests/auth/oauth2/fixtures/keycloak/realm-export.json
  • tests/auth/oauth2/init-user-data/preferences.json
  • tests/auth/oauth2/oauth2-state-validation.spec.ts

Comment on lines +44 to +48
try {
npm run test:e2e:auth:oauth2
} finally {
if ($kc -and -not $kc.HasExited) { Stop-Process -Id $kc.Id -Force -ErrorAction SilentlyContinue }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Test failures are silently masked by the try/finally block.

$ErrorActionPreference = 'Stop' only affects PowerShell cmdlets, not external command exit codes. When npm run test:e2e:auth:oauth2 exits non-zero, PowerShell does not throw — the finally block runs (killing Keycloak), and the script exits 0. GitHub Actions marks the step green even when tests fail.

Explicitly check $LASTEXITCODE and propagate it:

🐛 Proposed fix to propagate npm exit code
         try {
           npm run test:e2e:auth:oauth2
+          if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
         } finally {
           if ($kc -and -not $kc.HasExited) { Stop-Process -Id $kc.Id -Force -ErrorAction SilentlyContinue }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
npm run test:e2e:auth:oauth2
} finally {
if ($kc -and -not $kc.HasExited) { Stop-Process -Id $kc.Id -Force -ErrorAction SilentlyContinue }
}
try {
npm run test:e2e:auth:oauth2
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally {
if ($kc -and -not $kc.HasExited) { Stop-Process -Id $kc.Id -Force -ErrorAction SilentlyContinue }
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/auth/oauth2/windows/run-oauth2-e2e-tests/action.yml around
lines 44 - 48, Update the test execution flow around the npm command and its
finally cleanup so a non-zero $LASTEXITCODE from npm run test:e2e:auth:oauth2 is
explicitly propagated after Keycloak cleanup. Preserve the existing Stop-Process
behavior, but ensure the PowerShell step exits with the npm failure code instead
of reporting success.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js (1)

64-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for OAuth2 error clearing.

Test the success-after-error flow and verify that clearing the OAuth2 error does not remove unrelated assertion or test-result state.

Also applies to: 90-90

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js`
around lines 64 - 67, Add regression tests around clearOauth2Error in the OAuth2
action-button flow, covering a successful request after an OAuth2 error and
verifying responseCleared only clears the OAuth2 error while preserving
unrelated assertion and test-result state.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js`:
- Around line 64-67: The clearOauth2Error handler currently dispatches
responseCleared, which also removes assertion and test-result data. Replace this
broad action with a narrower OAuth2 response/error-clearing action, or update
the responseCleared reducer contract to preserve those arrays while clearing
only the OAuth2 error state; keep the existing itemUid and collectionUid
targeting intact.

---

Nitpick comments:
In
`@packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js`:
- Around line 64-67: Add regression tests around clearOauth2Error in the OAuth2
action-button flow, covering a successful request after an OAuth2 error and
verifying responseCleared only clears the OAuth2 error while preserving
unrelated assertion and test-result state.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9cfaf563-b50a-4285-8258-b4542c280ace

📥 Commits

Reviewing files that changed from the base of the PR and between 69c0184 and dddbc14.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js
  • tests/auth/oauth2/fixtures/keycloak/realm-export.json
  • tests/auth/oauth2/oauth2-state-validation.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/auth/oauth2/fixtures/keycloak/realm-export.json
  • tests/auth/oauth2/oauth2-state-validation.spec.ts

Comment on lines +64 to +67
const clearOauth2Error = () => {
dispatch(responseCleared({ itemUid: item.uid, collectionUid }));
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Avoid clearing unrelated test results when removing the OAuth2 error.

responseCleared also resets assertion and test-result arrays in packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js:828-846. Calling it after token acquisition can erase existing test results even though this flow only needs to remove the OAuth2 error response. Use a narrower action or adjust the reducer contract to clear only the response/error state.

Also applies to: 90-90

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.js`
around lines 64 - 67, The clearOauth2Error handler currently dispatches
responseCleared, which also removes assertion and test-result data. Replace this
broad action with a narrower OAuth2 response/error-clearing action, or update
the responseCleared reducer contract to preserve those arrays while clearing
only the OAuth2 error state; keep the existing itemUid and collectionUid
targeting intact.

@abhishekp-bruno
abhishekp-bruno marked this pull request as draft July 16, 2026 08:51
… environment

- Changed the Keycloak setup action to only prepare the environment without starting the server.
- Updated the test execution action to start Keycloak and run OAuth2 E2E tests in the same step, ensuring the server remains active during the tests.
- Improved error handling and logging for Keycloak readiness checks.
- Changed error reporting from Write-Error to Write-Host for better visibility during test execution.
- Ensured that logs are still accessible when Keycloak is not ready.
…tests

- Introduced a new `clearOauth2Error` function to handle error clearing in the OAuth2 action buttons.
- Refactored test cases to utilize a common `startOAuth2Flow` function for improved readability and maintainability.
- Updated Keycloak configuration to enable public client support for better compatibility.
@abhishekp-bruno
abhishekp-bruno force-pushed the feat/oauth2-keyclock-cicd-setup-zip branch from dddbc14 to 1d05927 Compare July 16, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant