Skip to content

Commit 211047c

Browse files
Kevin Norrisstephenplusplus
authored andcommitted
fix: signedURL cname (#210) (#234)
Fixes #210
1 parent eca993d commit 211047c

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

handwritten/storage/src/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ File.prototype.getSignedUrl = function(config, callback) {
18111811
const signedUrl = url.format({
18121812
protocol: parsedHost.protocol,
18131813
hostname: parsedHost.hostname,
1814-
pathname: self.bucket.name + '/' + name,
1814+
pathname: config.cname ? name : self.bucket.name + '/' + name,
18151815
query: query,
18161816
});
18171817

handwritten/storage/test/file.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,19 +2467,21 @@ describe('File', function() {
24672467
describe('cname', function() {
24682468
it('should use a provided cname', function(done) {
24692469
const host = 'http://www.example.com';
2470+
const configWithCname = extend({cname: host}, CONFIG);
24702471

2471-
file.getSignedUrl(
2472-
{
2473-
action: 'read',
2474-
cname: host,
2475-
expires: Date.now() + 2000,
2476-
},
2477-
function(err, signedUrl) {
2478-
assert.ifError(err);
2479-
assert.strictEqual(signedUrl.indexOf(host), 0);
2480-
done();
2481-
}
2482-
);
2472+
file.getSignedUrl(configWithCname, function(err, signedUrl) {
2473+
assert.ifError(err);
2474+
2475+
const expires = Math.round(CONFIG.expires / 1000);
2476+
const expected =
2477+
'http://www.example.com/file-name.png?' +
2478+
'GoogleAccessId=client-email&Expires=' +
2479+
expires +
2480+
'&Signature=signature';
2481+
2482+
assert.equal(signedUrl, expected);
2483+
done();
2484+
});
24832485
});
24842486

24852487
it('should remove trailing slashes from cname', function(done) {

0 commit comments

Comments
 (0)