From 5491ecabea8cdb1923c15d2f6be6046fc12bb9f0 Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Fri, 21 Jul 2023 01:10:01 -0700 Subject: [PATCH 1/6] "Update, Delete and Merge entities throw InvalidInput error for Malformed Etag" --- src/table/handlers/TableHandler.ts | 6 +-- tests/table/apis/table.entity.issues.test.ts | 51 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/table/handlers/TableHandler.ts b/src/table/handlers/TableHandler.ts index 7a7d80e82..c35f58a54 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, "Bad Request"); } } // check that key properties are valid @@ -466,7 +466,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { } if (options?.ifMatch && options.ifMatch !== "*" && options.ifMatch !== "") { if (isEtagValid(options.ifMatch)) { - throw StorageErrorFactory.getInvalidOperation(context); + throw StorageErrorFactory.getInvalidInput(context, "Bad Request"); } } @@ -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, "Bad Request"); } // 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..ced3228e7 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 { @@ -212,6 +213,56 @@ 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: partitionKey, + rowKey: rowKey, + ifMatch: malformedEtag + }).catch((reason) => { + const storageError = reason as StorageError; + assert.strictEqual(storageError.statusCode, "InvalidInput"); + assert.strictEqual(storageError.storageErrorCode, 400); + assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); + }); + + 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); + assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); + }); + + tableClient.mergeEntity({ + partitionKey: partitionKey, + rowKey: rowKey, + ifMatch: malformedEtag + }).catch((reason) => { + const storageError = reason as StorageError; + assert.strictEqual(storageError.statusCode, "InvalidInput"); + assert.strictEqual(storageError.storageErrorCode, 400); + assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); + }); + }); + // from issue #1214 it("should allow continuation tokens with non-ASCII characters, @loki", async () => { const partitionKey1 = createUniquePartitionKey("𤭢PK1"); From 2816f1344b09f086757ed604afe4bf4dfd90b91d Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Fri, 21 Jul 2023 01:46:54 -0700 Subject: [PATCH 2/6] Address comments --- src/table/handlers/TableHandler.ts | 6 +++--- tests/table/apis/table.entity.issues.test.ts | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/table/handlers/TableHandler.ts b/src/table/handlers/TableHandler.ts index c35f58a54..69e3867ef 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.getInvalidInput(context, "Bad Request"); + throw StorageErrorFactory.getInvalidInput(context); } } // check that key properties are valid @@ -466,7 +466,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { } if (options?.ifMatch && options.ifMatch !== "*" && options.ifMatch !== "") { if (isEtagValid(options.ifMatch)) { - throw StorageErrorFactory.getInvalidInput(context, "Bad Request"); + throw StorageErrorFactory.getInvalidInput(context); } } @@ -544,7 +544,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { throw StorageErrorFactory.getPreconditionFailed(context); } if (ifMatch !== "*" && isEtagValid(ifMatch)) { - throw StorageErrorFactory.getInvalidInput(context, "Bad Request"); + 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 ced3228e7..53d8e8e82 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -237,7 +237,6 @@ describe("table Entity APIs test : Issues", () => { const storageError = reason as StorageError; assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); - assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); }); tableClient.updateEntity({ @@ -248,7 +247,6 @@ describe("table Entity APIs test : Issues", () => { const storageError = reason as StorageError; assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); - assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); }); tableClient.mergeEntity({ @@ -259,7 +257,6 @@ describe("table Entity APIs test : Issues", () => { const storageError = reason as StorageError; assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); - assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); }); }); From 01f3b773a6230f48d79dc0865fe7d6600ba5fce2 Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Mon, 24 Jul 2023 00:13:49 -0700 Subject: [PATCH 3/6] Address comments --- tests/table/apis/table.entity.issues.test.ts | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/table/apis/table.entity.issues.test.ts b/tests/table/apis/table.entity.issues.test.ts index 53d8e8e82..eaed15ec8 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -217,7 +217,7 @@ describe("table Entity APIs test : Issues", () => { it("Malformed Etag when sent as input throws InvalidInput for table operations, ", async() => { const partitionKey = createUniquePartitionKey("𤭢PK1"); const malformedEtag = "MalformedEtag"; - const rowKey: "𐐷RK1" + const rowKey = "𐐷RK1" const tableClient = createAzureDataTablesClient( testLocalAzuriteInstance, tableName @@ -229,16 +229,17 @@ describe("table Entity APIs test : Issues", () => { rowKey: "𐐷RK1" }); - tableClient.deleteEntity({ - partitionKey: partitionKey, - rowKey: rowKey, - ifMatch: malformedEtag - }).catch((reason) => { - const storageError = reason as StorageError; - assert.strictEqual(storageError.statusCode, "InvalidInput"); - assert.strictEqual(storageError.storageErrorCode, 400); + 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, @@ -257,6 +258,7 @@ describe("table Entity APIs test : Issues", () => { const storageError = reason as StorageError; assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); + assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); }); }); From 324e0b34341c07c5ec06046ad6bf9d4cced3b1b4 Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Mon, 24 Jul 2023 00:14:31 -0700 Subject: [PATCH 4/6] Minor correction --- tests/table/apis/table.entity.issues.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/table/apis/table.entity.issues.test.ts b/tests/table/apis/table.entity.issues.test.ts index eaed15ec8..5f428044d 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -258,7 +258,6 @@ describe("table Entity APIs test : Issues", () => { const storageError = reason as StorageError; assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); - assert.strictEqual(storageError.storageErrorMessage, "Bad Request"); }); }); From a6c1e6dca8584a7cf45e18c9ec92024ee0a06d32 Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Mon, 31 Jul 2023 01:22:54 -0700 Subject: [PATCH 5/6] Fix build failure --- src/table/handlers/TableHandler.ts | 2 +- tests/table/apis/table.entity.issues.test.ts | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/table/handlers/TableHandler.ts b/src/table/handlers/TableHandler.ts index 69e3867ef..32fce5b81 100644 --- a/src/table/handlers/TableHandler.ts +++ b/src/table/handlers/TableHandler.ts @@ -466,7 +466,7 @@ export default class TableHandler extends BaseHandler implements ITableHandler { } if (options?.ifMatch && options.ifMatch !== "*" && options.ifMatch !== "") { if (isEtagValid(options.ifMatch)) { - throw StorageErrorFactory.getInvalidInput(context); + throw StorageErrorFactory.getInvalidOperation(context); } } diff --git a/tests/table/apis/table.entity.issues.test.ts b/tests/table/apis/table.entity.issues.test.ts index 5f428044d..a42766748 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -249,16 +249,6 @@ describe("table Entity APIs test : Issues", () => { assert.strictEqual(storageError.statusCode, "InvalidInput"); assert.strictEqual(storageError.storageErrorCode, 400); }); - - tableClient.mergeEntity({ - partitionKey: partitionKey, - rowKey: rowKey, - ifMatch: malformedEtag - }).catch((reason) => { - const storageError = reason as StorageError; - assert.strictEqual(storageError.statusCode, "InvalidInput"); - assert.strictEqual(storageError.storageErrorCode, 400); - }); }); // from issue #1214 From 5fd3ef153a4925d7d5ba41b8e418efc3b35aa0dd Mon Sep 17 00:00:00 2001 From: PrasantJillella <127192946+PrasantJillella@users.noreply.github.com> Date: Fri, 4 Aug 2023 15:03:46 -0700 Subject: [PATCH 6/6] Moving new tests to bottom of file --- tests/table/apis/table.entity.issues.test.ts | 76 ++++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/table/apis/table.entity.issues.test.ts b/tests/table/apis/table.entity.issues.test.ts index a42766748..3cc1b03f6 100644 --- a/tests/table/apis/table.entity.issues.test.ts +++ b/tests/table/apis/table.entity.issues.test.ts @@ -213,44 +213,6 @@ 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); - }); - }); - // from issue #1214 it("should allow continuation tokens with non-ASCII characters, @loki", async () => { const partitionKey1 = createUniquePartitionKey("𤭢PK1"); @@ -455,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); + }); + }); });