Azure / Azurite

A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
MIT License
1.8k stars 320 forks source link

Inconsistent error status code in Azurite and Azure when use the method beginCopyFromURL on block blob #633

Open zzhxiaofeng opened 3 years ago

zzhxiaofeng commented 3 years ago

Error Description: IfModifiedSince specify this conditional header to copy the blob from url only if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Azure returns status code 412 (Precondition Failed). But in Azurite, it returns status code 304. In azure, the error is shown as following: Screenshot 2020-11-19 152239 In azurite, the error is shown as following: Screenshot 2020-11-19 152155

To Reproduce Please run the demo code as following:

import {
  BlobServiceClient
} from "@azure/storage-blob";
import * as assert from "assert"

async function main() {
  const blobServiceClient = await BlobServiceClient.fromConnectionString("Azurite-https-connectionString");
  const containerClient = await blobServiceClient.getContainerClient("<container-name>");
  const originBlobClient = await containerClient.getBlockBlobClient("<origin-blob-name>");
  const newBlobClient = await containerClient.getBlockBlobClient("<new-blob-name>");

  try{
    await newBlobClient.beginCopyFromURL(originBlobClient.url,{sourceConditions:{
      ifModifiedSince:new Date()
    }})
  }catch(e){
    console.log((err as any).response.status);
    assert.ok((err as any).response.status === "412");
  }
}

main();

Error Track When use the method beginCopyFromURL on block blob in azurite, the process code and return error code for the ifModifiedSince are shown as following: https://github.com/Azure/Azurite/blob/master/src/blob/conditions/ReadConditionalHeadersValidator.ts#L90 https://github.com/Azure/Azurite/blob/master/src/blob/conditions/ReadConditionalHeadersValidator.ts#L107 Screenshot 2020-11-18 163331

Expected Behavior If the destination blob has not been modified in the date time specified by the ifModifiedSince, the error returned in Azurite is consistent with the one in Azure.

@jongio for notification.

blueww commented 3 years ago

@zzhxiaofeng Thanks for raising the issue! We will evaluate it.

We welcome contribution to Azurite. It would be great if you could contribute the the fix of this issue.

v-xuto commented 3 years ago

azsdk-azurite