Skip to content

Commit a256ecc

Browse files
committed
Merge pull request #1011 from stephenplusplus/spp--storage-1009
storage: clone user-provided options
2 parents f63eb9b + 2563001 commit a256ecc

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/storage/file.js

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var concat = require('concat-stream');
2424
var createErrorClass = require('create-error-class');
2525
var crypto = require('crypto');
2626
var duplexify = require('duplexify');
27+
var extend = require('extend');
2728
var format = require('string-format-obj');
2829
var fs = require('fs');
2930
var hashStreamValidation = require('hash-stream-validation');
@@ -979,6 +980,8 @@ File.prototype.getSignedPolicy = function(options, callback) {
979980
throw new Error('An expiration date cannot be in the past.');
980981
}
981982

983+
options = extend({}, options);
984+
982985
var conditions = [
983986
['eq', '$key', this.name],
984987
{
@@ -1159,6 +1162,8 @@ File.prototype.getSignedUrl = function(options, callback) {
11591162
throw new Error('An expiration date cannot be in the past.');
11601163
}
11611164

1165+
options = extend({}, options);
1166+
11621167
options.action = {
11631168
read: 'GET',
11641169
write: 'PUT',

test/storage/file.js

+29
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,20 @@ describe('File', function() {
13531353
});
13541354
});
13551355

1356+
it('should not modify the configuration object', function(done) {
1357+
var config = {
1358+
expires: Date.now() + 5
1359+
};
1360+
1361+
var originalConfig = extend({}, config);
1362+
1363+
file.getSignedPolicy(config, function(err) {
1364+
assert.ifError(err);
1365+
assert.deepEqual(config, originalConfig);
1366+
done();
1367+
});
1368+
});
1369+
13561370
it('should return an error if getCredentials errors', function(done) {
13571371
var error = new Error('Error.');
13581372

@@ -1642,6 +1656,21 @@ describe('File', function() {
16421656
});
16431657
});
16441658

1659+
it('should not modify the configuration object', function(done) {
1660+
var config = {
1661+
action: 'read',
1662+
expires: Date.now() + 5
1663+
};
1664+
1665+
var originalConfig = extend({}, config);
1666+
1667+
file.getSignedUrl(config, function(err) {
1668+
assert.ifError(err);
1669+
assert.deepEqual(config, originalConfig);
1670+
done();
1671+
});
1672+
});
1673+
16451674
it('should return an error if getCredentials errors', function(done) {
16461675
var error = new Error('Error.');
16471676

0 commit comments

Comments
 (0)