Repository navigation
fix(apigatewayv2): return the v2 response shape an SDK parses (#529) - #567
Merged
Merged
Conversation
Every apigatewayv2 response marshaled a PascalCase state struct onto the wire under an "Items" envelope. botocore matches a response key against the model's locationName case-sensitively, so nothing substrate returned parsed: `aws apigatewayv2 create-api --query ApiId` printed None and `get-apis --query 'length(Items)'` failed on a null. Substrate's own AccountID and Region went out on every response too. Same remedy as v1 (#565) and MSK: the state types keep their PascalCase tags and are untouched, so state encoding is unchanged and recorded runs replay. Nine response-only element types tagged from the botocore model are projected from them, and none declares an AccountID or Region member at all, so the leak cannot return through a field added later. The five list envelopes emit "items". Three members are now absent, from the model rather than the previous code: a route, integration, stage and API mapping declare no apiId (the API is a path parameter, not a member), a domain name reports the regional hostname where v2 puts it — domainNameConfigurations[].apiGatewayDomainName — rather than under v1's regionalDomainName spelling, and no response carries a nextToken. The CloudFormation v2 deploy handlers read these responses to set a resource's physical ID and now read the wire spellings; they worked before only because Go's json.Unmarshal is case-insensitive, which is also why ~10 existing assertions were wrong today and passed anyway. Those CloudFormation tests asserted only a resource count, so they now assert the physical ID itself. Verified through botocore's own parser against a live server: 28 checks that returned None or an empty parse now return values, and 0 leaked fields.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6 tasks
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 #529.
The last of the three plugins. Every
apigatewayv2response marshaled a PascalCasestate struct straight onto the wire under an
Itemsenvelope, and botocore matches aresponse key against the model's
locationNamecase-sensitively — so nothingsubstrate returned parsed at all. Not a member missing here and there:
Note the two
AccountID/Regionkeys in the before-body: substrate's own bookkeepingwent out on every v2 response.
This was invisible over the wire until PR A (
15867b6) made v2 reachable by an SDK atall —
create-apiused to 404 withunknown operation for POST /v2/apis, which is why#529's "same check applied to API Gateway v2" criterion was unverifiable when it was
filed.
Remedy — the same one as #528, v1 (#565) and MSK
persisted format:
MemoryStateManagersnapshots them and recorded runs replay fromthose bytes. State encoding is unchanged, and
TestAPIGatewayV2Wire_StateEncodingUnchangedasserts the stored bytes still carry
ApiId/Name/ProtocolType/AccountID/Regionand that no wire spelling appears in state — so that is a fact, not a claim, and it is
the test that fails if someone later "fixes" a casing bug by retagging a state struct.
apigatewayv2_wire.go, each tagged from themodel, each with a
Wire()projection.AccountIDorRegionmember at all. The leak is fixedstructurally rather than by an
omitemptya future field could sidestep.items— lowercase, and note this differs fromv1's singular
item. The two spellings are not a typo in one of them; each wastranscribed from its own model.
v2APIMappingStatewas declared inline insidecreateAPIMappingand is now apackage-level type, because a wire projection needed to name it. Its tags are unchanged.
Why v2 was easier than v1, and why it was still done by hand
All 1,545 members of v2's response shapes are the plain lowerCamel of their member
names, against v1's ~230 irregular renames. The only irregular spellings anywhere in
the v2 model —
ResourceArn -> "resource-arn"— are on the three tag request shapes,which substrate does not route.
Each tag was still transcribed from the model rather than lowercased programmatically. A
mechanical transform is exactly what silently gets an exception wrong, and "there are no
exceptions" is a claim that has to be checked before it can be relied on — which is the
same mistake #529 as filed made about v1's envelope and about MSK.
Three members are now absent — from the model, not from the old code
apiId. The API is a pathparameter of the request, not a member of any of those four shapes. botocore discarded
the key regardless, so nothing observable is lost.
regionalDomainName. That spelling is v1's; v2 has notop-level equivalent and nests the regional hostname as
domainNameConfigurations[].apiGatewayDomainName. Substrate computes the hostnameeither way — projecting it into that list is what makes it visible to an SDK instead
of being dropped as an undeclared key.
nextToken. Substrate returns every element in one page andhonours no token; emitting an empty one would invite a caller to page on nothing.
Unset optionals are omitted rather than sent as
""ornull, following each member'soptionality in the model, because "absent" versus "null" is a real observable a caller
can branch on.
Existing assertions that were wrong today and passed anyway
This is the part of the diff that must not read as weakening tests.
Go's
json.Unmarshalmatches an object key against a struct tag case-insensitively.Measured, not assumed — a field tagged
json:"ApiId"and one taggedjson:"apiId"bothdecode
{"apiId":"abc123"}toabc123. That single fact is why this defect survived theentire life of the plugin: the request side worked, every Go round-trip test passed, and
an assertion struct with the wrong tags stayed green.
So two groups of consumers were wrong and silent:
cfn_resources_v19.go) decodeApiId,RouteId,IntegrationIdandAuthorizerIdout of these response bodies to set aresource's
PhysicalIDandARN. Retagged to the wire spellings.apigatewayv2_plugin_test.goandapigateway_proxy_test.goread
result["ApiId"],["IntegrationId"],["Items"]and decoded response bodiesinto
emulator.V2*State— the state type this change deliberately keeps off the wire.Rewritten to read literal wire keys.
And the CloudFormation v2 tests asserted only
assert.Len(t, result.Resources, N). Aphysical ID silently falling back to a logical ID or a route key would not have failed
one, so a resource count could stay green while every
Refin the stack pointed at thewrong thing. They now assert the ID itself.
Tests
apigatewayv2_wire_test.go, 13 tests, all decoding intomap[string]anyand assertingliteral wire keys — per #528's lesson that a struct marshaled and unmarshaled by its
own definition agrees with itself whatever its tags say.
Wire()thatforgets a member still emits its key holding Go's zero value. Reuses
requireKeys/requireValuesfrommsk_wire_test.go.five would pass while four were wrong.
bytes.Containsnegative assertions onAccountID,Region,accountIdand
region, so a nested occurrence cannot hide from a top-level map check._EmptyListsAreLists: a table over four collections asserting an empty collection is[]and notnull, and that nonextTokenappears._StateEncodingUnchanged, described above.domainNameConfigurations[0].apiGatewayDomainNameand that no top-levelregionalDomainNamesurvives.Mutation testing
38 mutants, 38 CAUGHT, 0 SURVIVED, 0 BROKEN, 0 ANCHOR-MISS, against a green baseline,
each anchor count-asserted before applying and each mutant gated through
gofmt -w+go vetand run with-race.Covered: a tag reverted to PascalCase on each of the nine element types; both envelope
reversions (
Items, and v1'sitem— the cross-version confusion is a real hazard);three list operations reverted independently;
AccountID/Regionadded back to two wiretypes; three single-resource returns left unprojected; nine
Wire()projections eachdropping one member; two
omitemptydrops; the three non-model members added back; analways-emitted
nextToken; a state struct retagged instead of the wire type; and theCloudFormation decode tags.
One mutant is worth recording because it was initially scored SURVIVED and is in fact
EQUIVALENT: reverting a CloudFormation decode tag to
json:"ApiId"leaves the testsgreen because it changes nothing — Go's case-insensitive decode, proven above. No test
can distinguish the two spellings. It was replaced with a mutant that does not case-fold
onto the wire key (
json:"restApiId"), which is CAUGHT, and that is what proves the newphysical-ID assertions have teeth. The comment in the harness records the measurement so
the next reader does not mistake it for a coverage gap.
Verified end to end through botocore's real parser
Against a live
substrate server, and againstmain @ 4305bafon a second port for thebefore-comparison quoted at the top. 28 checks that returned
Noneor an empty parsenow return values; 0 leaked fields. Every v2 resource type is covered — API, route,
integration, stage, authorizer (including
jwtConfigurationandidentitySource),deployment, domain name (both nested configuration members) and API mapping.
The AWS CLI presents these responses with PascalCase output keys (
--query ApiId,Items) because botocore mapslocationNameback to the member name. That is expected:the wire is
apiId, the CLI's own view of it isApiId, and the whole defect was thatthe mapping between them never happened.
One thing deliberately left out
aws apigatewayv2 get-api-mappingsfails withunknown operation for GET /v2/domainnames/{name}/apimappings— onlyPOSTon that path is routed. That is amissing operation, not a wrong response shape, so it is filed as #566 rather than
folded into a wire-format change. The shape work it needs is already done here
(
v2APIMappingOut,v2APIMappingWireand theapigwV2ItemsOut[T]envelope all exist andare tested), so it becomes a routing and state-indexing change.
create-api-mappingitself parses correctly today.
Verification
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
make test(race) green,make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./....docs/services.mdgains a Response shape paragraph for the v2 section: every memberlowerCamel, collections under
items, nonextToken, and the three absent members withthe reason for each. The operation table is unchanged — no plugin is added or removed.
Compatibility
Any consumer asserting a PascalCase member, an
AccountID/Regionfield, or anItemsenvelope on an API Gateway v2 response will go red. That is the fix — no AWS SDK could
parse the old shape — but a consumer who pinned to the broken shape needs to be told
plainly. State encoding is unchanged, so recorded runs replay.