Selaa lähdekoodia

companion: fix uploader protocol validation (#2197)

* companion: fix uploader protocol validation

fixes #2188

* test: use correct tus URL

* companion: make it support node 6
Ifedapo .A. Olarewaju 5 vuotta sitten
vanhempi
commit
b27d678161

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

@@ -173,7 +173,7 @@ class Uploader {
 
     // validate protocol
     // @todo this validation should not be conditional once the protocol field is mandatory
-    if (options.protocol && !Object.prototype.hasOwnProperty.call(PROTOCOLS, options.protocol)) {
+    if (options.protocol && !Object.keys(PROTOCOLS).some((key) => PROTOCOLS[key] === options.protocol)) {
       this._errRespMessage = 'unsupported protocol specified'
       return false
     }

+ 28 - 8
packages/@uppy/companion/test/__tests__/companion.js

@@ -73,7 +73,7 @@ describe('validate upload data', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tusInvalid'
       })
       .expect(400)
@@ -86,7 +86,7 @@ describe('validate upload data', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus',
         fieldname: 390
       })
@@ -100,7 +100,7 @@ describe('validate upload data', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus',
         metadata: 'I am a string instead of object'
       })
@@ -114,7 +114,7 @@ describe('validate upload data', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus',
         headers: 'I am a string instead of object'
       })
@@ -128,7 +128,7 @@ describe('validate upload data', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus',
         httpMethod: 'DELETE'
       })
@@ -136,14 +136,34 @@ describe('validate upload data', () => {
       .then((res) => expect(res.body.error).toBe('unsupported HTTP METHOD specified'))
   })
 
-  test('valid upload data is allowed', () => {
+  test('valid upload data is allowed - tus', () => {
     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',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus',
+        httpMethod: 'POST',
+        headers: {
+          customheader: 'header value'
+        },
+        metadata: {
+          mymetadata: 'matadata value'
+        },
+        fieldname: 'uploadField'
+      })
+      .expect(200)
+  })
+
+  test('valid upload data is allowed - s3-multipart', () => {
+    return request(authServer)
+      .post('/drive/get/README.md')
+      .set('uppy-auth-token', token)
+      .set('Content-Type', 'application/json')
+      .send({
+        endpoint: 'http://master.tus.io/files',
+        protocol: 's3-multipart',
         httpMethod: 'PUT',
         headers: {
           customheader: 'header value'
@@ -164,7 +184,7 @@ describe('download provdier file', () => {
       .set('uppy-auth-token', token)
       .set('Content-Type', 'application/json')
       .send({
-        endpoint: 'http://master.tus.com/files',
+        endpoint: 'http://master.tus.io/files',
         protocol: 'tus'
       })
       .expect(200)