Skip to content

Commit

Permalink
Added accessTier check to download call for BlobHandler.ts to fail on… (
Browse files Browse the repository at this point in the history
#2483)

* Added accessTier check to download call for BlobHandler.ts to fail on archived blobs.

#2473

* Updated sas.test.ts test to handle new error.detail.code for Archived blob failure.

#2473

* Update sas.test.ts to fix sql failure

* Update blob.test.ts

---------

Co-authored-by: BrendonKleinhans <[email protected]>
Co-authored-by: Wei Wei <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent edaf26d commit 78a07e2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
## Upcoming Release

Blob:

- GetBlob on Archive tier blobs now fails as expected.

## 2024.10 Version 3.33.0

General:
Expand Down
4 changes: 4 additions & 0 deletions src/blob/handlers/BlobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export default class BlobHandler extends BaseHandler implements IBlobHandler {
options.modifiedAccessConditions
);

if (blob.properties.accessTier === Models.AccessTier.Archive) {
throw StorageErrorFactory.getBlobArchived(context.contextId!);
}

if (blob.properties.blobType === Models.BlobType.BlockBlob) {
return this.downloadBlockBlobOrAppendBlob(options, context, blob);
} else if (blob.properties.blobType === Models.BlobType.PageBlob) {
Expand Down
16 changes: 16 additions & 0 deletions tests/blob/apis/blob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ describe("BlobAPIs", () => {
assert.fail();
});

it("download should not work when blob in Archive tier @loki @sql", async () => {
try {

const result = await blobClient.setAccessTier("Archive");
assert.equal(
result._response.request.headers.get("x-ms-client-request-id"),
result.clientRequestId
);
await blobClient.download(0);
} catch (error) {
assert.deepStrictEqual(error.statusCode, 409);
return;
}
assert.fail();
});

it("download should not work with conditional header ifUnmodifiedSince @loki @sql", async () => {
try {
await blobClient.download(0, undefined, {
Expand Down
4 changes: 2 additions & 2 deletions tests/blob/sas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ describe("Shared Access Signature (SAS) authentication", () => {

const sourceBlob = sourceContainerClient.getBlockBlobClient(blobName);
await sourceBlob.upload("hello", 5);
sourceBlob.setAccessTier("Archive");
await sourceBlob.setAccessTier("Archive");

const targetBlob = targetContainerClient.getBlockBlobClient(blobName);

Expand All @@ -2122,7 +2122,7 @@ describe("Shared Access Signature (SAS) authentication", () => {
}
assert.ok(error !== undefined);
assert.equal(error.statusCode, 409);
assert.equal(error.details.code, "BlobArchived");
assert.equal(error.details.code, "CannotVerifyCopySource");
});

it("Sync Copy blob across accounts should work and honor metadata when provided @loki", async () => {
Expand Down

0 comments on commit 78a07e2

Please sign in to comment.