Improved content API filter validation#26698
Conversation
ref https://linear.app/ghost/issue/ONC-1525/ - Improved field matching in `rejectPrivateFieldsTransformer` on public content API endpoints - Extracted the transformer into a shared utility
WalkthroughThis change extracts a commonly used transformer function ( 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@ghost/core/test/legacy/api/content/authors.test.js`:
- Around line 95-96: In authors.test.js replace the profanity placeholder throws
(e.g., "throw new Error('fuck')" at the two locations) with explicit test
assertions that convey the expected failure message and reason; for example use
the test framework's assertion helper such as assert.fail('Descriptive failure:
<what went wrong>') or expect(...).to.be.ok/expect.fail('Descriptive failure')
so tests fail with a clear, actionable message and include context (e.g., which
condition or helper caused the failure) — update both instances (around the two
noted locations) to use these explicit assertions instead of throwing an Error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1cb5326b-6013-4758-8fb7-b6ee49c3818d
📒 Files selected for processing (5)
ghost/core/core/server/api/endpoints/authors-public.jsghost/core/core/server/api/endpoints/pages-public.jsghost/core/core/server/api/endpoints/posts-public.jsghost/core/core/server/api/endpoints/utils/public-endpoint-utils.tsghost/core/test/legacy/api/content/authors.test.js
| throw new Error('fuck'); | ||
| } |
There was a problem hiding this comment.
Replace placeholder/profane failure throws with explicit assertions.
The new tests should fail with clear, actionable assertion messages instead of throw new Error('fuck').
Proposed cleanup
- if (data.authors.length === 1) {
- throw new Error('fuck');
- }
+ assert.notEqual(data.authors.length, 1, 'Filtering by users.password must not match private fields');
...
- if (data.authors.length === 1) {
- throw new Error('fuck');
- }
+ assert.notEqual(data.authors.length, 1, 'Filtering by users.email must not match private fields');Also applies to: 133-135
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ghost/core/test/legacy/api/content/authors.test.js` around lines 95 - 96, In
authors.test.js replace the profanity placeholder throws (e.g., "throw new
Error('fuck')" at the two locations) with explicit test assertions that convey
the expected failure message and reason; for example use the test framework's
assertion helper such as assert.fail('Descriptive failure: <what went wrong>')
or expect(...).to.be.ok/expect.fail('Descriptive failure') so tests fail with a
clear, actionable message and include context (e.g., which condition or helper
caused the failure) — update both instances (around the two noted locations) to
use these explicit assertions instead of throwing an Error.
🤖 Velo CI Failure AnalysisClassification: 🔴 HARD FAIL
|
ref https://linear.app/ghost/issue/ONC-1525/
rejectPrivateFieldsTransformeron public content API endpoints