deauthorization.js 3.4 KB

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