diff --git a/ChangeLog.md b/ChangeLog.md index ff144413b..206be9982 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,9 @@ ## Upcoming Release +Table: +- Fixed the errorCode returned, when malformed Etag is provided for table Update/Delete calls. (issue #2013) + ## 2023.08 Version 3.26.0 General: diff --git a/src/table/handlers/TableHandler.ts b/src/table/handlers/TableHandler.ts index 7a7d80e82..32fce5b81 100644 --- a/src/table/handlers/TableHandler.ts +++ b/src/table/handlers/TableHandler.ts @@ -394,7 +394,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { } if (options?.ifMatch && options.ifMatch !== "*") { if (isEtagValid(options.ifMatch)) { - throw StorageErrorFactory.getInvalidOperation(context); + throw StorageErrorFactory.getInvalidInput(context); } } // check that key properties are valid @@ -544,7 +544,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { throw StorageErrorFactory.getPreconditionFailed(context); } if (ifMatch !== "*" && isEtagValid(ifMatch)) { - throw StorageErrorFactory.getInvalidOperation(context); + throw StorageErrorFactory.getInvalidInput(context); } // currently the props are not coming through as args, so we take them from the table context await this.metadataStore.deleteTableEntity( diff --git a/tests/table/apis/table.entity.issues.test.ts b/tests/table/apis/table.entity.issues.test.ts index 6e4b91a1e..3cc1b03f6 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -7,6 +7,7 @@ import { TableEntityResult } from "@azure/data-tables"; import { configLogger } from "../../../src/common/Logger"; +import StorageError from "../../../src/table/errors/StorageError"; import TableServer from "../../../src/table/TableServer"; import { getUniqueName } from "../../testutils"; import { @@ -416,4 +417,42 @@ describe("table Entity APIs test : Issues", () => { await tableClient.deleteTable(); }); + + //from issue #2013 + it("Malformed Etag when sent as input throws InvalidInput for table operations, ", async() => { + const partitionKey = createUniquePartitionKey("𤭢PK1"); + const malformedEtag = "MalformedEtag"; + const rowKey = "𐐷RK1" + const tableClient = createAzureDataTablesClient( + testLocalAzuriteInstance, + tableName + ); + + await tableClient.createTable(); + await tableClient.createEntity({ + partitionKey: partitionKey, + rowKey: "𐐷RK1" + }); + + tableClient.deleteEntity( + partitionKey, + rowKey, + { + etag: malformedEtag + } + ).catch((reason) => { + assert.strictEqual(reason.details.errorCode, "InvalidInput"); + assert.strictEqual(reason.statusCode, 400); + }); + + tableClient.updateEntity({ + partitionKey: partitionKey, + rowKey: rowKey, + ifMatch: malformedEtag + }).catch((reason) => { + const storageError = reason as StorageError; + assert.strictEqual(storageError.statusCode, "InvalidInput"); + assert.strictEqual(storageError.storageErrorCode, 400); + }); + }); });