peertube.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils'
  4. import {
  5. cleanupTests,
  6. CLICommand,
  7. createSingleServer,
  8. doubleFollow,
  9. PeerTubeServer,
  10. setAccessTokensToServers,
  11. waitJobs
  12. } from '@shared/server-commands'
  13. import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared'
  14. describe('Test CLI wrapper', function () {
  15. let server: PeerTubeServer
  16. let userAccessToken: string
  17. let cliCommand: CLICommand
  18. const cmd = 'node ./dist/server/tools/peertube.js'
  19. before(async function () {
  20. this.timeout(30000)
  21. server = await createSingleServer(1, {
  22. rates_limit: {
  23. login: {
  24. max: 30
  25. }
  26. }
  27. })
  28. await setAccessTokensToServers([ server ])
  29. await server.users.create({ username: 'user_1', password: 'super_password' })
  30. userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
  31. {
  32. const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
  33. await server.channels.create({ token: userAccessToken, attributes })
  34. }
  35. cliCommand = server.cli
  36. })
  37. describe('Authentication and instance selection', function () {
  38. it('Should get an access token', async function () {
  39. const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
  40. const token = stdout.trim()
  41. const body = await server.users.getMyInfo({ token })
  42. expect(body.username).to.equal('user_1')
  43. })
  44. it('Should display no selected instance', async function () {
  45. this.timeout(60000)
  46. const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
  47. expect(stdout).to.contain('no instance selected')
  48. })
  49. it('Should add a user', async function () {
  50. this.timeout(60000)
  51. await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
  52. })
  53. it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
  54. this.timeout(60000)
  55. let fullServerURL = server.url + '/'
  56. await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
  57. fullServerURL = server.url + '/asdfasdf'
  58. await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
  59. })
  60. it('Should default to this user', async function () {
  61. this.timeout(60000)
  62. const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
  63. expect(stdout).to.contain(`instance ${server.url} selected`)
  64. })
  65. it('Should remember the user', async function () {
  66. this.timeout(60000)
  67. const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
  68. expect(stdout).to.contain(server.url)
  69. })
  70. })
  71. describe('Video upload/import', function () {
  72. it('Should upload a video', async function () {
  73. this.timeout(60000)
  74. const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
  75. const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
  76. await cliCommand.execWithEnv(`${cmd} upload ${params}`)
  77. })
  78. it('Should have the video uploaded', async function () {
  79. const { total, data } = await server.videos.list()
  80. expect(total).to.equal(1)
  81. const video = await server.videos.get({ id: data[0].uuid })
  82. expect(video.name).to.equal('test upload')
  83. expect(video.support).to.equal('support_text')
  84. expect(video.channel.name).to.equal('user_channel')
  85. })
  86. it('Should import a video', async function () {
  87. if (areHttpImportTestsDisabled()) return
  88. this.timeout(60000)
  89. const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
  90. await cliCommand.execWithEnv(`${cmd} import ${params}`)
  91. })
  92. it('Should have imported the video', async function () {
  93. if (areHttpImportTestsDisabled()) return
  94. this.timeout(60000)
  95. await waitJobs([ server ])
  96. const { total, data } = await server.videos.list()
  97. expect(total).to.equal(2)
  98. const video = data.find(v => v.name === 'small video - youtube')
  99. expect(video).to.not.be.undefined
  100. const videoDetails = await server.videos.get({ id: video.id })
  101. expect(videoDetails.channel.name).to.equal('user_channel')
  102. expect(videoDetails.support).to.equal('super support text')
  103. expect(videoDetails.nsfw).to.be.false
  104. })
  105. it('Should not import again the same video', async function () {
  106. if (areHttpImportTestsDisabled()) return
  107. this.timeout(60000)
  108. const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
  109. await cliCommand.execWithEnv(`${cmd} import ${params}`)
  110. await waitJobs([ server ])
  111. const { total, data } = await server.videos.list()
  112. expect(total).to.equal(2)
  113. const videos = data.filter(v => v.name === 'small video - youtube')
  114. expect(videos).to.have.lengthOf(1)
  115. // So we can reimport it
  116. await server.videos.remove({ token: userAccessToken, id: videos[0].id })
  117. })
  118. it('Should import and override some imported attributes', async function () {
  119. if (areHttpImportTestsDisabled()) return
  120. this.timeout(60000)
  121. const params = `--target-url ${FIXTURE_URLS.youtube} ` +
  122. `--channel-name user_channel --video-name toto --nsfw --support support`
  123. await cliCommand.execWithEnv(`${cmd} import ${params}`)
  124. await waitJobs([ server ])
  125. {
  126. const { total, data } = await server.videos.list()
  127. expect(total).to.equal(2)
  128. const video = data.find(v => v.name === 'toto')
  129. expect(video).to.not.be.undefined
  130. const videoDetails = await server.videos.get({ id: video.id })
  131. expect(videoDetails.channel.name).to.equal('user_channel')
  132. expect(videoDetails.support).to.equal('support')
  133. expect(videoDetails.nsfw).to.be.true
  134. expect(videoDetails.commentsEnabled).to.be.true
  135. }
  136. })
  137. })
  138. describe('Admin auth', function () {
  139. it('Should remove the auth user', async function () {
  140. await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
  141. const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
  142. expect(stdout).to.contain('no instance selected')
  143. })
  144. it('Should add the admin user', async function () {
  145. await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
  146. })
  147. })
  148. describe('Manage plugins', function () {
  149. it('Should install a plugin', async function () {
  150. this.timeout(60000)
  151. await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
  152. })
  153. it('Should have registered settings', async function () {
  154. await testHelloWorldRegisteredSettings(server)
  155. })
  156. it('Should list installed plugins', async function () {
  157. const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
  158. expect(res).to.contain('peertube-plugin-hello-world')
  159. })
  160. it('Should uninstall the plugin', async function () {
  161. const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
  162. expect(res).to.not.contain('peertube-plugin-hello-world')
  163. })
  164. it('Should install a plugin in requested version', async function () {
  165. this.timeout(60000)
  166. await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
  167. })
  168. it('Should list installed plugins, in correct version', async function () {
  169. const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
  170. expect(res).to.contain('peertube-plugin-hello-world')
  171. expect(res).to.contain('0.0.17')
  172. })
  173. it('Should uninstall the plugin again', async function () {
  174. const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
  175. expect(res).to.not.contain('peertube-plugin-hello-world')
  176. })
  177. it('Should install a plugin in requested beta version', async function () {
  178. this.timeout(60000)
  179. await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.21-beta.1`)
  180. const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
  181. expect(res).to.contain('peertube-plugin-hello-world')
  182. expect(res).to.contain('0.0.21-beta.1')
  183. await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
  184. })
  185. })
  186. describe('Manage video redundancies', function () {
  187. let anotherServer: PeerTubeServer
  188. let video1Server2: number
  189. let servers: PeerTubeServer[]
  190. before(async function () {
  191. this.timeout(120000)
  192. anotherServer = await createSingleServer(2)
  193. await setAccessTokensToServers([ anotherServer ])
  194. await doubleFollow(server, anotherServer)
  195. servers = [ server, anotherServer ]
  196. await waitJobs(servers)
  197. const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
  198. await waitJobs(servers)
  199. video1Server2 = await server.videos.getId({ uuid })
  200. })
  201. it('Should add a redundancy', async function () {
  202. this.timeout(60000)
  203. const params = `add --video ${video1Server2}`
  204. await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
  205. await waitJobs(servers)
  206. })
  207. it('Should list redundancies', async function () {
  208. this.timeout(60000)
  209. {
  210. const params = 'list-my-redundancies'
  211. const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
  212. expect(stdout).to.contain('super video')
  213. expect(stdout).to.contain(`localhost:${server.port}`)
  214. }
  215. })
  216. it('Should remove a redundancy', async function () {
  217. this.timeout(60000)
  218. const params = `remove --video ${video1Server2}`
  219. await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
  220. await waitJobs(servers)
  221. {
  222. const params = 'list-my-redundancies'
  223. const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
  224. expect(stdout).to.not.contain('super video')
  225. }
  226. })
  227. after(async function () {
  228. this.timeout(10000)
  229. await cleanupTests([ anotherServer ])
  230. })
  231. })
  232. after(async function () {
  233. this.timeout(10000)
  234. await cleanupTests([ server ])
  235. })
  236. })