Repository navigation
Feat/oauth2 keyclock cicd setup zip - #8572
abhishekp-bruno wants to merge 21 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis 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. ChangesOAuth2 E2E validation
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
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
8df9b8c to
1664fcd
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
tests/auth/oauth2/oauth2-state-validation.spec.ts (2)
163-170: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the commented-out assertion referencing an undefined constant.
Line 168 references
STATE_NONCE_HEX_LENGTHwhich 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 valueUpdate the Docker quick-start comment to match the CI Keycloak version and port.
The comment references
quay.io/keycloak/keycloak:26.0but the CI actions use26.3.3. The Docker command also maps-p 8090:8080with--http-port=8080, while the CI uses--http-port=8090directly. 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 winAdd
set -euo pipefailfor consistency with the Linux action.The Linux counterpart uses
set -euo pipefailbut this macOS action does not. Currently failures propagate becausenpmis the sole command, but adding more commands later withoutset -ecould 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
📒 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.ymlpackage.jsonpackages/bruno-electron/src/utils/oauth2.jsplaywright.config.tstests/auth/oauth2/fixtures/collection/AuthCodeUserSuppliedState.brutests/auth/oauth2/fixtures/collection/AuthorizationCode.brutests/auth/oauth2/fixtures/collection/AuthorizationImplicit.brutests/auth/oauth2/fixtures/collection/ImplicitUserSuppliedState.brutests/auth/oauth2/fixtures/collection/bruno.jsontests/auth/oauth2/fixtures/collection/environments/Local.brutests/auth/oauth2/fixtures/keycloak/realm-export.jsontests/auth/oauth2/init-user-data/preferences.jsontests/auth/oauth2/oauth2-state-validation.spec.ts
| try { | ||
| npm run test:e2e:auth:oauth2 | ||
| } finally { | ||
| if ($kc -and -not $kc.HasExited) { Stop-Process -Id $kc.Id -Force -ErrorAction SilentlyContinue } | ||
| } |
There was a problem hiding this comment.
🩺 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.
| 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.
There was a problem hiding this comment.
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 winAdd 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
📒 Files selected for processing (3)
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2ActionButtons/index.jstests/auth/oauth2/fixtures/keycloak/realm-export.jsontests/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
| const clearOauth2Error = () => { | ||
| dispatch(responseCleared({ itemUid: item.uid, collectionUid })); | ||
| }; | ||
|
|
There was a problem hiding this comment.
🎯 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.
…tate handling logic
… 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.
dddbc14 to
1d05927
Compare
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:
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
statevalidation.oauth2Playwright project andtest:e2e:auth:oauth2script.