Skip to content

storage: clone user-provided options #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var concat = require('concat-stream');
var createErrorClass = require('create-error-class');
var crypto = require('crypto');
var duplexify = require('duplexify');
var extend = require('extend');
var format = require('string-format-obj');
var fs = require('fs');
var hashStreamValidation = require('hash-stream-validation');
Expand Down Expand Up @@ -979,6 +980,8 @@ File.prototype.getSignedPolicy = function(options, callback) {
throw new Error('An expiration date cannot be in the past.');
}

options = extend({}, options);

var conditions = [
['eq', '$key', this.name],
{
Expand Down Expand Up @@ -1159,6 +1162,8 @@ File.prototype.getSignedUrl = function(options, callback) {
throw new Error('An expiration date cannot be in the past.');
}

options = extend({}, options);

options.action = {
read: 'GET',
write: 'PUT',
Expand Down
29 changes: 29 additions & 0 deletions test/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,20 @@ describe('File', function() {
});
});

it('should not modify the configuration object', function(done) {
var config = {
expires: Date.now() + 5
};

var originalConfig = extend({}, config);

file.getSignedPolicy(config, function(err) {
assert.ifError(err);
assert.deepEqual(config, originalConfig);
done();
});
});

it('should return an error if getCredentials errors', function(done) {
var error = new Error('Error.');

Expand Down Expand Up @@ -1642,6 +1656,21 @@ describe('File', function() {
});
});

it('should not modify the configuration object', function(done) {
var config = {
action: 'read',
expires: Date.now() + 5
};

var originalConfig = extend({}, config);

file.getSignedUrl(config, function(err) {
assert.ifError(err);
assert.deepEqual(config, originalConfig);
done();
});
});

it('should return an error if getCredentials errors', function(done) {
var error = new Error('Error.');

Expand Down