diff --git a/lib/external/s3.js b/lib/external/s3.js index f8f2467ab..ee77ba240 100644 --- a/lib/external/s3.js +++ b/lib/external/s3.js @@ -118,7 +118,9 @@ const init = (config) => { // * https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html#API_GetObject_RequestSyntax const getRespHeaders = (filename, { contentType }) => ({ 'response-content-disposition': contentDisposition(filename), - 'response-content-type': contentType, + // "null" is a questionable content-type, but matches current central behaviour + // See: https://github.com/getodk/central-backend/pull/1352 + 'response-content-type': contentType || 'null', }); async function urlForBlob(filename, blob) { diff --git a/test/e2e/s3/test-forms/1-attachments/cities.geojson b/test/e2e/s3/test-forms/1-attachments/cities.geojson new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/test/e2e/s3/test-forms/1-attachments/cities.geojson @@ -0,0 +1 @@ +{} diff --git a/test/e2e/s3/test-forms/1-attachments/some.nomime b/test/e2e/s3/test-forms/1-attachments/some.nomime new file mode 100644 index 000000000..5a70c362b --- /dev/null +++ b/test/e2e/s3/test-forms/1-attachments/some.nomime @@ -0,0 +1,2 @@ +I should not be uploaded with a mime type. +TODO what mime type should I be DOWNLOADED with? diff --git a/test/e2e/s3/test-forms/1.xml b/test/e2e/s3/test-forms/1.xml index 73e0e9bbb..668bf3d1b 100644 --- a/test/e2e/s3/test-forms/1.xml +++ b/test/e2e/s3/test-forms/1.xml @@ -49,6 +49,14 @@ Smile jr://images/smile.png + + geojson + jr://images/cities.geojson + + + geojson + jr://images/some.nomime + diff --git a/test/e2e/s3/test.js b/test/e2e/s3/test.js index 26fd2f84c..b94c2e75c 100644 --- a/test/e2e/s3/test.js +++ b/test/e2e/s3/test.js @@ -90,13 +90,13 @@ describe('s3 support', () => { // given await setup(1); - await assertNewStatuses({ pending: 11 }); + await assertNewStatuses({ pending: 13 }); // when await cli('upload-pending'); // then - await assertNewStatuses({ uploaded: 11 }); + await assertNewStatuses({ uploaded: 13 }); // and await assertAllRedirect(actualAttachments); await assertAllDownloadsMatchOriginal(actualAttachments); @@ -379,7 +379,10 @@ describe('s3 support', () => { const filepath = `${attDir}/${name}`; - const expectedContentType = mimetypeFor(name); + // "null" is a questionable content-type, but matches current central behaviour + // See: https://github.com/getodk/central-backend/pull/1352 + const expectedContentType = mimetypeFor(name) ?? 'null'; + const actualContentType = res.headers.get('content-type'); should.equal(actualContentType, expectedContentType); diff --git a/test/e2e/util/api.js b/test/e2e/util/api.js index 50773e355..1c9c5c1f4 100644 --- a/test/e2e/util/api.js +++ b/test/e2e/util/api.js @@ -46,7 +46,11 @@ async function apiClient(suiteName, { serverUrl, userEmail, userPassword, logPat }); } else { const { body, mimeType } = opts; - return apiPost(path, body, { 'Content-Type':mimeType }); + + const headers = {}; + if(mimeType) headers['Content-Type'] = mimeType; + + return apiPost(path, body, headers); } } @@ -119,14 +123,16 @@ function mimetypeFor(f) { // For more, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types const extension = extname(f); switch(extension) { - case '.bin' : return 'application/octet-stream'; - case '.jpg' : return 'image/jpeg'; - case '.png' : return 'image/png'; - case '.svg' : return 'image/svg+xml'; - case '.txt' : return 'text/plain'; - case '.xls' : return 'application/vnd.ms-excel'; - case '.xlsx': return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - case '.xml' : return 'application/xml'; + case '.bin' : return 'application/octet-stream'; + case '.geojson': return 'application/geo+json'; + case '.jpg' : return 'image/jpeg'; + case '.nomime' : return null; // used for testing user agents which do not set a mime type for some file extensions + case '.png' : return 'image/png'; + case '.svg' : return 'image/svg+xml'; + case '.txt' : return 'text/plain'; + case '.xls' : return 'application/vnd.ms-excel'; + case '.xlsx' : return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + case '.xml' : return 'application/xml'; default: throw new Error(`Unsure what mime type to use for: ${f}`); } }