Skip to content

Commit

Permalink
storage: fix signed url tests. fixes #238
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Sep 23, 2014
1 parent 50704b7 commit 1a176ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
20 changes: 0 additions & 20 deletions regression/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,5 @@ describe('storage', function() {
});
});
});

it('should allow control of expiration', function(done) {
var offsetSeconds = 5;
bucket.getSignedUrl({
action: 'read',
expires: Math.round(Date.now() / 1000) + offsetSeconds,
resource: filename
}, function(err, signedReadUrl) {
assert.ifError(err);
request.get(signedReadUrl, function(err, resp, body) {
assert.equal(body, localFile);
});
setTimeout(function() {
request.get(signedReadUrl, function(err, resp) {
assert.equal(resp.statusCode, 400);
bucket.remove(filename, done);
});
}, (offsetSeconds + 1) * 1000);
});
});
});
});
38 changes: 28 additions & 10 deletions test/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var assert = require('assert');
var gcloud = require('../../lib');
var storage = require('../../lib/storage');
var url = require('url');

var credentials = require('../testdata/privateKeyFile.json');
var noop = function() {};
Expand Down Expand Up @@ -142,15 +143,32 @@ describe('Bucket', function() {
bucket.remove('file-name');
});

it('should create a signed url', function(done) {
bucket.getSignedUrl({
action: 'read',
resource: 'filename',
expires: Date.now() / 1000
}, function(err, url) {
assert.ifError(err);
assert.equal(typeof url, 'string');
done();
});
describe('getSignedUrl', function() {
it('should create a signed url', function(done) {
bucket.getSignedUrl({
action: 'read',
expires: Math.round(Date.now() / 1000) + 5,
resource: 'filename'
}, function(err, signedUrl) {
assert.ifError(err);
assert.equal(typeof signedUrl, 'string');
done();
});
});

it('should use the provided expiration date', function(done) {
var nowInSeconds = Date.now() / 1000;
var expirationTimestamp = Math.round(nowInSeconds + 60);
bucket.getSignedUrl({
action: 'read',
resource: 'filename',
expires: expirationTimestamp
}, function(err, signedUrl) {
assert.ifError(err);
var expires = url.parse(signedUrl, true).query.Expires;
assert.equal(expires, expirationTimestamp);
done();
});
});
});
});

0 comments on commit 1a176ae

Please sign in to comment.