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