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