Skip to content

Commit

Permalink
throw if trying to use validation with a range request
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Aug 27, 2015
1 parent cd9f7ba commit 0602fd4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ File.prototype.createReadStream = function(options) {
}

if (rangeRequest) {
if (is.string(options.validation) || options.validation === true) {
throw new Error('Cannot use validation with file ranges (start/end).');
}
// Range requests can't receive data integrity checks.
crc32c = false;
md5 = false;
Expand Down
32 changes: 31 additions & 1 deletion test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ describe('File', function() {
mockery.registerMock('sse4_crc32', crc32c);

mockery.registerMock('configstore', FakeConfigStore);
// mockery.registerMock('duplexify', FakeDuplexify);
mockery.registerMock('request', fakeRequest);
mockery.registerMock('../common/util.js', fakeUtil);
mockery.enable({
Expand Down Expand Up @@ -451,6 +450,37 @@ describe('File', function() {
return FakeFailedRequest;
}

it('should throw if both a range and validation is given', function() {
assert.throws(function() {
file.createReadStream({
validation: true,
start: 3,
end: 8
});
}, /Cannot use validation with file ranges/);

assert.throws(function() {
file.createReadStream({
validation: true,
start: 3
});
}, /Cannot use validation with file ranges/);

assert.throws(function() {
file.createReadStream({
validation: true,
end: 8
});
}, /Cannot use validation with file ranges/);

assert.doesNotThrow(function() {
file.createReadStream({
start: 3,
end: 8
});
});
});

it('should send query.generation if File has one', function(done) {
var versionedFile = new File(bucket, 'file.txt', { generation: 1 });

Expand Down

0 comments on commit 0602fd4

Please sign in to comment.