Skip to content

Commit 31b46f8

Browse files
author
alxndrsn
committed
blobs: prevent default contentType column
Set blob."contentType" values to application/octet-stream if no mime type is supplied on upload. Related: getodk#1351
1 parent 7574030 commit 31b46f8

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/model/query/blobs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const { construct } = require('../../util/util');
2222
const ensure = (blob) => ({ oneFirst }) => oneFirst(sql`
2323
with ensured as
2424
(insert into blobs (sha, md5, content, "contentType") values
25-
(${blob.sha}, ${blob.md5}, ${sql.binary(blob.content)}, ${blob.contentType || null})
25+
(${blob.sha}, ${blob.md5}, ${sql.binary(blob.content)}, ${blob.contentType || sql`DEFAULT`})
2626
on conflict (sha) do update set sha = ${blob.sha}
2727
returning id)
2828
select id from ensured`);

test/integration/api/submissions.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4377,8 +4377,7 @@ one,h,/data/h,2000-01-01T00:06,2000-01-01T00:07,-5,-6,,ee,ff
43774377
body.toString().should.equal('testvideo');
43784378
})))))));
43794379

4380-
// Ref https://github.com/getodk/central-backend/issues/1351
4381-
it('should attach a given file with empty Content-Type', testService((service) =>
4380+
it('should attach a given file with empty Content-Type and serve it with default mime type', testService((service) =>
43824381
service.login('alice', (asAlice) =>
43834382
asAlice.post('/v1/projects/1/forms?publish=true')
43844383
.set('Content-Type', 'application/xml')
@@ -4394,13 +4393,12 @@ one,h,/data/h,2000-01-01T00:06,2000-01-01T00:07,-5,-6,,ee,ff
43944393
.expect(200)
43954394
.then(() => asAlice.get('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
43964395
.expect(200)
4397-
.then(({ headers, text }) => {
4398-
headers['content-type'].should.equal('null');
4399-
text.toString().should.equal('testvideo'); // use 'text' instead of 'body' to avoid supertest response parsing
4396+
.then(({ headers, body }) => {
4397+
headers['content-type'].should.equal('application/octet-stream');
4398+
body.toString().should.equal('testvideo');
44004399
})))))));
44014400

4402-
// Ref https://github.com/getodk/central-backend/issues/1351
4403-
it('should attach a given file with missing Content-Type', testService((service) =>
4401+
it('should attach a given file with missing Content-Type and serve it with default mime type', testService((service) =>
44044402
service.login('alice', (asAlice) =>
44054403
asAlice.post('/v1/projects/1/forms?publish=true')
44064404
.set('Content-Type', 'application/xml')
@@ -4416,9 +4414,9 @@ one,h,/data/h,2000-01-01T00:06,2000-01-01T00:07,-5,-6,,ee,ff
44164414
.expect(200)
44174415
.then(() => asAlice.get('/v1/projects/1/forms/binaryType/submissions/both/attachments/my_file1.mp4')
44184416
.expect(200)
4419-
.then(({ headers, text }) => {
4420-
headers['content-type'].should.equal('null');
4421-
text.toString().should.equal('testvideo'); // use 'text' instead of 'body' to avoid supertest response parsing
4417+
.then(({ headers, body }) => {
4418+
headers['content-type'].should.equal('application/octet-stream');
4419+
body.toString().should.equal('testvideo');
44224420
})))))));
44234421

44244422
it('should log an audit entry about initial attachment', testService((service, { Audits, Forms, Submissions, SubmissionAttachments }) =>

0 commit comments

Comments
 (0)