Fix openapi/jwt-auth example and add missing example test#2697
Conversation
|
/ok-to-test |
📝 WalkthroughWalkthroughMigrates the OpenAPI JWT auth example from XML (proxies.xml) to YAML (apis.yaml), inserts an empty Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant JWK as JWK Generator
participant TokenServer as Token Server
participant ProtectedAPI as Protected API
Client->>JWK: run generate-jwk (create jwk.json)
JWK-->>Client: jwk.json created
Client->>TokenServer: GET / (use jwk for signing)
TokenServer-->>Client: JWT
Client->>ProtectedAPI: GET /products (Authorization: Bearer JWT)
ProtectedAPI->>ProtectedAPI: validate JWT signature (using jwk.json)
ProtectedAPI-->>Client: 200 + products
Client->>ProtectedAPI: GET /products (no Authorization)
ProtectedAPI->>ProtectedAPI: security check fails
ProtectedAPI-->>Client: 400 security problem
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
This pull request needs "/ok-to-test" from an authorized committer. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@distribution/examples/openapi/jwt-auth/README.md`:
- Around line 17-22: The code block fence in the README contains an invalid
opener "```<yaml"; open the README code block that shows the "specs:" YAML
sample and replace the malformed fence with a proper "```yaml" fence so the
snippet renders correctly; specifically update the code fence around the YAML
sample that includes "specs:" / "openapi:" / "location: secure-shop-api.yml" /
"validateSecurity: true" to use a valid YAML code fence.
In
`@distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenApiJwtAuthExampleTest.java`:
- Line 18: Remove the incorrect static import of org.cef.OS.isWindows and either
replace it with the correct static import
com.predic8.membrane.core.util.OSUtil.isWindows or remove the import entirely
and call OSUtil.isWindows() directly; update the import statement and any call
sites in OpenApiJwtAuthExampleTest to use OSUtil.isWindows (the parent class
DistributionExtractingTestcase already uses that utility), ensuring no
references to org.cef remain.
🧹 Nitpick comments (1)
distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/openapi/OpenApiJwtAuthExampleTest.java (1)
91-96: Process output may not be fully captured afterwaitFor().Reading from
p.getInputStream()afterwaitFor()completes can miss output if the buffer was already full during execution (causing deadlock) or if the stream wasn't buffered. Consider reading the output concurrently or usingProcessBuilder.redirectErrorStream(true)with a buffered read during execution.A safer pattern:
♻️ Suggested improvement
private static void runGenerateJwk(File dir) throws Exception { File jwk = new File(dir, "jwk.json"); if (jwk.isFile() && jwk.length() > 0) return; Process p = createJwkProcess(dir); + // Read output during execution to prevent buffer deadlock + String output = new String(p.getInputStream().readAllBytes(), UTF_8); int exit = p.waitFor(); if (exit != 0) { - throw new IllegalStateException(MessageFormat.format("generate-jwk failed (exit {0}):\n{1}", exit, new String(p.getInputStream().readAllBytes(), UTF_8))); + throw new IllegalStateException(MessageFormat.format("generate-jwk failed (exit {0}):\n{1}", exit, output)); }
Summary by CodeRabbit
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.