Skip to content

Commit

Permalink
Fixed issue of list container contains metadata even request doesn't …
Browse files Browse the repository at this point in the history
…have include=metadata (issue #2382) (#2389)

* Fixed issue of list container contains metadata even request doesn't have include=metadata (issue #2382)

* Fix a test issue
  • Loading branch information
blueww authored Apr 16, 2024
1 parent ad3114c commit 630ea56
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Blob:
- Fixed issue of setting blob tag should not update Blob Etag and LastModified. (issue #2327)
- Fix HTTP header parsing of `SubmitBatch()`. If a HTTP header has HTTP header delimiter (`:`) in its value, `SubmitBatch()` returns "400 One of the request inputs is not valid". For example, if `user-agent` header is `azsdk-cpp-storage-blobs/12.10.0-beta.1 (Darwin 23.1.0 arm64 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:12 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T8103)`, all `SubmitBatch()` requests are failed.
- Fixed issue of blob copying succeed without 'r' permission in source blob's SAS token credential.
- Fixed issue of list container contains metadata even request doesn't have include=metadata (issue #2382)

Table:

Expand Down
15 changes: 15 additions & 0 deletions src/blob/handlers/ServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ export default class ServiceHandler extends BaseHandler
marker
);

// Only the query parameter "include" contains the value "metadata" can the result present the metadata.
let includeMetadata = false;
if (options.include) {
for (const item of options.include) {
if (item.toLowerCase() === "metadata") {
includeMetadata = true;
break;
}
}
}
if (!includeMetadata) {
for (const container of containers[0]) {
container.metadata = undefined;
}
}
// TODO: Need update list out container lease properties with ContainerHandler.updateLeaseAttributes()
const serviceEndpoint = `${request.getEndpoint()}/${accountName}`;
const res: Models.ServiceListContainersSegmentResponse = {
Expand Down
2 changes: 1 addition & 1 deletion src/queue/handlers/ServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class ServiceHandler extends BaseHandler
let includeMetadata = false;
if (options.include) {
for (const item of options.include) {
if (item === "metadata") {
if (item.toLowerCase() === "metadata") {
includeMetadata = true;
break;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/blob/apis/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,32 @@ describe("ServiceAPIs", () => {
await containerClient1.delete();
await containerClient2.delete();
});

// fix issue 2382
it("ListContainers without include metadata should not return contaienr metadata. @loki @sql", async () => {
const containerNamePrefix = getUniqueName("container");
const containerName1 = `${containerNamePrefix}x1`;
const containerName2 = `${containerNamePrefix}x2`;
const containerClient1 = serviceClient.getContainerClient(containerName1);
const containerClient2 = serviceClient.getContainerClient(containerName2);
await containerClient1.create({ metadata: { key: "val" } });
await containerClient2.create({ metadata: { key: "val" } });

const result1 = (
await serviceClient
.listContainers({
prefix: containerNamePrefix
})
.byPage()
.next()
).value;

assert.equal(result1.containerItems!.length, 2);
assert.ok(result1.containerItems![0].name.startsWith(containerNamePrefix));
assert.ok(result1.containerItems![1].name.startsWith(containerNamePrefix));
assert.equal(result1.containerItems![0].metadata, undefined);
assert.equal(result1.containerItems![1].metadata, undefined);
});

it("get Account info @loki @sql", async () => {
const result = await serviceClient.getAccountInfo();
Expand Down

0 comments on commit 630ea56

Please sign in to comment.