credentials.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* global jest:false, test:false, expect:false, describe:false */
  2. // mocking request module used to fetch custom oauth credentials
  3. jest.mock('request', () => {
  4. const { remoteZoomKey, remoteZoomSecret, remoteZoomVerificationToken } = require('../fixtures/zoom').expects
  5. return {
  6. post: (url, options, done) => {
  7. if (url === 'http://localhost:2111/zoom-keys') {
  8. const { body } = options
  9. if (body.provider !== 'zoom') {
  10. return done(new Error('wrong provider'))
  11. }
  12. if (body.parameters !== 'ZOOM-CREDENTIALS-PARAMS') {
  13. return done(new Error('wrong params'))
  14. }
  15. const respBody = {
  16. credentials: {
  17. key: remoteZoomKey,
  18. secret: remoteZoomSecret,
  19. verificationToken: remoteZoomVerificationToken,
  20. },
  21. }
  22. return done(null, { statusCode: 200, body: respBody }, respBody)
  23. }
  24. done(new Error('unsupported request with mock function'))
  25. },
  26. }
  27. })
  28. const request = require('supertest')
  29. const tokenService = require('../../src/server/helpers/jwt')
  30. const { getServer } = require('../mockserver')
  31. const authServer = getServer({ COMPANION_ZOOM_KEYS_ENDPOINT: 'http://localhost:2111/zoom-keys' })
  32. const authData = {
  33. zoom: 'token value',
  34. }
  35. const token = tokenService.generateEncryptedToken(authData, process.env.COMPANION_SECRET)
  36. describe('providers requests with remote oauth keys', () => {
  37. test('zoom logout with remote oauth keys happy path', () => {
  38. const params = { params: 'ZOOM-CREDENTIALS-PARAMS' }
  39. const encodedParams = Buffer.from(JSON.stringify(params), 'binary').toString('base64')
  40. return request(authServer)
  41. .get('/zoom/logout/')
  42. .set('uppy-auth-token', token)
  43. .set('uppy-credentials-params', encodedParams)
  44. .expect(200)
  45. .then((res) => expect(res.body.ok).toBe(true))
  46. })
  47. test('zoom logout with wrong credentials params', () => {
  48. const params = { params: 'WRONG-ZOOM-CREDENTIALS-PARAMS' }
  49. const encodedParams = Buffer.from(JSON.stringify(params), 'binary').toString('base64')
  50. return request(authServer)
  51. .get('/zoom/logout/')
  52. .set('uppy-auth-token', token)
  53. .set('uppy-credentials-params', encodedParams)
  54. // todo: handle failures differently to return 400 for this case instead
  55. .expect(500)
  56. })
  57. })