deauthorization.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const nock = require('nock')
  2. const request = require('supertest')
  3. const { getServer } = require('../mockserver')
  4. const authServer = getServer()
  5. afterAll(() => {
  6. nock.cleanAll()
  7. nock.restore()
  8. })
  9. describe('handle deauthorization callback', () => {
  10. nock('https://api.zoom.us')
  11. .post('/oauth/data/compliance')
  12. .reply(200)
  13. test('providers without support for callback endpoint', () => {
  14. return request(authServer)
  15. .post('/dropbox/deauthorization/callback')
  16. .set('Content-Type', 'application/json')
  17. .send({
  18. foo: 'bar',
  19. })
  20. // @todo consider receiving 501 instead
  21. .expect(500)
  22. })
  23. test('validate that request credentials match', () => {
  24. return request(authServer)
  25. .post('/zoom/deauthorization/callback')
  26. .set('Content-Type', 'application/json')
  27. .set('Authorization', 'wrong-verfication-token')
  28. .send({
  29. event: 'app_deauthorized',
  30. payload: {
  31. user_data_retention: 'false',
  32. account_id: 'EabCDEFghiLHMA',
  33. user_id: 'z9jkdsfsdfjhdkfjQ',
  34. signature: '827edc3452044f0bc86bdd5684afb7d1e6becfa1a767f24df1b287853cf73000',
  35. deauthorization_time: '2019-06-17T13:52:28.632Z',
  36. client_id: 'ADZ9k9bTWmGUoUbECUKU_a',
  37. },
  38. })
  39. .expect(400)
  40. })
  41. test('validate request credentials is present', () => {
  42. // Authorization header is absent
  43. return request(authServer)
  44. .post('/zoom/deauthorization/callback')
  45. .set('Content-Type', 'application/json')
  46. .send({
  47. event: 'app_deauthorized',
  48. payload: {
  49. user_data_retention: 'false',
  50. account_id: 'EabCDEFghiLHMA',
  51. user_id: 'z9jkdsfsdfjhdkfjQ',
  52. signature: '827edc3452044f0bc86bdd5684afb7d1e6becfa1a767f24df1b287853cf73000',
  53. deauthorization_time: '2019-06-17T13:52:28.632Z',
  54. client_id: 'ADZ9k9bTWmGUoUbECUKU_a',
  55. },
  56. })
  57. .expect(400)
  58. })
  59. test('validate request content', () => {
  60. return request(authServer)
  61. .post('/zoom/deauthorization/callback')
  62. .set('Content-Type', 'application/json')
  63. .set('Authorization', 'zoom_verfication_token')
  64. .send({
  65. invalid: 'content',
  66. })
  67. .expect(400)
  68. })
  69. test('validate request content (event name)', () => {
  70. return request(authServer)
  71. .post('/zoom/deauthorization/callback')
  72. .set('Content-Type', 'application/json')
  73. .set('Authorization', 'zoom_verfication_token')
  74. .send({
  75. event: 'wrong_event_name',
  76. payload: {
  77. user_data_retention: 'false',
  78. account_id: 'EabCDEFghiLHMA',
  79. user_id: 'z9jkdsfsdfjhdkfjQ',
  80. signature: '827edc3452044f0bc86bdd5684afb7d1e6becfa1a767f24df1b287853cf73000',
  81. deauthorization_time: '2019-06-17T13:52:28.632Z',
  82. client_id: 'ADZ9k9bTWmGUoUbECUKU_a',
  83. },
  84. })
  85. .expect(400)
  86. })
  87. test('allow valid request', () => {
  88. return request(authServer)
  89. .post('/zoom/deauthorization/callback')
  90. .set('Content-Type', 'application/json')
  91. .set('Authorization', 'zoom_verfication_token')
  92. .send({
  93. event: 'app_deauthorized',
  94. payload: {
  95. user_data_retention: 'false',
  96. account_id: 'EabCDEFghiLHMA',
  97. user_id: 'z9jkdsfsdfjhdkfjQ',
  98. signature: '827edc3452044f0bc86bdd5684afb7d1e6becfa1a767f24df1b287853cf73000',
  99. deauthorization_time: '2019-06-17T13:52:28.632Z',
  100. client_id: 'ADZ9k9bTWmGUoUbECUKU_a',
  101. },
  102. })
  103. .expect(200)
  104. })
  105. })