mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): check the RevisionId precondition in UpdateFunctionCode (#4641)
* fix(lambda): check the RevisionId precondition in UpdateFunctionCode Fixes #4639 - M1 PASS: RED run: [ERROR] io.github.hectorvent.floci.services.lambda.LambdaServiceTest.updateFunctionCode_withMismatchedRevisionId_throwsPreconditionFailedException -- Time elapsed: 0.457 s <<< FAILURE! - M2 PASS: gates green, last summary: [INFO] Tests run: 192, Failures: 0, Errors: 0, Skipped: 0 - M3 PASS: 2 file(s), all in scope - M4 PASS: no new public members in main code - M5 PASS: main diff 11 changed lines, limit 25 - M6 PASS: no em-dash in added lines - A1 PASS: `LambdaService.java:+671-+678` throws `AwsException("PreconditionFailedException", "...", 412)`; `LambdaServiceTest.java:+1780-+1781` asserts exact code, status, and message literals. - A2 PASS: `LambdaService.java:+671-+678` sits before all `fn.set...` calls; `LambdaServiceTest.java:+1770-+1788` captures `initialRevisionId` before call and asserts `unchangedFn.getRevisionId()` matches it. - A3 PASS: `LambdaServiceTest.java:+1790-+1794` sends matching RevisionId and asserts update succeeds; Gate 2 output `Tests run: 192, Failures: 0, Errors: 0, Skipped: 0` confirms no regression. - A4 PASS: `LambdaServiceTest.java:+1779` invokes public `service.updateFunctionCode(...)`; `LambdaServiceTest.java:+1780-+1781` asserts literal error code `"PreconditionFailedException"` and status `412`. - G1 PASS: `LambdaService.java:+671-+678` directly implements the missing optimistic locking logic identified in the diagnosis, not a test workaround. - G2 PASS: `LambdaServiceTest.java:+1780-+1781` asserts hardcoded literals for errorCode, httpStatus, and message; `LambdaServiceTest.java:+1788` asserts exact pre-call `initialRevisionId` value. - G3 PASS: Diff modifies only `LambdaService.java:+671-+678` (a guard clause); Gate 2 shows 0 failures across the full suite, proving other paths are untouched. - G4 PASS: `LambdaServiceTest.java:+1780-+1781` enforces AWS-correct `PreconditionFailedException` and `412`; `LambdaServiceTest.java:+1788` verifies state is unmutated after rejection. * refactor(lambda): share the RevisionId precondition check UpdateFunctionCode and UpdateFunctionConfiguration now call one helper. The stale-RevisionId test also asserts CodeSha256 is unchanged after the rejected call, so it fails if the check moves below code extraction. * fix(lambda): use the RevisionId mismatch message AWS returns
This commit is contained in:
1 parent
d0fec13cae
commit
b9625bf7f7
2 files changed
+53
-10
No files matched your search
@@ -2323,4 +2323,37 @@ class LambdaServiceTest {
|
||||
assertEquals("ValidationException", thrown.getErrorCode());
|
||||
assertEquals(400, thrown.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFunctionCode_withMismatchedRevisionId_throwsPreconditionFailedException() throws Exception {
|
||||
// Catches: UpdateFunctionCode silently accepts a stale RevisionId and overwrites the function's code
|
||||
// (the CodeSha256 assertion fails if the check ever runs after code extraction)
|
||||
Map<String, Object> createReq = baseRequest("revision-lock-func");
|
||||
service.createFunction(REGION, createReq);
|
||||
|
||||
LambdaFunction fn = service.getFunction(REGION, "revision-lock-func");
|
||||
String initialRevisionId = fn.getRevisionId();
|
||||
String initialCodeSha256 = fn.getCodeSha256();
|
||||
String mismatchingRevision = "stale-revision-id-abc123";
|
||||
String zipBase64 = createZipBase64("index.js");
|
||||
|
||||
Map<String, Object> updateReq = new HashMap<>();
|
||||
updateReq.put("ZipFile", zipBase64);
|
||||
updateReq.put("RevisionId", mismatchingRevision);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> service.updateFunctionCode(REGION, "revision-lock-func", updateReq));
|
||||
assertEquals("PreconditionFailedException", ex.getErrorCode());
|
||||
assertEquals(412, ex.getHttpStatus());
|
||||
assertEquals("The Revision Id provided does not match the latest Revision Id. Call the GetFunction/GetAlias API to retrieve the latest Revision Id", ex.getMessage());
|
||||
|
||||
LambdaFunction unchangedFn = service.getFunction(REGION, "revision-lock-func");
|
||||
assertEquals(initialRevisionId, unchangedFn.getRevisionId());
|
||||
assertEquals(initialCodeSha256, unchangedFn.getCodeSha256());
|
||||
|
||||
updateReq.put("RevisionId", initialRevisionId);
|
||||
service.updateFunctionCode(REGION, "revision-lock-func", updateReq);
|
||||
|
||||
LambdaFunction updatedFn = service.getFunction(REGION, "revision-lock-func");
|
||||
assertNotEquals(initialRevisionId, updatedFn.getRevisionId());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user