video-blacklist.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import {
  4. createUser,
  5. doubleFollow,
  6. flushAndRunMultipleServers,
  7. flushTests,
  8. getBlacklistedVideosList,
  9. getVideo,
  10. getVideoWithToken,
  11. killallServers,
  12. makePostBodyRequest,
  13. makePutBodyRequest,
  14. removeVideoFromBlacklist,
  15. ServerInfo,
  16. setAccessTokensToServers,
  17. uploadVideo,
  18. userLogin, waitJobs
  19. } from '../../../../shared/extra-utils'
  20. import {
  21. checkBadCountPagination,
  22. checkBadSortPagination,
  23. checkBadStartPagination
  24. } from '../../../../shared/extra-utils/requests/check-api-params'
  25. import { VideoDetails, VideoBlacklistType } from '../../../../shared/models/videos'
  26. import { expect } from 'chai'
  27. describe('Test video blacklist API validators', function () {
  28. let servers: ServerInfo[]
  29. let notBlacklistedVideoId: number
  30. let remoteVideoUUID: string
  31. let userAccessToken1 = ''
  32. let userAccessToken2 = ''
  33. // ---------------------------------------------------------------
  34. before(async function () {
  35. this.timeout(120000)
  36. servers = await flushAndRunMultipleServers(2)
  37. await setAccessTokensToServers(servers)
  38. await doubleFollow(servers[0], servers[1])
  39. {
  40. const username = 'user1'
  41. const password = 'my super password'
  42. await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
  43. userAccessToken1 = await userLogin(servers[0], { username, password })
  44. }
  45. {
  46. const username = 'user2'
  47. const password = 'my super password'
  48. await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
  49. userAccessToken2 = await userLogin(servers[0], { username, password })
  50. }
  51. {
  52. const res = await uploadVideo(servers[0].url, userAccessToken1, {})
  53. servers[0].video = res.body.video
  54. }
  55. {
  56. const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
  57. notBlacklistedVideoId = res.body.video.uuid
  58. }
  59. {
  60. const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
  61. remoteVideoUUID = res.body.video.uuid
  62. }
  63. await waitJobs(servers)
  64. })
  65. describe('When adding a video in blacklist', function () {
  66. const basePath = '/api/v1/videos/'
  67. it('Should fail with nothing', async function () {
  68. const path = basePath + servers[0].video + '/blacklist'
  69. const fields = {}
  70. await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
  71. })
  72. it('Should fail with a wrong video', async function () {
  73. const wrongPath = '/api/v1/videos/blabla/blacklist'
  74. const fields = {}
  75. await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
  76. })
  77. it('Should fail with a non authenticated user', async function () {
  78. const path = basePath + servers[0].video + '/blacklist'
  79. const fields = {}
  80. await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
  81. })
  82. it('Should fail with a non admin user', async function () {
  83. const path = basePath + servers[0].video + '/blacklist'
  84. const fields = {}
  85. await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
  86. })
  87. it('Should fail with an invalid reason', async function () {
  88. const path = basePath + servers[0].video.uuid + '/blacklist'
  89. const fields = { reason: 'a'.repeat(305) }
  90. await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
  91. })
  92. it('Should fail to unfederate a remote video', async function () {
  93. const path = basePath + remoteVideoUUID + '/blacklist'
  94. const fields = { unfederate: true }
  95. await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
  96. })
  97. it('Should succeed with the correct params', async function () {
  98. const path = basePath + servers[0].video.uuid + '/blacklist'
  99. const fields = { }
  100. await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
  101. })
  102. })
  103. describe('When updating a video in blacklist', function () {
  104. const basePath = '/api/v1/videos/'
  105. it('Should fail with a wrong video', async function () {
  106. const wrongPath = '/api/v1/videos/blabla/blacklist'
  107. const fields = {}
  108. await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
  109. })
  110. it('Should fail with a video not blacklisted', async function () {
  111. const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
  112. const fields = {}
  113. await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
  114. })
  115. it('Should fail with a non authenticated user', async function () {
  116. const path = basePath + servers[0].video + '/blacklist'
  117. const fields = {}
  118. await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
  119. })
  120. it('Should fail with a non admin user', async function () {
  121. const path = basePath + servers[0].video + '/blacklist'
  122. const fields = {}
  123. await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
  124. })
  125. it('Should fail with an invalid reason', async function () {
  126. const path = basePath + servers[0].video.uuid + '/blacklist'
  127. const fields = { reason: 'a'.repeat(305) }
  128. await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
  129. })
  130. it('Should succeed with the correct params', async function () {
  131. const path = basePath + servers[0].video.uuid + '/blacklist'
  132. const fields = { reason: 'hello' }
  133. await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
  134. })
  135. })
  136. describe('When getting blacklisted video', function () {
  137. it('Should fail with a non authenticated user', async function () {
  138. await getVideo(servers[0].url, servers[0].video.uuid, 401)
  139. })
  140. it('Should fail with another user', async function () {
  141. await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
  142. })
  143. it('Should succeed with the owner authenticated user', async function () {
  144. const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
  145. const video: VideoDetails = res.body
  146. expect(video.blacklisted).to.be.true
  147. })
  148. it('Should succeed with an admin', async function () {
  149. const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
  150. const video: VideoDetails = res.body
  151. expect(video.blacklisted).to.be.true
  152. })
  153. })
  154. describe('When removing a video in blacklist', function () {
  155. it('Should fail with a non authenticated user', async function () {
  156. await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
  157. })
  158. it('Should fail with a non admin user', async function () {
  159. await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
  160. })
  161. it('Should fail with an incorrect id', async function () {
  162. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
  163. })
  164. it('Should fail with a not blacklisted video', async function () {
  165. // The video was not added to the blacklist so it should fail
  166. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
  167. })
  168. it('Should succeed with the correct params', async function () {
  169. await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
  170. })
  171. })
  172. describe('When listing videos in blacklist', function () {
  173. const basePath = '/api/v1/videos/blacklist/'
  174. it('Should fail with a non authenticated user', async function () {
  175. await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
  176. })
  177. it('Should fail with a non admin user', async function () {
  178. await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
  179. })
  180. it('Should fail with a bad start pagination', async function () {
  181. await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
  182. })
  183. it('Should fail with a bad count pagination', async function () {
  184. await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
  185. })
  186. it('Should fail with an incorrect sort', async function () {
  187. await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
  188. })
  189. it('Should fail with an invalid type', async function () {
  190. await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
  191. })
  192. it('Should succeed with the correct parameters', async function () {
  193. await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
  194. })
  195. })
  196. after(function () {
  197. killallServers(servers)
  198. })
  199. })