Skip to content

Commit

Permalink
Fixes #272 use content-disposition library for blob
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsolt Lattmann committed Apr 3, 2015
1 parent 258d1a0 commit fd3c1db
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"commander": "=2.7.1",
"compression": "=1.4.3",
"connect-multiparty": "=1.2.5",
"content-disposition": "^0.5.0",
"cookie-parser": "=1.3.4",
"debug": "=2.1.3",
"express": "=4.12.3",
Expand Down
5 changes: 3 additions & 2 deletions src/server/middleware/blob/BlobServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
'use strict';

var mime = require('mime'),
BlobMetadata = requireJS('blob/BlobMetadata');
BlobMetadata = requireJS('blob/BlobMetadata'),
contentDisposition = require('content-disposition');

function createExpressBlob(__app, blobBackend, ensureAuthenticated, __logger) {
__app.get('/rest/blob/metadata', ensureAuthenticated, function (req, res) {
Expand Down Expand Up @@ -136,7 +137,7 @@ function createExpressBlob(__app, blobBackend, ensureAuthenticated, __logger) {
var mimeType = mime.lookup(filename);

if (download || mimeType === 'application/octet-stream' || mimeType === 'application/zip') {
res.setHeader('Content-disposition', 'attachment; filename=' + filename);
res.setHeader('Content-Disposition', contentDisposition(filename, {type: 'attachment'}));
}
res.setHeader('Content-type', mimeType);

Expand Down
52 changes: 48 additions & 4 deletions test/server/middleware/blob/BlobServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ describe('BlobServer', function () {
var gmeConfig = testFixture.getGmeConfig(),
agent = testFixture.superagent.agent(),
should = testFixture.should,
expect = testFixture.expect,
rimraf = testFixture.rimraf,
BlobClient = testFixture.BlobClient,
Artifact = testFixture.requirejs('blob/Artifact'),
contentDisposition = require('content-disposition'),
server,
serverBaseUrl,
bcParam = {};
Expand Down Expand Up @@ -120,8 +122,38 @@ describe('BlobServer', function () {
return;
}
agent.get(serverBaseUrl + '/rest/blob/download/' + hash).end(function (err, res) {
var checkContentDisposition = function () {
return contentDisposition.parse(res.header['content-disposition']);
};
should.equal(res.status, 200, err);
should.equal(res.header['content-disposition'], 'attachment; filename=notPublic.zip');
expect(checkContentDisposition).to.not.throw(TypeError);
should.equal(checkContentDisposition().parameters.filename, 'notPublic.zip');
done();
});
});
});
});

it('should download non-public artifact "Case (1).zip" at /rest/blob/download/valid-hash', function (done) {
var bc = new BlobClient(bcParam),
artifact = new Artifact('Case (1)', bc);
artifact.addFile('tt.txt', 'ttt', function (err/*, fHash*/) {
if (err) {
done(err);
return;
}
artifact.save(function (err, hash) {
if (err) {
done(err);
return;
}
agent.get(serverBaseUrl + '/rest/blob/download/' + hash).end(function (err, res) {
var checkContentDisposition = function () {
return contentDisposition.parse(res.header['content-disposition']);
};
should.equal(res.status, 200, err);
expect(checkContentDisposition).to.not.throw(TypeError);
should.equal(checkContentDisposition().parameters.filename, 'Case (1).zip');
done();
});
});
Expand All @@ -137,8 +169,12 @@ describe('BlobServer', function () {
return;
}
agent.get(serverBaseUrl + '/rest/blob/download/' + hash).end(function (err, res) {
var checkContentDisposition = function () {
return contentDisposition.parse(res.header['content-disposition']);
};
should.equal(res.status, 200, err);
should.equal(res.header['content-disposition'], 'attachment; filename=notPublic.zip');
expect(checkContentDisposition).to.not.throw(TypeError);
should.equal(checkContentDisposition().parameters.filename, 'notPublic.zip');
done();
});
});
Expand All @@ -158,8 +194,12 @@ describe('BlobServer', function () {
return;
}
agent.get(serverBaseUrl + '/rest/blob/view/' + hash).end(function (err, res) {
var checkContentDisposition = function () {
return contentDisposition.parse(res.header['content-disposition']);
};
should.equal(res.status, 200, err);
should.equal(res.header['content-disposition'], 'attachment; filename=notPublic.zip');
expect(checkContentDisposition).to.not.throw(TypeError);
should.equal(checkContentDisposition().parameters.filename, 'notPublic.zip');
done();
});
});
Expand All @@ -175,8 +215,12 @@ describe('BlobServer', function () {
return;
}
agent.get(serverBaseUrl + '/rest/blob/view/' + hash).end(function (err, res) {
var checkContentDisposition = function () {
return contentDisposition.parse(res.header['content-disposition']);
};
should.equal(res.status, 200, err);
should.equal(res.header['content-disposition'], 'attachment; filename=notPublic.zip');
expect(checkContentDisposition).to.not.throw(TypeError);
should.equal(checkContentDisposition().parameters.filename, 'notPublic.zip');
done();
});
});
Expand Down

0 comments on commit fd3c1db

Please sign in to comment.