From 6cb043a2faaf2401a80f164b81bb7fd849b14bcb Mon Sep 17 00:00:00 2001 From: "sophie.berry" Date: Thu, 25 May 2023 11:04:05 +0100 Subject: [PATCH] Fix error code when overwriting a blob without correct permissions --- ChangeLog.md | 1 + src/blob/authentication/BlobSASAuthenticator.ts | 2 +- src/blob/errors/StorageErrorFactory.ts | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index a8e7e25ae..01c7156d2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -8,6 +8,7 @@ Blob: - Fixed issue of: blob batch subresponse is slightly different from the on from Azure serivce, which causes exception in CPP SDK. - Fixed issue of: setMetadata API allows invalid metadata name with hyphen. +- Fixed issue of: error code not matching Azure blob storage is returned when overwriting existing blobs with incorrect permissions Table: diff --git a/src/blob/authentication/BlobSASAuthenticator.ts b/src/blob/authentication/BlobSASAuthenticator.ts index d61f43ce8..958a7b144 100644 --- a/src/blob/authentication/BlobSASAuthenticator.ts +++ b/src/blob/authentication/BlobSASAuthenticator.ts @@ -436,7 +436,7 @@ export default class BlobSASAuthenticator implements IAuthenticator { `BlobSASAuthenticator:validate() Account SAS validation failed for special requirement.`, context.contextId ); - throw StorageErrorFactory.getAuthorizationPermissionMismatch( + throw StorageErrorFactory.getUnauthorizedBlobOverwrite( context.contextId! ); } diff --git a/src/blob/errors/StorageErrorFactory.ts b/src/blob/errors/StorageErrorFactory.ts index 573fe45b6..f8a8c8d49 100644 --- a/src/blob/errors/StorageErrorFactory.ts +++ b/src/blob/errors/StorageErrorFactory.ts @@ -529,6 +529,17 @@ export default class StorageErrorFactory { ); } + public static getUnauthorizedBlobOverwrite( + contextID: string + ): StorageError { + return new StorageError( + 403, + "UnauthorizedBlobOverwrite", + "This request is not authorized to perform blob overwrites.", + contextID + ); + } + public static getAuthorizationServiceMismatch( contextID: string ): StorageError {