Ver código fonte

companion: validate upload protocol

Ifedapo Olarewaju 6 anos atrás
pai
commit
94a7167d17

+ 5 - 0
packages/@uppy/companion/src/server/Uploader.js

@@ -93,6 +93,11 @@ class Uploader {
    * @returns {boolean}
    */
   validateOptions (options) {
+    if (!Object.keys(PROTOCOLS).some((key) => PROTOCOLS[key] === options.protocol)) {
+      this._errRespMessage = 'Invalid upload protocol'
+      return false
+    }
+
     // s3 uploads don't require upload destination
     // validation, because the destination is determined
     // by the server's s3 config

+ 11 - 0
packages/@uppy/companion/test/__tests__/companion.js

@@ -63,6 +63,17 @@ describe('download provdier file', () => {
       .expect(200)
       .then((res) => expect(res.body.token).toBeTruthy())
   })
+
+  test('download should fail if protocol is not specified', () => {
+    return request(authServer)
+      .post('/drive/get/README.md')
+      .set('uppy-auth-token', token)
+      .set('Content-Type', 'application/json')
+      .send({
+        endpoint: 'http://master.tus.com/files'
+      })
+      .expect(400)
+  })
 })
 
 describe('test authentication', () => {