]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
a0c149ac0fea63c405f715501a333ba7cb9b11e1
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import { Video, VideoDetails } from '../../../shared'
6 import {
7 areHttpImportTestsDisabled,
8 buildAbsoluteFixturePath,
9 cleanupTests,
10 CLICommand,
11 doubleFollow,
12 flushAndRunServer,
13 getLocalIdByUUID,
14 getVideo,
15 getVideosList,
16 ImportsCommand,
17 removeVideo,
18 ServerInfo,
19 setAccessTokensToServers,
20 testHelloWorldRegisteredSettings,
21 uploadVideoAndGetId,
22 waitJobs
23 } from '../../../shared/extra-utils'
24
25 describe('Test CLI wrapper', function () {
26 let server: ServerInfo
27 let userAccessToken: string
28
29 let cliCommand: CLICommand
30
31 const cmd = 'node ./dist/server/tools/peertube.js'
32
33 before(async function () {
34 this.timeout(30000)
35
36 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
38
39 await server.usersCommand.create({ username: 'user_1', password: 'super_password' })
40
41 userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
42
43 {
44 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
45 await server.channelsCommand.create({ token: userAccessToken, attributes })
46 }
47
48 cliCommand = server.cliCommand
49 })
50
51 describe('Authentication and instance selection', function () {
52
53 it('Should get an access token', async function () {
54 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
55 const token = stdout.trim()
56
57 const body = await server.usersCommand.getMyInfo({ token })
58 expect(body.username).to.equal('user_1')
59 })
60
61 it('Should display no selected instance', async function () {
62 this.timeout(60000)
63
64 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
65 expect(stdout).to.contain('no instance selected')
66 })
67
68 it('Should add a user', async function () {
69 this.timeout(60000)
70
71 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
72 })
73
74 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
75 this.timeout(60000)
76
77 let fullServerURL = server.url + '/'
78
79 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
80
81 fullServerURL = server.url + '/asdfasdf'
82 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
83 })
84
85 it('Should default to this user', async function () {
86 this.timeout(60000)
87
88 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
89 expect(stdout).to.contain(`instance ${server.url} selected`)
90 })
91
92 it('Should remember the user', async function () {
93 this.timeout(60000)
94
95 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
96 expect(stdout).to.contain(server.url)
97 })
98 })
99
100 describe('Video upload/import', function () {
101
102 it('Should upload a video', async function () {
103 this.timeout(60000)
104
105 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
106 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
107
108 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
109 })
110
111 it('Should have the video uploaded', async function () {
112 const res = await getVideosList(server.url)
113
114 expect(res.body.total).to.equal(1)
115
116 const videos: Video[] = res.body.data
117
118 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
119
120 expect(video.name).to.equal('test upload')
121 expect(video.support).to.equal('support_text')
122 expect(video.channel.name).to.equal('user_channel')
123 })
124
125 it('Should import a video', async function () {
126 if (areHttpImportTestsDisabled()) return
127
128 this.timeout(60000)
129
130 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
131 await cliCommand.execWithEnv(`${cmd} import ${params}`)
132 })
133
134 it('Should have imported the video', async function () {
135 if (areHttpImportTestsDisabled()) return
136
137 this.timeout(60000)
138
139 await waitJobs([ server ])
140
141 const res = await getVideosList(server.url)
142
143 expect(res.body.total).to.equal(2)
144
145 const videos: Video[] = res.body.data
146 const video = videos.find(v => v.name === 'small video - youtube')
147 expect(video).to.not.be.undefined
148
149 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
150 expect(videoDetails.channel.name).to.equal('user_channel')
151 expect(videoDetails.support).to.equal('super support text')
152 expect(videoDetails.nsfw).to.be.false
153
154 // So we can reimport it
155 await removeVideo(server.url, userAccessToken, video.id)
156 })
157
158 it('Should import and override some imported attributes', async function () {
159 if (areHttpImportTestsDisabled()) return
160
161 this.timeout(60000)
162
163 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
164 `--channel-name user_channel --video-name toto --nsfw --support support`
165 await cliCommand.execWithEnv(`${cmd} import ${params}`)
166
167 await waitJobs([ server ])
168
169 {
170 const res = await getVideosList(server.url)
171 expect(res.body.total).to.equal(2)
172
173 const videos: Video[] = res.body.data
174 const video = videos.find(v => v.name === 'toto')
175 expect(video).to.not.be.undefined
176
177 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
178 expect(videoDetails.channel.name).to.equal('user_channel')
179 expect(videoDetails.support).to.equal('support')
180 expect(videoDetails.nsfw).to.be.true
181 expect(videoDetails.commentsEnabled).to.be.true
182 }
183 })
184 })
185
186 describe('Admin auth', function () {
187
188 it('Should remove the auth user', async function () {
189 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
190
191 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
192 expect(stdout).to.contain('no instance selected')
193 })
194
195 it('Should add the admin user', async function () {
196 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
197 })
198 })
199
200 describe('Manage plugins', function () {
201
202 it('Should install a plugin', async function () {
203 this.timeout(60000)
204
205 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
206 })
207
208 it('Should have registered settings', async function () {
209 await testHelloWorldRegisteredSettings(server)
210 })
211
212 it('Should list installed plugins', async function () {
213 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
214
215 expect(res).to.contain('peertube-plugin-hello-world')
216 })
217
218 it('Should uninstall the plugin', async function () {
219 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
220
221 expect(res).to.not.contain('peertube-plugin-hello-world')
222 })
223 })
224
225 describe('Manage video redundancies', function () {
226 let anotherServer: ServerInfo
227 let video1Server2: number
228 let servers: ServerInfo[]
229
230 before(async function () {
231 this.timeout(120000)
232
233 anotherServer = await flushAndRunServer(2)
234 await setAccessTokensToServers([ anotherServer ])
235
236 await doubleFollow(server, anotherServer)
237
238 servers = [ server, anotherServer ]
239 await waitJobs(servers)
240
241 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
242 await waitJobs(servers)
243
244 video1Server2 = await getLocalIdByUUID(server.url, uuid)
245 })
246
247 it('Should add a redundancy', async function () {
248 this.timeout(60000)
249
250 const params = `add --video ${video1Server2}`
251 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
252
253 await waitJobs(servers)
254 })
255
256 it('Should list redundancies', async function () {
257 this.timeout(60000)
258
259 {
260 const params = 'list-my-redundancies'
261 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
262
263 expect(stdout).to.contain('super video')
264 expect(stdout).to.contain(`localhost:${server.port}`)
265 }
266 })
267
268 it('Should remove a redundancy', async function () {
269 this.timeout(60000)
270
271 const params = `remove --video ${video1Server2}`
272 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
273
274 await waitJobs(servers)
275
276 {
277 const params = 'list-my-redundancies'
278 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
279
280 expect(stdout).to.not.contain('super video')
281 }
282 })
283
284 after(async function () {
285 this.timeout(10000)
286
287 await cleanupTests([ anotherServer ])
288 })
289 })
290
291 after(async function () {
292 this.timeout(10000)
293
294 await cleanupTests([ server ])
295 })
296 })