浏览代码

companion,provider-views: set default version if none is set

also encode versions sent through query params
Ifedapo Olarewaju 5 年之前
父节点
当前提交
592b43bf67

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

@@ -233,7 +233,7 @@ const getOptionsMiddleware = (options) => {
       options,
       options,
       s3Client,
       s3Client,
       authToken: req.header('uppy-auth-token') || req.query.uppyAuthToken,
       authToken: req.header('uppy-auth-token') || req.query.uppyAuthToken,
-      clientVersion: req.header('uppy-versions') || req.query.uppyVersions,
+      clientVersion: req.header('uppy-versions') || decodeURIComponent(req.query.uppyVersions) || '1.0.0',
       buildURL: getURLBuilder(options)
       buildURL: getURLBuilder(options)
     }
     }
     next()
     next()

+ 29 - 3
packages/@uppy/companion/test/__tests__/companion.js

@@ -12,11 +12,15 @@ jest.mock('../../src/server/helpers/oauth-state', () => {
       }
       }
 
 
       if (state === 'state-with-older-version' && key === 'clientVersion') {
       if (state === 'state-with-older-version' && key === 'clientVersion') {
-        return '@uppy/companion-client:1.0.1'
+        return '@uppy/companion-client=1.0.1'
       }
       }
 
 
       if (state === 'state-with-newer-version' && key === 'clientVersion') {
       if (state === 'state-with-newer-version' && key === 'clientVersion') {
-        return '@uppy/companion-client:1.0.3'
+        return '@uppy/companion-client=1.0.3'
+      }
+
+      if (state === 'state-with-newer-version-old-style' && key === 'clientVersion') {
+        return 'companion-client:1.0.2'
       }
       }
 
 
       return 'http://localhost:3020'
       return 'http://localhost:3020'
@@ -111,7 +115,7 @@ describe('test authentication', () => {
       })
       })
   })
   })
 
 
-  test('the token gets sent to html based on version', () => {
+  test('the token gets to older clients without stringify', () => {
     // see mock ../../src/server/helpers/oauth-state above for state values
     // see mock ../../src/server/helpers/oauth-state above for state values
     return request(authServer)
     return request(authServer)
       .get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-older-version`)
       .get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-older-version`)
@@ -133,6 +137,28 @@ describe('test authentication', () => {
       })
       })
   })
   })
 
 
+  test('the token gets sent to newer clients with old version style', () => {
+    // see mock ../../src/server/helpers/oauth-state above for state values
+    return request(authServer)
+      .get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-newer-version-old-style`)
+      .expect(200)
+      .expect((res) => {
+        const body = `
+    <!DOCTYPE html>
+    <html>
+    <head>
+        <meta charset="utf-8" />
+        <script>
+          window.opener.postMessage(JSON.stringify({token: "${token}"}), "http://localhost:3020")
+          window.close()
+        </script>
+    </head>
+    <body></body>
+    </html>`
+        expect(res.text).toBe(body)
+      })
+  })
+
   test('logout provider', () => {
   test('logout provider', () => {
     return request(authServer)
     return request(authServer)
       .get('/drive/logout/')
       .get('/drive/logout/')

+ 1 - 3
packages/@uppy/companion/tsconfig.json

@@ -7,9 +7,7 @@
     "sourceMap": false,
     "sourceMap": false,
     "allowJs": true,
     "allowJs": true,
     "checkJs": true,
     "checkJs": true,
-    "noEmitOnError": true,
-    "resolveJsonModule": true,
-    "esModuleInterop": true
+    "noEmitOnError": true
   },
   },
   "include": [
   "include": [
     "src/**/*"
     "src/**/*"

+ 1 - 1
packages/@uppy/provider-views/src/index.js

@@ -423,7 +423,7 @@ module.exports = class ProviderView {
   handleAuth () {
   handleAuth () {
     const authState = btoa(JSON.stringify({ origin: getOrigin() }))
     const authState = btoa(JSON.stringify({ origin: getOrigin() }))
     // @todo remove this hardcoded version
     // @todo remove this hardcoded version
-    const clientVersion = 'companion-client:1.0.2'
+    const clientVersion = encodeURIComponent('@uppy/companion-client=1.0.2')
     const link = `${this.provider.authUrl()}?state=${authState}&uppyVersions=${clientVersion}`
     const link = `${this.provider.authUrl()}?state=${authState}&uppyVersions=${clientVersion}`
 
 
     const authWindow = window.open(link, '_blank')
     const authWindow = window.open(link, '_blank')