diff --git a/src/server/Uploader.js b/src/server/Uploader.js index 7bba45d1f0..317a2ab1f7 100644 --- a/src/server/Uploader.js +++ b/src/server/Uploader.js @@ -92,8 +92,9 @@ function validateOptions (options) { } // validate protocol - if (options.protocol == null || !Object.keys(PROTOCOLS).some((key) => PROTOCOLS[key] === options.protocol)) { - throw new ValidationError('please specify a valid protocol') + // @todo this validation should not be conditional once the protocol field is mandatory + if (options.protocol && !Object.keys(PROTOCOLS).some((key) => PROTOCOLS[key] === options.protocol)) { + throw new ValidationError('unsupported protocol specified') } // s3 uploads don't require upload destination @@ -206,7 +207,9 @@ class Uploader { } async _uploadByProtocol () { - const { protocol } = this.options + // todo a default protocol should not be set. We should ensure that the user specifies their protocol. + // after we drop old versions of uppy client we can remove this + const protocol = this.options.protocol || PROTOCOLS.multipart switch (protocol) { case PROTOCOLS.multipart: diff --git a/test/__tests__/companion.js b/test/__tests__/companion.js index fe6d2f7ee6..c71c624d37 100644 --- a/test/__tests__/companion.js +++ b/test/__tests__/companion.js @@ -36,7 +36,7 @@ describe('validate upload data', () => { protocol: 'tusInvalid', }) .expect(400) - .then((res) => expect(res.body.message).toBe('please specify a valid protocol')) + .then((res) => expect(res.body.message).toBe('unsupported protocol specified')) }) test('invalid upload fieldname gets rejected', () => { diff --git a/test/__tests__/uploader.js b/test/__tests__/uploader.js index 60ccb8f9bb..5a3422c7be 100644 --- a/test/__tests__/uploader.js +++ b/test/__tests__/uploader.js @@ -20,13 +20,10 @@ process.env.COMPANION_DATADIR = './test/output' process.env.COMPANION_DOMAIN = 'localhost:3020' const { companionOptions } = standalone() -const protocol = 'tus' - describe('uploader with tus protocol', () => { test('uploader respects uploadUrls', async () => { const opts = { endpoint: 'http://localhost/files', - protocol, companionOptions: { ...companionOptions, uploadUrls: [/^http:\/\/url.myendpoint.com\//] }, } @@ -36,7 +33,6 @@ describe('uploader with tus protocol', () => { test('uploader respects uploadUrls, valid', async () => { const opts = { endpoint: 'http://url.myendpoint.com/files', - protocol, companionOptions: { ...companionOptions, uploadUrls: [/^http:\/\/url.myendpoint.com\//] }, } @@ -47,7 +43,6 @@ describe('uploader with tus protocol', () => { test('uploader respects uploadUrls, localhost', async () => { const opts = { endpoint: 'http://localhost:1337/', - protocol, companionOptions: { ...companionOptions, uploadUrls: [/^http:\/\/localhost:1337\//] }, } @@ -231,7 +226,6 @@ describe('uploader with tus protocol', () => { const opts = { companionOptions, endpoint: 'http://localhost', - protocol, } // eslint-disable-next-line no-new @@ -253,7 +247,6 @@ describe('uploader with tus protocol', () => { test('uploader respects maxFileSize correctly', async () => { const opts = { endpoint: 'http://url.myendpoint.com/files', - protocol, companionOptions: { ...companionOptions, maxFileSize: 100 }, size: 99, }