Files
floci/src/test/java
David 3d2b8828ad fix(lambda): honour the CodeSha256 precondition on PublishVersion (#2939)
* fix(lambda): honour the CodeSha256 precondition on PublishVersion

CodeSha256 is documented as a precondition: "only publish a version if the
hash value matches the value that's specified". The controller parsed only
Description out of the request body, so the field never reached the service
and a publish that should have been rejected succeeded and produced a
version. A caller that raced someone else's deploy published code it had
never authorised, with nothing to say so.

A mismatch is now InvalidParameterValueException carrying the message shape
AWS uses, and no version is created. The check sits inside the lock
UpdateFunctionCode takes, so the hash cannot be validated against one state
of $LATEST and the snapshot then taken from another.

Opt in: a request without the field behaves exactly as before, which
omittingCodeSha256StillPublishes pins.

Part of #2822; the unchanged-publish half follows separately because it
changes behaviour for existing callers.

* fix(lambda): close the CodeSha256 race and reject malformed preconditions

Two gaps found in review of the precondition itself.

The check was not atomic with UpdateFunctionCode. The earlier claim that it
sat inside that lock was wrong: extractZipCodeBytes sets codeLocalPath,
codeSizeBytes and codeSha256 with no lock held, and the only synchronized
block in there wraps an unrelated legacy-directory cleanup further down. So
PublishVersion holding its own lock serialised nothing, and a deploy landing
between the hash matching and the snapshot being taken still published code
the caller had not authorised.

Make the writer take the lock. Hashing stays outside it, being pure
computation on bytes already in hand, as does extraction to disk so a large
package does not serialise unrelated work; only the fields that decide what
a snapshot copies are published inside it.

A malformed precondition also bypassed the check. {"CodeSha256": 12345}
throws a ClassCastException into the body-parse catch, leaving the field
null and indistinguishable from omitted, so the publish succeeded with 201.
An unparseable body behaved the same way. Both are now 400: field extraction
rejects a wrong JSON type rather than letting the cast fail silently, and a
body that cannot be parsed is an error rather than an empty request.

* fix(lambda): reject a null JSON body on PublishVersion

A body of literal "null" is valid JSON that parses cleanly to a null map, so
it never reaches the parse-failure path and then threw a
NullPointerException on the field reads, surfacing as a 500 rather than a
400.

Guarded outside the try rather than inside it. Inside, the exception would
be caught by that method's own catch and rewrapped as a parse failure, which
it is not, giving "Could not parse request body: Request body must be a JSON
object".

* fix(lambda): compare a blank CodeSha256 rather than treating it as absent

An isBlank() check short-circuited the whole condition, so an explicit empty
or whitespace-only CodeSha256 skipped the comparison and published without
checking anything: the same present-but-malformed value behaving like an
absent one that the rest of this branch addresses.

The exclusion is simply removed, so an empty string is compared like any
other value and fails as a mismatch. Rejecting it with a dedicated error
would mean inventing an error shape for the empty case that has not been
measured against the live service; a mismatch is one AWS demonstrably
produces for a hash that does not match.
2026-09-02 18:41:14 -04:00
..