-
Notifications
You must be signed in to change notification settings - Fork 7
fix: Adds webhook size limit parameter #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cd21257
fix: Adds webhook size limit parameter
f-nie c3a75a1
Identation
6ba0092
Merge branch 'main' into fix/webhook-size-limit
0a074bb
Adds unit test
9589488
Review comments addressed
63ca43e
Test case added
abba04b
Cleanup
5f22f14
Changes priority of configuration parameters
f-nie 4bd61b1
Test fixed
318695c
Adds documentation of new parameter
6b26c57
Update cds-plugin.js
f-nie 3057433
Test fix
dd6b5a5
Update docu
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
59 changes: 59 additions & 0 deletions
59
test/event-broker-unit-tests/event-broker-register-webhook.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| describe('event broker webhook endpoint registration', () => { | ||
| test.each([ | ||
| { | ||
| name: 'webhookSizeLimit correctly passed to express.json', | ||
| webhookPath: '/webhook-test', | ||
| webhookSizeLimit: '5mb', | ||
| bodyParserLimit: undefined, | ||
| expectedLimit: '5mb' | ||
| }, | ||
| { | ||
| name: 'body_parser.limit overrides webhookSizeLimit', | ||
| webhookPath: '/webhook-test-2', | ||
| webhookSizeLimit: '5mb', | ||
| bodyParserLimit: '42mb', | ||
| expectedLimit: '42mb' | ||
| } | ||
| ])('$name', async ({ webhookPath, webhookSizeLimit, bodyParserLimit, expectedLimit }) => { | ||
| // Arrange | ||
| const express = require('express') | ||
| const originalJson = express.json | ||
| let calledLimit | ||
| express.json = opts => { | ||
| calledLimit = opts.limit | ||
| return (req, res, next) => next() | ||
| } | ||
|
|
||
| const cds = require('@sap/cds') | ||
| const originalServer = cds.server | ||
| if (bodyParserLimit) { | ||
| cds.server = { body_parser: { limit: bodyParserLimit } } | ||
| } | ||
|
|
||
| const EventBroker = require('../../cds-plugin.js') | ||
| const eb = new EventBroker('event-broker') | ||
| eb.options = { | ||
| webhookPath, | ||
| webhookSizeLimit, | ||
| credentials: { | ||
| ias: { clientId: 'clientId' }, | ||
| } | ||
| } | ||
| eb.auth = { kind: 'ias', ias: { credentials: { certificate: 'cert', key: 'key' }, clientId: 'clientId' } } | ||
|
|
||
| const useMock = jest.fn() | ||
| const postMock = jest.fn() | ||
| cds.app = { use: useMock, post: postMock } | ||
|
|
||
| // Act | ||
| eb.registerWebhookEndpoints() | ||
|
|
||
| // Assert | ||
| expect(calledLimit).toBe(expectedLimit) | ||
|
|
||
| // Cleanup | ||
| express.json = originalJson | ||
| cds.server = originalServer | ||
| }) | ||
|
|
||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.