Skip to content

fix(s3): parse a notification configuration off the wire (#542) - #553

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/s3-notification-xml
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/s3-notification-xml

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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

PutBucketNotificationConfiguration unmarshalled its request body into S3NotificationConfiguration, a struct carrying only json tags. Go's XML decoder falls back to matching Go field names when a field has no xml tag, and none of the API's element names are substrate's field names:

The API writes Substrate's field was
<TopicConfiguration> (singular) TopicConfigurations
<QueueConfiguration> QueueConfigurations
<CloudFunctionConfiguration> LambdaFunctionConfigurations
<Topic>, <Queue>, <CloudFunction> TopicArn, QueueArn, LambdaFunctionArn
repeated <Event> Events
<S3Key> Key

So a real-S3 body matched nothing.

What made it invisible: xml.Unmarshal reports 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 answered 200. 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

fireNotifications reads 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 json tags are untouched; wire types with the correct xml element names sit beside them with projections both ways.

EventBridgeConfiguration is now recognized, stored and reported. Delivery to EventBridge is still not dispatched — substrate has no bus-to-target path for S3 events — and docs/services.md says so rather than leaving it to be discovered.

fireNotifications and 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's json tags, 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:

$ curl -X PUT 'localhost:4621/notifbkt?notification' -d '<NotificationConfiguration>...'
200
$ curl 'localhost:4621/notifbkt?notification'
<NotificationConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><TopicConfiguration><Id>t1</Id>
<Topic>arn:aws:sns:us-east-1:123456789012:tp</Topic><Event>s3:ObjectCreated:Put</Event></TopicConfiguration>
<QueueConfiguration><Queue>...:notif-q</Queue><Event>s3:ObjectRemoved:*</Event><Filter><S3Key><FilterRule>
<Name>suffix</Name><Value>.log</Value></FilterRule></S3Key></Filter></QueueConfiguration>
<CloudFunctionConfiguration><CloudFunction>...:function:f</CloudFunction><Event>s3:ObjectCreated:*</Event>
</CloudFunctionConfiguration></NotificationConfiguration>

And the dispatch half, with the key filter applied:

$ aws s3api put-bucket-notification-configuration --bucket notifbkt \
    --notification-configuration '{"QueueConfigurations":[{...,"Filter":{"Key":{"FilterRules":[{"Name":"prefix","Value":"images/"}]}}}]}'
$ aws s3api put-object --bucket notifbkt --key docs/a.txt   --body f
$ aws sqs receive-message ...                       # {"Messages": []} — outside the prefix
$ aws s3api put-object --bucket notifbkt --key images/a.jpg --body f
$ aws sqs receive-message ...                       # s3:ObjectCreated:Put, images/a.jpg — was silence
$ curl -X PUT '...?notification' -d '<NotificationConfiguration><QueueConfigurations>...'   # 400 MalformedXML
$ curl '.../badbkt?notification'                    # empty NotificationConfiguration

Mutation testing

Nine mutants, all CAUGHT, none survived — anchor-count asserted before applying, gofmt -w && go vet gated, run under -race:

Mutant Caught by
TopicConfiguration reverted to plural — only that one AllThreeDestinations/topic
QueueConfiguration reverted to plural AllThreeDestinations/queue + 4 more
lambda element uses the SDK's LambdaFunctionConfigurations AllThreeDestinations/lambda
Event nests under a plural Events RealS3BodyRoundTrips, both dispatch tests
the wire filter's inner element named Key KeyFilterRoundTrips, KeyFilterAppliesOnDispatch
the MalformedXML refusal removed both UnrecognizedBodyIsMalformedXML subtests
fireNotifications reads a differently-keyed record both new dispatch tests and the pre-existing FireSQS
EventBridgeConfiguration never reported EventBridgeConfiguration
a queue's key filter dropped going into state KeyFilterRoundTrips, KeyFilterAppliesOnDispatch

The 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 now 400 MalformedXML instead of a 200 that stored nothing. A test that submits that shape and asserts 200 will 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. S3NotificationConfiguration gains one field, EventBridgeEnabled.

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

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/s3_plugin.go 74.00% 8 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 23e00f4 into main Aug 4, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/s3-notification-xml branch August 9, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3: PutBucketNotificationConfiguration parses XML by Go field name, so a real-S3 request body stores nothing and returns 200

1 participant