Tutorial: API Keys#3019
Conversation
Added comprehensive tutorials covering API Key Authentication, RBAC, OpenAPI integration, JDBC, and MongoDB key stores. Included corresponding test suites to validate behavior.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds API key security tutorial YAML files, a fruitshop OpenAPI spec, demo key data, JUnit 5 integration tests, and a MongoDB API key store null-scope fix. ChangesAPI Key Security Tutorials
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
distribution/tutorials/security/fruitshop-api-v2-openapi-3-security.yml (1)
792-795: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winUse standard OpenAPI format names here.
urlanddatetimeare not the standard OpenAPI 3.0.3 format names most tooling expects, so generators/validators may ignore them. Preferurianddate-timein this tutorial spec.Also applies to: 921-927, 1064-1066
🤖 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 `@distribution/tutorials/security/fruitshop-api-v2-openapi-3-security.yml` around lines 792 - 795, Update the OpenAPI tutorial spec to use standard format names so tooling recognizes them: in the SelfLink schema and the other referenced examples, replace nonstandard format values in the relevant schema definitions with the OpenAPI 3.0.3 equivalents. Focus on the affected properties in the tutorial YAML and keep the changes consistent wherever the same pattern appears.
🤖 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
`@distribution/src/test/java/com/predic8/membrane/tutorials/security/ApiKeyOpenApiTutorialTest.java`:
- Around line 28-45: The test in enforcesOpenApiSecurityRequirements only covers
the unauthorized and forbidden branches, so extend it with the authorized-path
case as well. Add an assertion for POST /shop/v2/products using the documented
working X-Api-Key value (222) and verify the expected success response from the
OpenAPI spec (201), keeping the existing 401 and 403 checks intact.
In `@distribution/tutorials/security/140-MongoDB-API-Key-Store.yaml`:
- Around line 5-6: The MongoDB API key tutorial seeds a scope-less key without a
scopes field, but MongoDBApiKeyStore.getScopes() expects a list and will fail on
that document. Update the seeded demo key in this tutorial to include scopes: []
for the no-scope case, or adjust MongoDBApiKeyStore.getScopes() to treat a
missing scopes field as an empty set; use the demo-key / Valid key (no scopes)
steps as the main place to fix.
---
Nitpick comments:
In `@distribution/tutorials/security/fruitshop-api-v2-openapi-3-security.yml`:
- Around line 792-795: Update the OpenAPI tutorial spec to use standard format
names so tooling recognizes them: in the SelfLink schema and the other
referenced examples, replace nonstandard format values in the relevant schema
definitions with the OpenAPI 3.0.3 equivalents. Focus on the affected properties
in the tutorial YAML and keep the changes consistent wherever the same pattern
appears.
🪄 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: 62102bd4-c0af-4da8-8814-2dbbdbeacff7
📒 Files selected for processing (10)
distribution/src/test/java/com/predic8/membrane/tutorials/security/ApiKeyAuthenticationTutorialTest.javadistribution/src/test/java/com/predic8/membrane/tutorials/security/ApiKeyOpenApiTutorialTest.javadistribution/src/test/java/com/predic8/membrane/tutorials/security/ApiKeyRbacTutorialTest.javadistribution/tutorials/security/100-API-Key-Authentication.yamldistribution/tutorials/security/110-API-Key-RBAC.yamldistribution/tutorials/security/120-API-Key-OpenAPI.yamldistribution/tutorials/security/130-JDBC-API-Key-Store.yamldistribution/tutorials/security/140-MongoDB-API-Key-Store.yamldistribution/tutorials/security/demo-keys.txtdistribution/tutorials/security/fruitshop-api-v2-openapi-3-security.yml
|
This pull request needs "/ok-to-test" from an authorized committer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java`:
- Around line 84-85: `MongoDBApiKeyStore#getScopes` is returning a present empty
set when no scopes exist, which breaks the `ApiKeyStore#getScopes` contract
followed by `SimpleKeyStore`. Update the `getScopes` logic so that a missing or
null `scopes` field yields `Optional.empty()` instead of `Optional.of(new
HashSet<>())`, while still returning a populated set when scopes are present.
🪄 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: a5677bdf-9a00-4eb5-a915-c08e4fe4de75
📒 Files selected for processing (1)
core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java
|
/ok-to-test |
| @@ -0,0 +1,67 @@ | |||
| # yaml-language-server: $schema=https://www.membrane-api.io/v7.2.4.json | |||
| # | |||
| # Tutorial: JDBC API Key Store | |||
There was a problem hiding this comment.
This can be tested using a H2 database. See e.g. LoggingJDBCExampleTest.
There was a problem hiding this comment.
H2 only needs the driver no docker.
But I think the postgres is closer to the application of the users. And it is easier to create the users in the database.
Added comprehensive tutorials covering API Key Authentication, RBAC, OpenAPI integration, JDBC, and MongoDB key stores. Included corresponding test suites to validate behavior.
Summary by CodeRabbit
scopesfield.