Skip to content

Commit

Permalink
Fix #292 - 500 error when uploading zero-length file using Azure driver
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Feb 7, 2020
1 parent bb47992 commit 544513e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hub/src/server/drivers/AzDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ class AzDriver implements DriverModel, DriverModelTestMethods {
const blockBlobURL = azure.BlockBlobURL.fromBlobURL(blobURL)

// 1MB max buffer block size
const bufferSize = Math.min(1024 * 1024, args.contentLength)
const defaultBufferSize = 1024 * 1024
const bufferSize = Math.min(defaultBufferSize, args.contentLength) || defaultBufferSize

/**
* No parallelism since bottleneck would be in clients' http request
Expand Down
29 changes: 21 additions & 8 deletions hub/test/src/testDrivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ function testDriver(testName: string, mockTest: boolean, dataMap: {key: string,
t.equal(error.constructor.name, 'DoesNotExist', 'Should throw DoesNotExist trying to performRead on directory')
}
}
}

if (!mockTest) {

// test file stat on listFiles
try {
Expand Down Expand Up @@ -393,9 +390,6 @@ function testDriver(testName: string, mockTest: boolean, dataMap: {key: string,
t.error(error, 'File stat directory error')
}

}

if (!mockTest) {
sampleData = getSampleData();
const bogusContentType = 'x'.repeat(3000)
try {
Expand All @@ -409,6 +403,25 @@ function testDriver(testName: string, mockTest: boolean, dataMap: {key: string,
} catch (error) {
t.pass('Extremely large content-type headers should fail to write')
}

// test file write without content-length
const zeroByteTestFile = 'zero_bytes.txt'
const stream = new PassThrough()
stream.end(Buffer.alloc(0));
await driver.performWrite({
path: zeroByteTestFile,
storageTopLevel: topLevelStorage,
stream: stream,
contentType: 'text/plain; charset=utf-8',
contentLength: undefined
})
const readResult = await driver.performRead({
path: zeroByteTestFile,
storageTopLevel: topLevelStorage
})
t.equal(readResult.contentLength || 0, 0, 'Zero bytes file write should result in content-length read of 0');
const dataBuffer = await utils.readStream(readResult.data)
t.equal(dataBuffer.length, 0, 'Zero bytes file write should result in read of zero bytes');
}

try {
Expand Down Expand Up @@ -575,7 +588,7 @@ function testDriver(testName: string, mockTest: boolean, dataMap: {key: string,
stream: stream1,
contentType: 'text/plain; charset=utf-8',
contentLength: 100
});
}).catch(error => error);

const stream2 = new PassThrough()
stream2.write('xyz sample content 2', 'utf8')
Expand All @@ -587,7 +600,7 @@ function testDriver(testName: string, mockTest: boolean, dataMap: {key: string,
stream: stream2,
contentType: 'text/plain; charset=utf-8',
contentLength: 100
})
}).catch(error => error)
await utils.timeout(10)
stream1.end()
await utils.timeout(10)
Expand Down

0 comments on commit 544513e

Please sign in to comment.