|
21 | 21 | var assert = require('assert');
|
22 | 22 | var gcloud = require('../../lib');
|
23 | 23 | var storage = require('../../lib/storage');
|
| 24 | +var url = require('url'); |
24 | 25 |
|
25 | 26 | var credentials = require('../testdata/privateKeyFile.json');
|
26 | 27 | var noop = function() {};
|
@@ -142,15 +143,32 @@ describe('Bucket', function() {
|
142 | 143 | bucket.remove('file-name');
|
143 | 144 | });
|
144 | 145 |
|
145 |
| - it('should create a signed url', function(done) { |
146 |
| - bucket.getSignedUrl({ |
147 |
| - action: 'read', |
148 |
| - resource: 'filename', |
149 |
| - expires: Date.now() / 1000 |
150 |
| - }, function(err, url) { |
151 |
| - assert.ifError(err); |
152 |
| - assert.equal(typeof url, 'string'); |
153 |
| - done(); |
154 |
| - }); |
| 146 | + describe('getSignedUrl', function() { |
| 147 | + it('should create a signed url', function(done) { |
| 148 | + bucket.getSignedUrl({ |
| 149 | + action: 'read', |
| 150 | + expires: Math.round(Date.now() / 1000) + 5, |
| 151 | + resource: 'filename' |
| 152 | + }, function(err, signedUrl) { |
| 153 | + assert.ifError(err); |
| 154 | + assert.equal(typeof signedUrl, 'string'); |
| 155 | + done(); |
| 156 | + }); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should use the provided expiration date', function(done) { |
| 160 | + var nowInSeconds = Date.now() / 1000; |
| 161 | + var expirationTimestamp = Math.round(nowInSeconds + 60); |
| 162 | + bucket.getSignedUrl({ |
| 163 | + action: 'read', |
| 164 | + resource: 'filename', |
| 165 | + expires: expirationTimestamp |
| 166 | + }, function(err, signedUrl) { |
| 167 | + assert.ifError(err); |
| 168 | + var expires = url.parse(signedUrl, true).query.Expires; |
| 169 | + assert.equal(expires, expirationTimestamp); |
| 170 | + done(); |
| 171 | + }); |
| 172 | + }); |
155 | 173 | });
|
156 | 174 | });
|
0 commit comments