fix: validate simulator notification rules#123
Draft
goanpeca wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the simulator’s fidelity to the real B2 API by validating b2_set_bucket_notification_rules inputs (per Issue #17) so invalid notification rules are rejected before being stored/used, and updates related regression coverage and docs.
Changes:
- Added
validateNotificationRules()in the simulator validation layer (names, event types, webhook target type, https URL, and unknown-field rejection). - Wired the new validator into
B2Simulator.setBucketNotificationRulesso invalid rules return400instead of being stored. - Added/updated unit + fidelity tests and corrected
targetTypedocumentation to reflect'webhook'.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/notifications.ts | Updates notification rule docs/examples to use targetType: 'webhook'. |
| src/simulator/validation.ts | Adds validateNotificationRules() and supporting helpers/constants. |
| src/simulator/validation.test.ts | Adds unit tests for notification rule validation. |
| src/simulator/index.ts | Enforces notification rule validation in setBucketNotificationRules. |
| src/simulator/fidelity.test.ts | Adds simulator fidelity regression tests for invalid notification rules and updates existing expectations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+371
to
+386
| const eventTypes = ruleValue['eventTypes'] | ||
| if (!Array.isArray(eventTypes) || eventTypes.length === 0) { | ||
| return { | ||
| code: 'bad_request', | ||
| message: `${rulePath}.eventTypes must be a non-empty array`, | ||
| } | ||
| } | ||
| for (const eventType of eventTypes) { | ||
| if (typeof eventType !== 'string' || !KNOWN_NOTIFICATION_EVENT_TYPES.has(eventType)) { | ||
| return { | ||
| code: 'bad_request', | ||
| message: `${rulePath}.eventTypes contains an unknown event type`, | ||
| } | ||
| } | ||
| } | ||
|
|
Comment on lines
65
to
68
| readonly targetConfiguration: { | ||
| /** Target type (e.g., `'url'` for webhook delivery). */ | ||
| /** Target type (`'webhook'` for webhook delivery). */ | ||
| readonly targetType: string | ||
| /** Webhook URL that receives the event notifications. */ |
842293f to
8dd03b5
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Linked issue:
Tests run:
Follow-up notes: