Repository navigation
fix(iam): decode query-protocol scalar parameters (#642) - #643
Merged
Merged
Conversation
MaxItems failed every paginated IAM operation with 400 ValidationError, and CreateRole rejected MaxSessionDuration. Same root cause as #639, one layer along: the query protocol has no types, so server.go rebuilds req.Body as json.Marshal(req.Params) over a map[string]string and MaxItems=1 arrives as {"MaxItems":"1"}. A field declared `int` made encoding/json refuse the whole request. Where #639's lists unmarshaled to nil silently, an integer took the request down with it. iamInt and iamBool in iam_query.go accept either a JSON number or a numeric JSON string; all 14 MaxItems fields and MaxSessionDuration now use iamInt. iamBool lands unused so #497's OnlyAttached is not built with the defect already in it. An empty value is the zero value, not an error — a client that sent MaxItems= expressed no limit. A malformed value names its parameter via a json.UnmarshalTypeError, which is the one error type encoding/json annotates with the field path it was decoding, so the message is "MaxItems must be an integer, got \"abc\"" rather than a Go struct field. Found by probing ListUsers(MaxItems: 1) through the SDK while building #579, which makes this the third defect of the class. The unit suite cannot see it: iamRequest hand-marshals a body holding a real JSON number, the one shape no AWS client produces, and the IAM journeys never passed MaxItems because pagination is asserted at the unit level where the number is real. journey_iam_numbers_test.go closes that — it fails against the pre-fix code with exactly the 400 above, verified by reverting listUsers and re-running. Gates: gofmt clean, go build, go vet, golangci-lint 0 issues, make test (race), coverage 82.3% emulator / 81.6% total, test/e2e vet+test.
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 #642
What was broken
MaxItemsfailed every paginated IAM operation with400 ValidationError, andCreateRolerejectedMaxSessionDuration. Through the Go SDK:Why
The same root cause as #639, one layer along. IAM speaks the query protocol, so
ParseAWSRequestflattens the form body intoAWSRequest.Params(map[string]string) andserver.go:583-589rebuildsreq.Bodyasjson.Marshal(req.Params)— every value in thatJSON object is a string. A handler field declared
intmadeencoding/jsonrefuse thewhole request. Where #639's lists unmarshaled to nil in silence, an integer took the request
down with it.
The fix
iamIntandiamBoolinemulator/iam_query.goaccept either a JSON number or a numericJSON string. All 14
MaxItemsdeclarations andMaxSessionDurationnow useiamInt.iamBoollands unused so #497'sOnlyAttachedis not built with the defect already in it.Both shapes are accepted rather than only the string, because
iamRequest(
iam_plugin_test.go:40) hand-marshals a real JSON number — that asymmetry is precisely whathid this.
An empty value is the zero value rather than an error: a client that sent
MaxItems=expressed no limit, and refusing it would fail a request AWS accepts. A malformed value now
names its parameter —
MaxItems must be an integer, got "abc"— carried through a*json.UnmarshalTypeError, which is the one error typeencoding/jsonannotates with thefield path it was decoding (and it nests correctly for a scalar inside a list member).
How it was found, and why no test caught it
By probing
ListUsers(MaxItems: 1)through the SDK while building #579. That makes this thethird defect of the #561/#610/#636/#639 class. The unit suite structurally cannot see it:
iamRequestsends the one shape no AWS client produces, and the IAM journeys that do gothrough the SDK never passed
MaxItems, because pagination is asserted at the unit levelwhere the number is real.
test/e2e/journey_iam_numbers_test.gocloses that:MaxItemsacross two pages (assertingthe pages are disjoint and complete, so a Marker that silently restarted still fails) and
MaxSessionDurationround-tripped throughGetRole. Verified to fail against the pre-fixcode by reverting
listUsersand re-running — it reproduces the 400 above.Gates
gofmt -l .clean ·go build ./...·go vet ./...·golangci-lint run ./...→ 0issues ·
make test(race) ·make coverage→ emulator 82.3%, total 81.6% ·go vet -C test/e2e ./... && go test -C test/e2e ./...