Repository navigation
fix(s3): parse a notification configuration off the wire (#542) - #553
Merged
Merged
Conversation
PutBucketNotificationConfiguration unmarshalled its body into a struct carrying only json tags. Go's XML decoder falls back to matching field names, and none of the API's element names are substrate's field names: the wire is singular (TopicConfiguration), names the destination after the service (Topic, Queue, CloudFunction), repeats a bare Event, and calls the filter's inner element S3Key. A real-S3 body matched nothing. xml.Unmarshal reports no error for a body it recognised nothing in, so the JSON fallback never ran, an empty configuration was persisted, and the request answered 200. Since an empty configuration is the documented way to disable notifications, configuring one the AWS way turned notifications off — and fireNotifications reads the same record, so nothing was ever dispatched. Wire types beside the state struct with projections both ways, per the remedy #528 established: the struct is also the persisted encoding, so retagging it would have stranded existing records. A non-empty body naming no recognised element is now MalformedXML, without which the wrong element names stay indistinguishable from a deliberate disable.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #542
This is not a lost-configuration bug. It is a working feature that could not be turned on — every S3 event notification configured through the real API was silently off.
The cause
PutBucketNotificationConfigurationunmarshalled its request body intoS3NotificationConfiguration, a struct carrying onlyjsontags. Go's XML decoder falls back to matching Go field names when a field has noxmltag, and none of the API's element names are substrate's field names:<TopicConfiguration>(singular)TopicConfigurations<QueueConfiguration>QueueConfigurations<CloudFunctionConfiguration>LambdaFunctionConfigurations<Topic>,<Queue>,<CloudFunction>TopicArn,QueueArn,LambdaFunctionArn<Event>Events<S3Key>KeySo a real-S3 body matched nothing.
What made it invisible:
xml.Unmarshalreports no error for a body whose elements match no field. The handler's JSON fallback therefore never ran, an empty configuration was persisted, and the request answered200. Since an empty configuration is also the documented way to disable notifications, the effect of configuring a notification the AWS way was to turn notifications off.The half that isn't in the report
fireNotificationsreads that same record. With an empty configuration stored, no event was ever dispatched — a test asserting a message arrives failed far from its assertion, and one asserting no message arrives passed vacuously. That is the more serious half, and it is fixed by the same change.The remedy
Follows the one #528 established for CloudWatch Logs, because the struct is dual-role: it is also the persisted encoding, so retagging it would have fixed the wire and changed the stored format in the same edit, stranding existing records. The state struct and its
jsontags are untouched; wire types with the correctxmlelement names sit beside them with projections both ways.EventBridgeConfigurationis now recognized, stored and reported. Delivery to EventBridge is still not dispatched — substrate has no bus-to-target path for S3 events — anddocs/services.mdsays so rather than leaving it to be discovered.fireNotificationsand the API read now share one loader, so a read-back that passes while delivery stays broken is no longer reachable. The mutation run below confirms that: pointing the loader at a different key takes down both the new dispatch tests and the pre-existing one.Provenance
A non-empty body naming no recognized element is now
400 MalformedXML. Substrate's own choice, not the API model's. Without it, a body with the wrong element names stays indistinguishable from a deliberate disable — which is exactly how this defect stayed invisible for as long as it did. A genuinely empty<NotificationConfiguration/>still disables notifications, since that is documented; the two are told apart by whether the body named anything at all. Substrate's pre-existing JSON body form, keyed on the state shape'sjsontags, is still accepted.Two existing tests worth naming
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...— all clean.All 13 new gates fail before the fix (reverting
s3_types.go+s3_plugin.go, leaving the tests).Byte-for-byte round-trip against a live server — this body in, this body out:
And the dispatch half, with the key filter applied:
Mutation testing
Nine mutants, all CAUGHT, none survived — anchor-count asserted before applying,
gofmt -w && go vetgated, run under-race:TopicConfigurationreverted to plural — only that oneAllThreeDestinations/topicQueueConfigurationreverted to pluralAllThreeDestinations/queue+ 4 moreLambdaFunctionConfigurationsAllThreeDestinations/lambdaEventnests under a pluralEventsRealS3BodyRoundTrips, both dispatch testsKeyKeyFilterRoundTrips,KeyFilterAppliesOnDispatchMalformedXMLrefusal removedUnrecognizedBodyIsMalformedXMLsubtestsfireNotificationsreads a differently-keyed recordFireSQSEventBridgeConfigurationnever reportedEventBridgeConfigurationKeyFilterRoundTrips,KeyFilterAppliesOnDispatchThe first three are the plan's requirement that one element reverted at a time still goes red — a single test catching all five would not prove per-element coverage.
Compatibility
Substrate's old XML shape is no longer accepted: a body with
<QueueConfigurations>/<QueueArn>/<Events>is now400 MalformedXMLinstead of a200that stored nothing. A test that submits that shape and asserts200will go red; it was never storing a configuration. Rewrite it in the API's element names, or use the JSON form, which is unchanged.A test that asserted no notification arrives after configuring one the AWS way will also go red — the notification now arrives. That is the fix.
The persisted format is unchanged, so existing state records still load.
S3NotificationConfigurationgains one field,EventBridgeEnabled.