Skip to content

Commit 0a6b4d3

Browse files
jasoncheunggJason Cheung (INTUNE)
andauthored
Fixes Azurite V3 emulator not returning 412 Precondition Failed if a resource (blob) does not exist and "*" IfMatch is provided. (#2621)
* Fix * IfMatch for non-existent resource not throwing 412 Precondition Failed * Update ChangeLog.md --------- Co-authored-by: Jason Cheung (INTUNE) <cheungj@microsoft.com>
1 parent 4058f77 commit 0a6b4d3

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ General:
88

99
- Performance improvements for internal metadata access using in-memory metadata store
1010
- Fix building failure on Node 22 platform.
11+
- Fix * IfMatch for non-existent resource not throwing 412 Precondition Failed
1112

1213
## 2025.07 Version 3.35.0
1314

src/blob/conditions/WriteConditionalHeadersValidator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ export default class WriteConditionalHeadersValidator
102102
if (conditionalHeaders.ifMatch && conditionalHeaders.ifMatch.length > 0) {
103103
// If a request specifies both the If-Match and If-Unmodified-Since headers,
104104
// the request is evaluated based on the criteria specified in If-Match.
105-
if (conditionalHeaders.ifMatch[0] !== "*") {
106-
throw StorageErrorFactory.getConditionNotMet(context.contextId!);
107-
}
108-
return;
105+
// Throw if there is any value in if-match for non exist blob
106+
throw StorageErrorFactory.getConditionNotMet(context.contextId!);
109107
}
110108

111109
if (conditionalHeaders.ifModifiedSince) {

tests/blob/conditions.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,38 @@ describe("WriteConditionalHeadersValidator for nonexistent resource", () => {
830830

831831
assert.fail();
832832
});
833+
834+
it("Should throw 412 Precondition Failed for * if-match @loki @sql", () => {
835+
const validator = new WriteConditionalHeadersValidator();
836+
const modifiedAccessConditions = {
837+
ifMatch: "*"
838+
};
839+
840+
const expectedError = StorageErrorFactory.getConditionNotMet(
841+
context.contextId!
842+
);
843+
844+
try {
845+
validator.validate(
846+
context,
847+
new ConditionalHeadersAdapter(context, modifiedAccessConditions),
848+
new ConditionResourceAdapter(undefined)
849+
);
850+
} catch (error) {
851+
assert.deepStrictEqual(error.statusCode, expectedError.statusCode);
852+
assert.deepStrictEqual(
853+
error.storageErrorCode,
854+
expectedError.storageErrorCode
855+
);
856+
assert.deepStrictEqual(
857+
error.storageErrorMessage,
858+
expectedError.storageErrorMessage
859+
);
860+
return;
861+
}
862+
863+
assert.fail();
864+
});
833865
});
834866

835867
describe("WriteConditionalHeadersValidator for exist resource", () => {

0 commit comments

Comments
 (0)