Skip to content

Commit

Permalink
companion,provider-views: set default version if none is set
Browse files Browse the repository at this point in the history
also encode versions sent through query params
  • Loading branch information
ifedapoolarewaju committed Jun 5, 2019
1 parent d647e89 commit 93e0e5f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
43 changes: 32 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/uppy.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const getOptionsMiddleware = (options) => {
options,
s3Client,
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)
}
next()
Expand Down
32 changes: 29 additions & 3 deletions packages/@uppy/companion/test/__tests__/companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ jest.mock('../../src/server/helpers/oauth-state', () => {
}

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') {
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'
Expand Down Expand Up @@ -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
return request(authServer)
.get(`/drive/send-token?uppyAuthToken=${token}&state=state-with-older-version`)
Expand All @@ -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', () => {
return request(authServer)
.get('/drive/logout/')
Expand Down
4 changes: 1 addition & 3 deletions packages/@uppy/companion/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"sourceMap": false,
"allowJs": true,
"checkJs": true,
"noEmitOnError": true,
"resolveJsonModule": true,
"esModuleInterop": true
"noEmitOnError": true
},
"include": [
"src/**/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/provider-views/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ module.exports = class ProviderView {
handleAuth () {
const authState = btoa(JSON.stringify({ origin: getOrigin() }))
// @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 authWindow = window.open(link, '_blank')
Expand Down

0 comments on commit 93e0e5f

Please sign in to comment.