diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 10:33:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | ae2abfd3aed3e75d39a316b49b914d187faa7475 (patch) | |
tree | 4d5060dc310f3d8cdcd5829779522f49b3d10e71 | |
parent | 9c6327f803aaf4200672f1fc40b2f43786daca47 (diff) | |
download | PeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.tar.gz PeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.tar.zst PeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.zip |
Introduce plugins command
26 files changed, 480 insertions, 765 deletions
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index a833fe6ff..d372221d0 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts | |||
@@ -10,7 +10,6 @@ import { | |||
10 | createUser, | 10 | createUser, |
11 | flushAndRunServer, | 11 | flushAndRunServer, |
12 | immutableAssign, | 12 | immutableAssign, |
13 | installPlugin, | ||
14 | makeGetRequest, | 13 | makeGetRequest, |
15 | makePostBodyRequest, | 14 | makePostBodyRequest, |
16 | makePutBodyRequest, | 15 | makePutBodyRequest, |
@@ -50,13 +49,13 @@ describe('Test server plugins API validators', function () { | |||
50 | userAccessToken = await userLogin(server, user) | 49 | userAccessToken = await userLogin(server, user) |
51 | 50 | ||
52 | { | 51 | { |
53 | const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) | 52 | const res = await server.pluginsCommand.install({ npmName: npmPlugin }) |
54 | const plugin = res.body as PeerTubePlugin | 53 | const plugin = res.body as PeerTubePlugin |
55 | npmVersion = plugin.version | 54 | npmVersion = plugin.version |
56 | } | 55 | } |
57 | 56 | ||
58 | { | 57 | { |
59 | const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin }) | 58 | const res = await server.pluginsCommand.install({ npmName: themePlugin }) |
60 | const plugin = res.body as PeerTubePlugin | 59 | const plugin = res.body as PeerTubePlugin |
61 | themeVersion = plugin.version | 60 | themeVersion = plugin.version |
62 | } | 61 | } |
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 91681c9d6..da9767b74 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts | |||
@@ -2,18 +2,20 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { MockJoinPeerTubeVersions } from '@shared/extra-utils' | ||
6 | import { PluginType } from '@shared/models' | ||
7 | import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' | ||
8 | import { ServerInfo } from '../../../../shared/extra-utils/index' | ||
9 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | ||
10 | import { | 5 | import { |
11 | CheckerBaseParams, | 6 | CheckerBaseParams, |
12 | checkNewPeerTubeVersion, | 7 | checkNewPeerTubeVersion, |
13 | checkNewPluginVersion, | 8 | checkNewPluginVersion, |
14 | prepareNotificationsTest | 9 | cleanupTests, |
15 | } from '../../../../shared/extra-utils/users/user-notifications' | 10 | MockJoinPeerTubeVersions, |
16 | import { UserNotification, UserNotificationType } from '../../../../shared/models/users' | 11 | MockSmtpServer, |
12 | prepareNotificationsTest, | ||
13 | ServerInfo, | ||
14 | setPluginLatestVersion, | ||
15 | setPluginVersion, | ||
16 | wait | ||
17 | } from '@shared/extra-utils' | ||
18 | import { PluginType, UserNotification, UserNotificationType } from '@shared/models' | ||
17 | 19 | ||
18 | describe('Test admin notifications', function () { | 20 | describe('Test admin notifications', function () { |
19 | let server: ServerInfo | 21 | let server: ServerInfo |
@@ -58,17 +60,8 @@ describe('Test admin notifications', function () { | |||
58 | token: server.accessToken | 60 | token: server.accessToken |
59 | } | 61 | } |
60 | 62 | ||
61 | await installPlugin({ | 63 | await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' }) |
62 | url: server.url, | 64 | await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) |
63 | accessToken: server.accessToken, | ||
64 | npmName: 'peertube-plugin-hello-world' | ||
65 | }) | ||
66 | |||
67 | await installPlugin({ | ||
68 | url: server.url, | ||
69 | accessToken: server.accessToken, | ||
70 | npmName: 'peertube-theme-background-red' | ||
71 | }) | ||
72 | }) | 65 | }) |
73 | 66 | ||
74 | describe('Latest PeerTube version notification', function () { | 67 | describe('Latest PeerTube version notification', function () { |
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 6b61c7c33..1536997d5 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts | |||
@@ -9,34 +9,25 @@ import { | |||
9 | flushAndRunServer, | 9 | flushAndRunServer, |
10 | getConfig, | 10 | getConfig, |
11 | getMyUserInformation, | 11 | getMyUserInformation, |
12 | getPlugin, | ||
13 | getPluginPackageJSON, | ||
14 | getPluginTestPath, | ||
15 | getPublicSettings, | ||
16 | installPlugin, | ||
17 | killallServers, | 12 | killallServers, |
18 | listAvailablePlugins, | 13 | PluginsCommand, |
19 | listPlugins, | ||
20 | reRunServer, | 14 | reRunServer, |
21 | ServerInfo, | 15 | ServerInfo, |
22 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
23 | setPluginVersion, | 17 | setPluginVersion, |
24 | testHelloWorldRegisteredSettings, | 18 | testHelloWorldRegisteredSettings, |
25 | uninstallPlugin, | ||
26 | updateCustomSubConfig, | 19 | updateCustomSubConfig, |
27 | updateMyUser, | 20 | updateMyUser, |
28 | updatePlugin, | ||
29 | updatePluginPackageJSON, | ||
30 | updatePluginSettings, | ||
31 | wait, | 21 | wait, |
32 | waitUntilLog | 22 | waitUntilLog |
33 | } from '@shared/extra-utils' | 23 | } from '@shared/extra-utils' |
34 | import { PeerTubePlugin, PeerTubePluginIndex, PluginPackageJson, PluginType, PublicServerSetting, ServerConfig, User } from '@shared/models' | 24 | import { PluginType, ServerConfig, User } from '@shared/models' |
35 | 25 | ||
36 | const expect = chai.expect | 26 | const expect = chai.expect |
37 | 27 | ||
38 | describe('Test plugins', function () { | 28 | describe('Test plugins', function () { |
39 | let server: ServerInfo = null | 29 | let server: ServerInfo = null |
30 | let command: PluginsCommand | ||
40 | 31 | ||
41 | before(async function () { | 32 | before(async function () { |
42 | this.timeout(30000) | 33 | this.timeout(30000) |
@@ -54,60 +45,51 @@ describe('Test plugins', function () { | |||
54 | this.timeout(30000) | 45 | this.timeout(30000) |
55 | 46 | ||
56 | { | 47 | { |
57 | const res = await listAvailablePlugins({ | 48 | const body = await command.listAvailable({ |
58 | url: server.url, | ||
59 | accessToken: server.accessToken, | ||
60 | count: 1, | 49 | count: 1, |
61 | start: 0, | 50 | start: 0, |
62 | pluginType: PluginType.THEME, | 51 | pluginType: PluginType.THEME, |
63 | search: 'background-red' | 52 | search: 'background-red' |
64 | }) | 53 | }) |
65 | 54 | ||
66 | expect(res.body.total).to.be.at.least(1) | 55 | expect(body.total).to.be.at.least(1) |
67 | expect(res.body.data).to.have.lengthOf(1) | 56 | expect(body.data).to.have.lengthOf(1) |
68 | } | 57 | } |
69 | 58 | ||
70 | { | 59 | { |
71 | const res1 = await listAvailablePlugins({ | 60 | const body1 = await command.listAvailable({ |
72 | url: server.url, | ||
73 | accessToken: server.accessToken, | ||
74 | count: 2, | 61 | count: 2, |
75 | start: 0, | 62 | start: 0, |
76 | sort: 'npmName' | 63 | sort: 'npmName' |
77 | }) | 64 | }) |
78 | const data1: PeerTubePluginIndex[] = res1.body.data | 65 | expect(body1.total).to.be.at.least(2) |
79 | 66 | ||
80 | expect(res1.body.total).to.be.at.least(2) | 67 | const data1 = body1.data |
81 | expect(data1).to.have.lengthOf(2) | 68 | expect(data1).to.have.lengthOf(2) |
82 | 69 | ||
83 | const res2 = await listAvailablePlugins({ | 70 | const body2 = await command.listAvailable({ |
84 | url: server.url, | ||
85 | accessToken: server.accessToken, | ||
86 | count: 2, | 71 | count: 2, |
87 | start: 0, | 72 | start: 0, |
88 | sort: '-npmName' | 73 | sort: '-npmName' |
89 | }) | 74 | }) |
90 | const data2: PeerTubePluginIndex[] = res2.body.data | 75 | expect(body2.total).to.be.at.least(2) |
91 | 76 | ||
92 | expect(res2.body.total).to.be.at.least(2) | 77 | const data2 = body2.data |
93 | expect(data2).to.have.lengthOf(2) | 78 | expect(data2).to.have.lengthOf(2) |
94 | 79 | ||
95 | expect(data1[0].npmName).to.not.equal(data2[0].npmName) | 80 | expect(data1[0].npmName).to.not.equal(data2[0].npmName) |
96 | } | 81 | } |
97 | 82 | ||
98 | { | 83 | { |
99 | const res = await listAvailablePlugins({ | 84 | const body = await command.listAvailable({ |
100 | url: server.url, | ||
101 | accessToken: server.accessToken, | ||
102 | count: 10, | 85 | count: 10, |
103 | start: 0, | 86 | start: 0, |
104 | pluginType: PluginType.THEME, | 87 | pluginType: PluginType.THEME, |
105 | search: 'background-red', | 88 | search: 'background-red', |
106 | currentPeerTubeEngine: '1.0.0' | 89 | currentPeerTubeEngine: '1.0.0' |
107 | }) | 90 | }) |
108 | const data: PeerTubePluginIndex[] = res.body.data | ||
109 | 91 | ||
110 | const p = data.find(p => p.npmName === 'peertube-theme-background-red') | 92 | const p = body.data.find(p => p.npmName === 'peertube-theme-background-red') |
111 | expect(p).to.be.undefined | 93 | expect(p).to.be.undefined |
112 | } | 94 | } |
113 | }) | 95 | }) |
@@ -115,17 +97,8 @@ describe('Test plugins', function () { | |||
115 | it('Should install a plugin and a theme', async function () { | 97 | it('Should install a plugin and a theme', async function () { |
116 | this.timeout(30000) | 98 | this.timeout(30000) |
117 | 99 | ||
118 | await installPlugin({ | 100 | await command.install({ npmName: 'peertube-plugin-hello-world' }) |
119 | url: server.url, | 101 | await command.install({ npmName: 'peertube-theme-background-red' }) |
120 | accessToken: server.accessToken, | ||
121 | npmName: 'peertube-plugin-hello-world' | ||
122 | }) | ||
123 | |||
124 | await installPlugin({ | ||
125 | url: server.url, | ||
126 | accessToken: server.accessToken, | ||
127 | npmName: 'peertube-theme-background-red' | ||
128 | }) | ||
129 | }) | 102 | }) |
130 | 103 | ||
131 | it('Should have the plugin loaded in the configuration', async function () { | 104 | it('Should have the plugin loaded in the configuration', async function () { |
@@ -161,45 +134,38 @@ describe('Test plugins', function () { | |||
161 | 134 | ||
162 | it('Should list plugins and themes', async function () { | 135 | it('Should list plugins and themes', async function () { |
163 | { | 136 | { |
164 | const res = await listPlugins({ | 137 | const body = await command.list({ |
165 | url: server.url, | ||
166 | accessToken: server.accessToken, | ||
167 | count: 1, | 138 | count: 1, |
168 | start: 0, | 139 | start: 0, |
169 | pluginType: PluginType.THEME | 140 | pluginType: PluginType.THEME |
170 | }) | 141 | }) |
171 | const data: PeerTubePlugin[] = res.body.data | 142 | expect(body.total).to.be.at.least(1) |
172 | 143 | ||
173 | expect(res.body.total).to.be.at.least(1) | 144 | const data = body.data |
174 | expect(data).to.have.lengthOf(1) | 145 | expect(data).to.have.lengthOf(1) |
175 | expect(data[0].name).to.equal('background-red') | 146 | expect(data[0].name).to.equal('background-red') |
176 | } | 147 | } |
177 | 148 | ||
178 | { | 149 | { |
179 | const res = await listPlugins({ | 150 | const body = await command.list({ |
180 | url: server.url, | ||
181 | accessToken: server.accessToken, | ||
182 | count: 2, | 151 | count: 2, |
183 | start: 0, | 152 | start: 0, |
184 | sort: 'name' | 153 | sort: 'name' |
185 | }) | 154 | }) |
186 | const data: PeerTubePlugin[] = res.body.data | ||
187 | 155 | ||
156 | const data = body | ||
188 | expect(data[0].name).to.equal('background-red') | 157 | expect(data[0].name).to.equal('background-red') |
189 | expect(data[1].name).to.equal('hello-world') | 158 | expect(data[1].name).to.equal('hello-world') |
190 | } | 159 | } |
191 | 160 | ||
192 | { | 161 | { |
193 | const res = await listPlugins({ | 162 | const body = await command.list({ |
194 | url: server.url, | ||
195 | accessToken: server.accessToken, | ||
196 | count: 2, | 163 | count: 2, |
197 | start: 1, | 164 | start: 1, |
198 | sort: 'name' | 165 | sort: 'name' |
199 | }) | 166 | }) |
200 | const data: PeerTubePlugin[] = res.body.data | ||
201 | 167 | ||
202 | expect(data[0].name).to.equal('hello-world') | 168 | expect(body.data[0].name).to.equal('hello-world') |
203 | } | 169 | } |
204 | }) | 170 | }) |
205 | 171 | ||
@@ -208,9 +174,8 @@ describe('Test plugins', function () { | |||
208 | }) | 174 | }) |
209 | 175 | ||
210 | it('Should get public settings', async function () { | 176 | it('Should get public settings', async function () { |
211 | const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' }) | 177 | const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' }) |
212 | 178 | const publicSettings = body.publicSettings | |
213 | const publicSettings = (res.body as PublicServerSetting).publicSettings | ||
214 | 179 | ||
215 | expect(Object.keys(publicSettings)).to.have.lengthOf(1) | 180 | expect(Object.keys(publicSettings)).to.have.lengthOf(1) |
216 | expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) | 181 | expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) |
@@ -222,9 +187,7 @@ describe('Test plugins', function () { | |||
222 | 'admin-name': 'Cid' | 187 | 'admin-name': 'Cid' |
223 | } | 188 | } |
224 | 189 | ||
225 | await updatePluginSettings({ | 190 | await command.updateSettings({ |
226 | url: server.url, | ||
227 | accessToken: server.accessToken, | ||
228 | npmName: 'peertube-plugin-hello-world', | 191 | npmName: 'peertube-plugin-hello-world', |
229 | settings | 192 | settings |
230 | }) | 193 | }) |
@@ -238,13 +201,7 @@ describe('Test plugins', function () { | |||
238 | 201 | ||
239 | it('Should get a plugin and a theme', async function () { | 202 | it('Should get a plugin and a theme', async function () { |
240 | { | 203 | { |
241 | const res = await getPlugin({ | 204 | const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' }) |
242 | url: server.url, | ||
243 | accessToken: server.accessToken, | ||
244 | npmName: 'peertube-plugin-hello-world' | ||
245 | }) | ||
246 | |||
247 | const plugin: PeerTubePlugin = res.body | ||
248 | 205 | ||
249 | expect(plugin.type).to.equal(PluginType.PLUGIN) | 206 | expect(plugin.type).to.equal(PluginType.PLUGIN) |
250 | expect(plugin.name).to.equal('hello-world') | 207 | expect(plugin.name).to.equal('hello-world') |
@@ -262,13 +219,7 @@ describe('Test plugins', function () { | |||
262 | } | 219 | } |
263 | 220 | ||
264 | { | 221 | { |
265 | const res = await getPlugin({ | 222 | const plugin = await command.get({ npmName: 'peertube-theme-background-red' }) |
266 | url: server.url, | ||
267 | accessToken: server.accessToken, | ||
268 | npmName: 'peertube-theme-background-red' | ||
269 | }) | ||
270 | |||
271 | const plugin: PeerTubePlugin = res.body | ||
272 | 223 | ||
273 | expect(plugin.type).to.equal(PluginType.THEME) | 224 | expect(plugin.type).to.equal(PluginType.THEME) |
274 | expect(plugin.name).to.equal('background-red') | 225 | expect(plugin.name).to.equal('background-red') |
@@ -295,92 +246,59 @@ describe('Test plugins', function () { | |||
295 | await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') | 246 | await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') |
296 | 247 | ||
297 | // Fake update package.json | 248 | // Fake update package.json |
298 | const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') | 249 | const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
299 | const oldVersion = packageJSON.version | 250 | const oldVersion = packageJSON.version |
300 | 251 | ||
301 | packageJSON.version = '0.0.1' | 252 | packageJSON.version = '0.0.1' |
302 | await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON) | 253 | await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) |
303 | 254 | ||
304 | // Restart the server to take into account this change | 255 | // Restart the server to take into account this change |
305 | killallServers([ server ]) | 256 | killallServers([ server ]) |
306 | await reRunServer(server) | 257 | await reRunServer(server) |
307 | 258 | ||
308 | { | 259 | { |
309 | const res = await listPlugins({ | 260 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
310 | url: server.url, | ||
311 | accessToken: server.accessToken, | ||
312 | pluginType: PluginType.PLUGIN | ||
313 | }) | ||
314 | |||
315 | const plugin: PeerTubePlugin = res.body.data[0] | ||
316 | 261 | ||
262 | const plugin = body.data[0] | ||
317 | expect(plugin.version).to.equal('0.0.1') | 263 | expect(plugin.version).to.equal('0.0.1') |
318 | expect(plugin.latestVersion).to.exist | 264 | expect(plugin.latestVersion).to.exist |
319 | expect(plugin.latestVersion).to.not.equal('0.0.1') | 265 | expect(plugin.latestVersion).to.not.equal('0.0.1') |
320 | } | 266 | } |
321 | 267 | ||
322 | { | 268 | { |
323 | await updatePlugin({ | 269 | await command.update({ npmName: 'peertube-plugin-hello-world' }) |
324 | url: server.url, | ||
325 | accessToken: server.accessToken, | ||
326 | npmName: 'peertube-plugin-hello-world' | ||
327 | }) | ||
328 | |||
329 | const res = await listPlugins({ | ||
330 | url: server.url, | ||
331 | accessToken: server.accessToken, | ||
332 | pluginType: PluginType.PLUGIN | ||
333 | }) | ||
334 | 270 | ||
335 | const plugin: PeerTubePlugin = res.body.data[0] | 271 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
336 | 272 | ||
273 | const plugin = body.data[0] | ||
337 | expect(plugin.version).to.equal(oldVersion) | 274 | expect(plugin.version).to.equal(oldVersion) |
338 | 275 | ||
339 | const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') | 276 | const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
340 | expect(updatedPackageJSON.version).to.equal(oldVersion) | 277 | expect(updatedPackageJSON.version).to.equal(oldVersion) |
341 | } | 278 | } |
342 | }) | 279 | }) |
343 | 280 | ||
344 | it('Should uninstall the plugin', async function () { | 281 | it('Should uninstall the plugin', async function () { |
345 | await uninstallPlugin({ | 282 | await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) |
346 | url: server.url, | ||
347 | accessToken: server.accessToken, | ||
348 | npmName: 'peertube-plugin-hello-world' | ||
349 | }) | ||
350 | |||
351 | const res = await listPlugins({ | ||
352 | url: server.url, | ||
353 | accessToken: server.accessToken, | ||
354 | pluginType: PluginType.PLUGIN | ||
355 | }) | ||
356 | 283 | ||
357 | expect(res.body.total).to.equal(0) | 284 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
358 | expect(res.body.data).to.have.lengthOf(0) | 285 | expect(body.total).to.equal(0) |
286 | expect(body.data).to.have.lengthOf(0) | ||
359 | }) | 287 | }) |
360 | 288 | ||
361 | it('Should list uninstalled plugins', async function () { | 289 | it('Should list uninstalled plugins', async function () { |
362 | const res = await listPlugins({ | 290 | const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true }) |
363 | url: server.url, | 291 | expect(body.total).to.equal(1) |
364 | accessToken: server.accessToken, | 292 | expect(body.data).to.have.lengthOf(1) |
365 | pluginType: PluginType.PLUGIN, | ||
366 | uninstalled: true | ||
367 | }) | ||
368 | 293 | ||
369 | expect(res.body.total).to.equal(1) | 294 | const plugin = body.data[0] |
370 | expect(res.body.data).to.have.lengthOf(1) | ||
371 | |||
372 | const plugin: PeerTubePlugin = res.body.data[0] | ||
373 | expect(plugin.name).to.equal('hello-world') | 295 | expect(plugin.name).to.equal('hello-world') |
374 | expect(plugin.enabled).to.be.false | 296 | expect(plugin.enabled).to.be.false |
375 | expect(plugin.uninstalled).to.be.true | 297 | expect(plugin.uninstalled).to.be.true |
376 | }) | 298 | }) |
377 | 299 | ||
378 | it('Should uninstall the theme', async function () { | 300 | it('Should uninstall the theme', async function () { |
379 | await uninstallPlugin({ | 301 | await command.uninstall({ npmName: 'peertube-theme-background-red' }) |
380 | url: server.url, | ||
381 | accessToken: server.accessToken, | ||
382 | npmName: 'peertube-theme-background-red' | ||
383 | }) | ||
384 | }) | 302 | }) |
385 | 303 | ||
386 | it('Should have updated the configuration', async function () { | 304 | it('Should have updated the configuration', async function () { |
@@ -406,21 +324,13 @@ describe('Test plugins', function () { | |||
406 | this.timeout(60000) | 324 | this.timeout(60000) |
407 | 325 | ||
408 | async function check () { | 326 | async function check () { |
409 | const res = await listPlugins({ | 327 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
410 | url: server.url, | 328 | const plugins = body.data |
411 | accessToken: server.accessToken, | ||
412 | pluginType: PluginType.PLUGIN | ||
413 | }) | ||
414 | |||
415 | const plugins: PeerTubePlugin[] = res.body.data | ||
416 | |||
417 | expect(plugins.find(p => p.name === 'test-broken')).to.not.exist | 329 | expect(plugins.find(p => p.name === 'test-broken')).to.not.exist |
418 | } | 330 | } |
419 | 331 | ||
420 | await installPlugin({ | 332 | await command.install({ |
421 | url: server.url, | 333 | path: PluginsCommand.getPluginTestPath('-broken'), |
422 | accessToken: server.accessToken, | ||
423 | path: getPluginTestPath('-broken'), | ||
424 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | 334 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
425 | }) | 335 | }) |
426 | 336 | ||
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 92927ea97..ba4183e08 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -23,7 +23,6 @@ import { | |||
23 | getUsersListPaginationAndSort, | 23 | getUsersListPaginationAndSort, |
24 | getVideoChannel, | 24 | getVideoChannel, |
25 | getVideosList, | 25 | getVideosList, |
26 | installPlugin, | ||
27 | killallServers, | 26 | killallServers, |
28 | login, | 27 | login, |
29 | logout, | 28 | logout, |
@@ -75,7 +74,7 @@ describe('Test users', function () { | |||
75 | 74 | ||
76 | await setAccessTokensToServers([ server ]) | 75 | await setAccessTokensToServers([ server ]) |
77 | 76 | ||
78 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | 77 | await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) |
79 | }) | 78 | }) |
80 | 79 | ||
81 | describe('OAuth client', function () { | 80 | describe('OAuth client', function () { |
diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts index efdc20748..7b8746a5d 100644 --- a/server/tests/cli/plugins.ts +++ b/server/tests/cli/plugins.ts | |||
@@ -6,8 +6,8 @@ import { | |||
6 | cleanupTests, | 6 | cleanupTests, |
7 | flushAndRunServer, | 7 | flushAndRunServer, |
8 | getConfig, | 8 | getConfig, |
9 | getPluginTestPath, | ||
10 | killallServers, | 9 | killallServers, |
10 | PluginsCommand, | ||
11 | reRunServer, | 11 | reRunServer, |
12 | ServerInfo, | 12 | ServerInfo, |
13 | setAccessTokensToServers | 13 | setAccessTokensToServers |
@@ -27,7 +27,7 @@ describe('Test plugin scripts', function () { | |||
27 | it('Should install a plugin from stateless CLI', async function () { | 27 | it('Should install a plugin from stateless CLI', async function () { |
28 | this.timeout(60000) | 28 | this.timeout(60000) |
29 | 29 | ||
30 | const packagePath = getPluginTestPath() | 30 | const packagePath = PluginsCommand.getPluginTestPath() |
31 | 31 | ||
32 | await server.cliCommand.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`) | 32 | await server.cliCommand.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`) |
33 | }) | 33 | }) |
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts index e4eae7e8c..0d4edbee0 100644 --- a/server/tests/external-plugins/auth-ldap.ts +++ b/server/tests/external-plugins/auth-ldap.ts | |||
@@ -3,17 +3,7 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { User } from '@shared/models/users/user.model' | 5 | import { User } from '@shared/models/users/user.model' |
6 | import { | 6 | import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils' |
7 | blockUser, | ||
8 | getMyUserInformation, | ||
9 | installPlugin, | ||
10 | setAccessTokensToServers, | ||
11 | unblockUser, | ||
12 | uninstallPlugin, | ||
13 | updatePluginSettings, | ||
14 | uploadVideo, | ||
15 | userLogin | ||
16 | } from '../../../shared/extra-utils' | ||
17 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 7 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
18 | 8 | ||
19 | describe('Official plugin auth-ldap', function () { | 9 | describe('Official plugin auth-ldap', function () { |
@@ -27,11 +17,7 @@ describe('Official plugin auth-ldap', function () { | |||
27 | server = await flushAndRunServer(1) | 17 | server = await flushAndRunServer(1) |
28 | await setAccessTokensToServers([ server ]) | 18 | await setAccessTokensToServers([ server ]) |
29 | 19 | ||
30 | await installPlugin({ | 20 | await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' }) |
31 | url: server.url, | ||
32 | accessToken: server.accessToken, | ||
33 | npmName: 'peertube-plugin-auth-ldap' | ||
34 | }) | ||
35 | }) | 21 | }) |
36 | 22 | ||
37 | it('Should not login with without LDAP settings', async function () { | 23 | it('Should not login with without LDAP settings', async function () { |
@@ -39,9 +25,7 @@ describe('Official plugin auth-ldap', function () { | |||
39 | }) | 25 | }) |
40 | 26 | ||
41 | it('Should not login with bad LDAP settings', async function () { | 27 | it('Should not login with bad LDAP settings', async function () { |
42 | await updatePluginSettings({ | 28 | await server.pluginsCommand.updateSettings({ |
43 | url: server.url, | ||
44 | accessToken: server.accessToken, | ||
45 | npmName: 'peertube-plugin-auth-ldap', | 29 | npmName: 'peertube-plugin-auth-ldap', |
46 | settings: { | 30 | settings: { |
47 | 'bind-credentials': 'GoodNewsEveryone', | 31 | 'bind-credentials': 'GoodNewsEveryone', |
@@ -59,9 +43,7 @@ describe('Official plugin auth-ldap', function () { | |||
59 | }) | 43 | }) |
60 | 44 | ||
61 | it('Should not login with good LDAP settings but wrong username/password', async function () { | 45 | it('Should not login with good LDAP settings but wrong username/password', async function () { |
62 | await updatePluginSettings({ | 46 | await server.pluginsCommand.updateSettings({ |
63 | url: server.url, | ||
64 | accessToken: server.accessToken, | ||
65 | npmName: 'peertube-plugin-auth-ldap', | 47 | npmName: 'peertube-plugin-auth-ldap', |
66 | settings: { | 48 | settings: { |
67 | 'bind-credentials': 'GoodNewsEveryone', | 49 | 'bind-credentials': 'GoodNewsEveryone', |
@@ -114,7 +96,7 @@ describe('Official plugin auth-ldap', function () { | |||
114 | }) | 96 | }) |
115 | 97 | ||
116 | it('Should not login if the plugin is uninstalled', async function () { | 98 | it('Should not login if the plugin is uninstalled', async function () { |
117 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' }) | 99 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) |
118 | 100 | ||
119 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) | 101 | await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) |
120 | }) | 102 | }) |
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts index 18ea17d78..6baf37566 100644 --- a/server/tests/external-plugins/auto-block-videos.ts +++ b/server/tests/external-plugins/auto-block-videos.ts | |||
@@ -7,11 +7,9 @@ import { | |||
7 | doubleFollow, | 7 | doubleFollow, |
8 | getBlacklistedVideosList, | 8 | getBlacklistedVideosList, |
9 | getVideosList, | 9 | getVideosList, |
10 | installPlugin, | ||
11 | MockBlocklist, | 10 | MockBlocklist, |
12 | removeVideoFromBlacklist, | 11 | removeVideoFromBlacklist, |
13 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
14 | updatePluginSettings, | ||
15 | uploadVideoAndGetId, | 13 | uploadVideoAndGetId, |
16 | wait | 14 | wait |
17 | } from '../../../shared/extra-utils' | 15 | } from '../../../shared/extra-utils' |
@@ -28,11 +26,8 @@ async function check (server: ServerInfo, videoUUID: string, exists = true) { | |||
28 | 26 | ||
29 | const video = res.body.data.find(v => v.uuid === videoUUID) | 27 | const video = res.body.data.find(v => v.uuid === videoUUID) |
30 | 28 | ||
31 | if (exists) { | 29 | if (exists) expect(video).to.not.be.undefined |
32 | expect(video).to.not.be.undefined | 30 | else expect(video).to.be.undefined |
33 | } else { | ||
34 | expect(video).to.be.undefined | ||
35 | } | ||
36 | } | 31 | } |
37 | 32 | ||
38 | describe('Official plugin auto-block videos', function () { | 33 | describe('Official plugin auto-block videos', function () { |
@@ -49,11 +44,7 @@ describe('Official plugin auto-block videos', function () { | |||
49 | await setAccessTokensToServers(servers) | 44 | await setAccessTokensToServers(servers) |
50 | 45 | ||
51 | for (const server of servers) { | 46 | for (const server of servers) { |
52 | await installPlugin({ | 47 | await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-block-videos' }) |
53 | url: server.url, | ||
54 | accessToken: server.accessToken, | ||
55 | npmName: 'peertube-plugin-auto-block-videos' | ||
56 | }) | ||
57 | } | 48 | } |
58 | 49 | ||
59 | blocklistServer = new MockBlocklist() | 50 | blocklistServer = new MockBlocklist() |
@@ -78,9 +69,7 @@ describe('Official plugin auto-block videos', function () { | |||
78 | }) | 69 | }) |
79 | 70 | ||
80 | it('Should update plugin settings', async function () { | 71 | it('Should update plugin settings', async function () { |
81 | await updatePluginSettings({ | 72 | await servers[0].pluginsCommand.updateSettings({ |
82 | url: servers[0].url, | ||
83 | accessToken: servers[0].accessToken, | ||
84 | npmName: 'peertube-plugin-auto-block-videos', | 73 | npmName: 'peertube-plugin-auto-block-videos', |
85 | settings: { | 74 | settings: { |
86 | 'blocklist-urls': `http://localhost:${port}/blocklist`, | 75 | 'blocklist-urls': `http://localhost:${port}/blocklist`, |
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts index 09355d932..8fcf94452 100644 --- a/server/tests/external-plugins/auto-mute.ts +++ b/server/tests/external-plugins/auto-mute.ts | |||
@@ -2,30 +2,24 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
5 | import { | 6 | import { |
6 | addAccountToServerBlocklist, | 7 | addAccountToServerBlocklist, |
7 | addServerToAccountBlocklist, | 8 | addServerToAccountBlocklist, |
8 | removeAccountFromServerBlocklist | 9 | cleanupTests, |
9 | } from '@shared/extra-utils/users/blocklist' | ||
10 | import { | ||
11 | doubleFollow, | 10 | doubleFollow, |
11 | flushAndRunMultipleServers, | ||
12 | getVideosList, | 12 | getVideosList, |
13 | installPlugin, | 13 | killallServers, |
14 | makeGetRequest, | 14 | makeGetRequest, |
15 | MockBlocklist, | 15 | MockBlocklist, |
16 | removeAccountFromServerBlocklist, | ||
17 | reRunServer, | ||
18 | ServerInfo, | ||
16 | setAccessTokensToServers, | 19 | setAccessTokensToServers, |
17 | updatePluginSettings, | ||
18 | uploadVideoAndGetId, | 20 | uploadVideoAndGetId, |
19 | wait | 21 | wait |
20 | } from '../../../shared/extra-utils' | 22 | } from '@shared/extra-utils' |
21 | import { | ||
22 | cleanupTests, | ||
23 | flushAndRunMultipleServers, | ||
24 | killallServers, | ||
25 | reRunServer, | ||
26 | ServerInfo | ||
27 | } from '../../../shared/extra-utils/server/servers' | ||
28 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
29 | 23 | ||
30 | describe('Official plugin auto-mute', function () { | 24 | describe('Official plugin auto-mute', function () { |
31 | const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' | 25 | const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' |
@@ -40,11 +34,7 @@ describe('Official plugin auto-mute', function () { | |||
40 | await setAccessTokensToServers(servers) | 34 | await setAccessTokensToServers(servers) |
41 | 35 | ||
42 | for (const server of servers) { | 36 | for (const server of servers) { |
43 | await installPlugin({ | 37 | await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' }) |
44 | url: server.url, | ||
45 | accessToken: server.accessToken, | ||
46 | npmName: 'peertube-plugin-auto-mute' | ||
47 | }) | ||
48 | } | 38 | } |
49 | 39 | ||
50 | blocklistServer = new MockBlocklist() | 40 | blocklistServer = new MockBlocklist() |
@@ -57,9 +47,7 @@ describe('Official plugin auto-mute', function () { | |||
57 | }) | 47 | }) |
58 | 48 | ||
59 | it('Should update plugin settings', async function () { | 49 | it('Should update plugin settings', async function () { |
60 | await updatePluginSettings({ | 50 | await servers[0].pluginsCommand.updateSettings({ |
61 | url: servers[0].url, | ||
62 | accessToken: servers[0].accessToken, | ||
63 | npmName: 'peertube-plugin-auto-mute', | 51 | npmName: 'peertube-plugin-auto-mute', |
64 | settings: { | 52 | settings: { |
65 | 'blocklist-urls': `http://localhost:${port}/blocklist`, | 53 | 'blocklist-urls': `http://localhost:${port}/blocklist`, |
@@ -185,9 +173,7 @@ describe('Official plugin auto-mute', function () { | |||
185 | }) | 173 | }) |
186 | 174 | ||
187 | it('Should enable auto mute list', async function () { | 175 | it('Should enable auto mute list', async function () { |
188 | await updatePluginSettings({ | 176 | await servers[0].pluginsCommand.updateSettings({ |
189 | url: servers[0].url, | ||
190 | accessToken: servers[0].accessToken, | ||
191 | npmName: 'peertube-plugin-auto-mute', | 177 | npmName: 'peertube-plugin-auto-mute', |
192 | settings: { | 178 | settings: { |
193 | 'blocklist-urls': '', | 179 | 'blocklist-urls': '', |
@@ -206,9 +192,7 @@ describe('Official plugin auto-mute', function () { | |||
206 | it('Should mute an account on server 1, and server 2 auto mutes it', async function () { | 192 | it('Should mute an account on server 1, and server 2 auto mutes it', async function () { |
207 | this.timeout(20000) | 193 | this.timeout(20000) |
208 | 194 | ||
209 | await updatePluginSettings({ | 195 | await servers[1].pluginsCommand.updateSettings({ |
210 | url: servers[1].url, | ||
211 | accessToken: servers[1].accessToken, | ||
212 | npmName: 'peertube-plugin-auto-mute', | 196 | npmName: 'peertube-plugin-auto-mute', |
213 | settings: { | 197 | settings: { |
214 | 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath, | 198 | 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath, |
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 0f57ef7fe..0de5b523b 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts | |||
@@ -11,8 +11,7 @@ import { | |||
11 | createUser, | 11 | createUser, |
12 | createVideoPlaylist, | 12 | createVideoPlaylist, |
13 | deleteVideoComment, | 13 | deleteVideoComment, |
14 | getPluginTestPath, | 14 | PluginsCommand, |
15 | installPlugin, | ||
16 | registerUser, | 15 | registerUser, |
17 | removeUser, | 16 | removeUser, |
18 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
@@ -49,11 +48,7 @@ describe('Test plugin action hooks', function () { | |||
49 | await setAccessTokensToServers(servers) | 48 | await setAccessTokensToServers(servers) |
50 | await setDefaultVideoChannel(servers) | 49 | await setDefaultVideoChannel(servers) |
51 | 50 | ||
52 | await installPlugin({ | 51 | await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) |
53 | url: servers[0].url, | ||
54 | accessToken: servers[0].accessToken, | ||
55 | path: getPluginTestPath() | ||
56 | }) | ||
57 | 52 | ||
58 | killallServers([ servers[0] ]) | 53 | killallServers([ servers[0] ]) |
59 | 54 | ||
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 5addb45c7..424302786 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts | |||
@@ -2,27 +2,26 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { ServerConfig, User, UserRole } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { | 6 | import { |
7 | cleanupTests, | ||
8 | createUser, | ||
7 | decodeQueryString, | 9 | decodeQueryString, |
10 | flushAndRunServer, | ||
8 | getConfig, | 11 | getConfig, |
9 | getExternalAuth, | ||
10 | getMyUserInformation, | 12 | getMyUserInformation, |
11 | getPluginTestPath, | ||
12 | installPlugin, | ||
13 | loginUsingExternalToken, | 13 | loginUsingExternalToken, |
14 | logout, | 14 | logout, |
15 | PluginsCommand, | ||
15 | refreshToken, | 16 | refreshToken, |
17 | ServerInfo, | ||
16 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
17 | uninstallPlugin, | ||
18 | updateMyUser, | 19 | updateMyUser, |
19 | wait, | ||
20 | userLogin, | 20 | userLogin, |
21 | updatePluginSettings, | 21 | wait, |
22 | createUser | 22 | waitUntilLog |
23 | } from '../../../shared/extra-utils' | 23 | } from '@shared/extra-utils' |
24 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | 24 | import { ServerConfig, User, UserRole } from '@shared/models' |
25 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
26 | 25 | ||
27 | async function loginExternal (options: { | 26 | async function loginExternal (options: { |
28 | server: ServerInfo | 27 | server: ServerInfo |
@@ -33,13 +32,12 @@ async function loginExternal (options: { | |||
33 | statusCodeExpected?: HttpStatusCode | 32 | statusCodeExpected?: HttpStatusCode |
34 | statusCodeExpectedStep2?: HttpStatusCode | 33 | statusCodeExpectedStep2?: HttpStatusCode |
35 | }) { | 34 | }) { |
36 | const res = await getExternalAuth({ | 35 | const res = await options.server.pluginsCommand.getExternalAuth({ |
37 | url: options.server.url, | ||
38 | npmName: options.npmName, | 36 | npmName: options.npmName, |
39 | npmVersion: '0.0.1', | 37 | npmVersion: '0.0.1', |
40 | authName: options.authName, | 38 | authName: options.authName, |
41 | query: options.query, | 39 | query: options.query, |
42 | statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302 | 40 | expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302 |
43 | }) | 41 | }) |
44 | 42 | ||
45 | if (res.status !== HttpStatusCode.FOUND_302) return | 43 | if (res.status !== HttpStatusCode.FOUND_302) return |
@@ -75,11 +73,7 @@ describe('Test external auth plugins', function () { | |||
75 | await setAccessTokensToServers([ server ]) | 73 | await setAccessTokensToServers([ server ]) |
76 | 74 | ||
77 | for (const suffix of [ 'one', 'two', 'three' ]) { | 75 | for (const suffix of [ 'one', 'two', 'three' ]) { |
78 | await installPlugin({ | 76 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) }) |
79 | url: server.url, | ||
80 | accessToken: server.accessToken, | ||
81 | path: getPluginTestPath('-external-auth-' + suffix) | ||
82 | }) | ||
83 | } | 77 | } |
84 | }) | 78 | }) |
85 | 79 | ||
@@ -98,15 +92,14 @@ describe('Test external auth plugins', function () { | |||
98 | }) | 92 | }) |
99 | 93 | ||
100 | it('Should redirect for a Cyan login', async function () { | 94 | it('Should redirect for a Cyan login', async function () { |
101 | const res = await getExternalAuth({ | 95 | const res = await server.pluginsCommand.getExternalAuth({ |
102 | url: server.url, | ||
103 | npmName: 'test-external-auth-one', | 96 | npmName: 'test-external-auth-one', |
104 | npmVersion: '0.0.1', | 97 | npmVersion: '0.0.1', |
105 | authName: 'external-auth-1', | 98 | authName: 'external-auth-1', |
106 | query: { | 99 | query: { |
107 | username: 'cyan' | 100 | username: 'cyan' |
108 | }, | 101 | }, |
109 | statusCodeExpected: HttpStatusCode.FOUND_302 | 102 | expectedStatus: HttpStatusCode.FOUND_302 |
110 | }) | 103 | }) |
111 | 104 | ||
112 | const location = res.header.location | 105 | const location = res.header.location |
@@ -275,9 +268,7 @@ describe('Test external auth plugins', function () { | |||
275 | }) | 268 | }) |
276 | 269 | ||
277 | it('Should unregister external-auth-2 and do not login existing Kefka', async function () { | 270 | it('Should unregister external-auth-2 and do not login existing Kefka', async function () { |
278 | await updatePluginSettings({ | 271 | await server.pluginsCommand.updateSettings({ |
279 | url: server.url, | ||
280 | accessToken: server.accessToken, | ||
281 | npmName: 'peertube-plugin-test-external-auth-one', | 272 | npmName: 'peertube-plugin-test-external-auth-one', |
282 | settings: { disableKefka: true } | 273 | settings: { disableKefka: true } |
283 | }) | 274 | }) |
@@ -309,11 +300,7 @@ describe('Test external auth plugins', function () { | |||
309 | }) | 300 | }) |
310 | 301 | ||
311 | it('Should uninstall the plugin one and do not login Cyan', async function () { | 302 | it('Should uninstall the plugin one and do not login Cyan', async function () { |
312 | await uninstallPlugin({ | 303 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' }) |
313 | url: server.url, | ||
314 | accessToken: server.accessToken, | ||
315 | npmName: 'peertube-plugin-test-external-auth-one' | ||
316 | }) | ||
317 | 304 | ||
318 | await loginExternal({ | 305 | await loginExternal({ |
319 | server, | 306 | server, |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index e2ec5457b..c51e96ab7 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -14,7 +14,6 @@ import { | |||
14 | getAccountVideos, | 14 | getAccountVideos, |
15 | getConfig, | 15 | getConfig, |
16 | getMyVideos, | 16 | getMyVideos, |
17 | getPluginTestPath, | ||
18 | getVideo, | 17 | getVideo, |
19 | getVideoChannelVideos, | 18 | getVideoChannelVideos, |
20 | getVideoCommentThreads, | 19 | getVideoCommentThreads, |
@@ -23,8 +22,8 @@ import { | |||
23 | getVideosListPagination, | 22 | getVideosListPagination, |
24 | getVideoThreadComments, | 23 | getVideoThreadComments, |
25 | getVideoWithToken, | 24 | getVideoWithToken, |
26 | installPlugin, | ||
27 | makeRawRequest, | 25 | makeRawRequest, |
26 | PluginsCommand, | ||
28 | registerUser, | 27 | registerUser, |
29 | ServerInfo, | 28 | ServerInfo, |
30 | setAccessTokensToServers, | 29 | setAccessTokensToServers, |
@@ -63,17 +62,8 @@ describe('Test plugin filter hooks', function () { | |||
63 | await setDefaultVideoChannel(servers) | 62 | await setDefaultVideoChannel(servers) |
64 | await doubleFollow(servers[0], servers[1]) | 63 | await doubleFollow(servers[0], servers[1]) |
65 | 64 | ||
66 | await installPlugin({ | 65 | await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() }) |
67 | url: servers[0].url, | 66 | await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) |
68 | accessToken: servers[0].accessToken, | ||
69 | path: getPluginTestPath() | ||
70 | }) | ||
71 | |||
72 | await installPlugin({ | ||
73 | url: servers[0].url, | ||
74 | accessToken: servers[0].accessToken, | ||
75 | path: getPluginTestPath('-filter-translations') | ||
76 | }) | ||
77 | 67 | ||
78 | for (let i = 0; i < 10; i++) { | 68 | for (let i = 0; i < 10; i++) { |
79 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | 69 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) |
diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 4fa8caa3a..80d67ae0e 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts | |||
@@ -5,30 +5,31 @@ import * as chai from 'chai' | |||
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | flushAndRunServer, | 7 | flushAndRunServer, |
8 | getPluginsCSS, | ||
9 | installPlugin, | ||
10 | makeHTMLRequest, | 8 | makeHTMLRequest, |
9 | PluginsCommand, | ||
11 | ServerInfo, | 10 | ServerInfo, |
12 | setAccessTokensToServers, | 11 | setAccessTokensToServers |
13 | uninstallPlugin | ||
14 | } from '../../../shared/extra-utils' | 12 | } from '../../../shared/extra-utils' |
15 | 13 | ||
16 | const expect = chai.expect | 14 | const expect = chai.expect |
17 | 15 | ||
18 | describe('Test plugins HTML injection', function () { | 16 | describe('Test plugins HTML injection', function () { |
19 | let server: ServerInfo = null | 17 | let server: ServerInfo = null |
18 | let command: PluginsCommand | ||
20 | 19 | ||
21 | before(async function () { | 20 | before(async function () { |
22 | this.timeout(30000) | 21 | this.timeout(30000) |
23 | 22 | ||
24 | server = await flushAndRunServer(1) | 23 | server = await flushAndRunServer(1) |
25 | await setAccessTokensToServers([ server ]) | 24 | await setAccessTokensToServers([ server ]) |
25 | |||
26 | command = server.pluginsCommand | ||
26 | }) | 27 | }) |
27 | 28 | ||
28 | it('Should not inject global css file in HTML', async function () { | 29 | it('Should not inject global css file in HTML', async function () { |
29 | { | 30 | { |
30 | const res = await getPluginsCSS(server.url) | 31 | const text = await command.getCSS() |
31 | expect(res.text).to.be.empty | 32 | expect(text).to.be.empty |
32 | } | 33 | } |
33 | 34 | ||
34 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { | 35 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { |
@@ -40,17 +41,13 @@ describe('Test plugins HTML injection', function () { | |||
40 | it('Should install a plugin and a theme', async function () { | 41 | it('Should install a plugin and a theme', async function () { |
41 | this.timeout(30000) | 42 | this.timeout(30000) |
42 | 43 | ||
43 | await installPlugin({ | 44 | await command.install({ npmName: 'peertube-plugin-hello-world' }) |
44 | url: server.url, | ||
45 | accessToken: server.accessToken, | ||
46 | npmName: 'peertube-plugin-hello-world' | ||
47 | }) | ||
48 | }) | 45 | }) |
49 | 46 | ||
50 | it('Should have the correct global css', async function () { | 47 | it('Should have the correct global css', async function () { |
51 | { | 48 | { |
52 | const res = await getPluginsCSS(server.url) | 49 | const text = await command.getCSS() |
53 | expect(res.text).to.contain('background-color: red') | 50 | expect(text).to.contain('background-color: red') |
54 | } | 51 | } |
55 | 52 | ||
56 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { | 53 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { |
@@ -60,15 +57,11 @@ describe('Test plugins HTML injection', function () { | |||
60 | }) | 57 | }) |
61 | 58 | ||
62 | it('Should have an empty global css on uninstall', async function () { | 59 | it('Should have an empty global css on uninstall', async function () { |
63 | await uninstallPlugin({ | 60 | await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) |
64 | url: server.url, | ||
65 | accessToken: server.accessToken, | ||
66 | npmName: 'peertube-plugin-hello-world' | ||
67 | }) | ||
68 | 61 | ||
69 | { | 62 | { |
70 | const res = await getPluginsCSS(server.url) | 63 | const text = await command.getCSS() |
71 | expect(res.text).to.be.empty | 64 | expect(text).to.be.empty |
72 | } | 65 | } |
73 | 66 | ||
74 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { | 67 | for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { |
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index cbba638c2..545968040 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts | |||
@@ -1,21 +1,25 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | 4 | import { expect } from 'chai' |
5 | import { | 5 | import { |
6 | cleanupTests, | ||
7 | flushAndRunServer, | ||
8 | getConfig, | ||
6 | getMyUserInformation, | 9 | getMyUserInformation, |
7 | getPluginTestPath, | 10 | getUsersList, |
8 | installPlugin, | 11 | login, |
9 | logout, | 12 | logout, |
13 | PluginsCommand, | ||
14 | refreshToken, | ||
15 | ServerInfo, | ||
10 | setAccessTokensToServers, | 16 | setAccessTokensToServers, |
11 | uninstallPlugin, | ||
12 | updateMyUser, | 17 | updateMyUser, |
13 | userLogin, | 18 | userLogin, |
14 | wait, | 19 | wait, |
15 | login, refreshToken, getConfig, updatePluginSettings, getUsersList | 20 | waitUntilLog |
16 | } from '../../../shared/extra-utils' | 21 | } from '@shared/extra-utils' |
17 | import { User, UserRole, ServerConfig } from '@shared/models' | 22 | import { ServerConfig, User, UserRole } from '@shared/models' |
18 | import { expect } from 'chai' | ||
19 | 23 | ||
20 | describe('Test id and pass auth plugins', function () { | 24 | describe('Test id and pass auth plugins', function () { |
21 | let server: ServerInfo | 25 | let server: ServerInfo |
@@ -33,11 +37,7 @@ describe('Test id and pass auth plugins', function () { | |||
33 | await setAccessTokensToServers([ server ]) | 37 | await setAccessTokensToServers([ server ]) |
34 | 38 | ||
35 | for (const suffix of [ 'one', 'two', 'three' ]) { | 39 | for (const suffix of [ 'one', 'two', 'three' ]) { |
36 | await installPlugin({ | 40 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) }) |
37 | url: server.url, | ||
38 | accessToken: server.accessToken, | ||
39 | path: getPluginTestPath('-id-pass-auth-' + suffix) | ||
40 | }) | ||
41 | } | 41 | } |
42 | }) | 42 | }) |
43 | 43 | ||
@@ -180,9 +180,7 @@ describe('Test id and pass auth plugins', function () { | |||
180 | }) | 180 | }) |
181 | 181 | ||
182 | it('Should unregister spyro-auth and do not login existing Spyro', async function () { | 182 | it('Should unregister spyro-auth and do not login existing Spyro', async function () { |
183 | await updatePluginSettings({ | 183 | await server.pluginsCommand.updateSettings({ |
184 | url: server.url, | ||
185 | accessToken: server.accessToken, | ||
186 | npmName: 'peertube-plugin-test-id-pass-auth-one', | 184 | npmName: 'peertube-plugin-test-id-pass-auth-one', |
187 | settings: { disableSpyro: true } | 185 | settings: { disableSpyro: true } |
188 | }) | 186 | }) |
@@ -204,11 +202,7 @@ describe('Test id and pass auth plugins', function () { | |||
204 | }) | 202 | }) |
205 | 203 | ||
206 | it('Should uninstall the plugin one and do not login existing Crash', async function () { | 204 | it('Should uninstall the plugin one and do not login existing Crash', async function () { |
207 | await uninstallPlugin({ | 205 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) |
208 | url: server.url, | ||
209 | accessToken: server.accessToken, | ||
210 | npmName: 'peertube-plugin-test-id-pass-auth-one' | ||
211 | }) | ||
212 | 206 | ||
213 | await userLogin(server, { username: 'crash', password: 'crash password' }, 400) | 207 | await userLogin(server, { username: 'crash', password: 'crash password' }, 400) |
214 | }) | 208 | }) |
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 0296d6eb7..0e0f61638 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts | |||
@@ -1,23 +1,25 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | ||
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
4 | import { | 6 | import { |
5 | checkVideoFilesWereRemoved, | 7 | checkVideoFilesWereRemoved, |
8 | cleanupTests, | ||
6 | doubleFollow, | 9 | doubleFollow, |
7 | getPluginTestPath, | 10 | flushAndRunMultipleServers, |
8 | getVideo, | 11 | getVideo, |
9 | installPlugin, | 12 | getVideosList, |
13 | makeGetRequest, | ||
10 | makePostBodyRequest, | 14 | makePostBodyRequest, |
15 | PluginsCommand, | ||
16 | ServerInfo, | ||
11 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
12 | uploadVideoAndGetId, | 18 | uploadVideoAndGetId, |
13 | viewVideo, | 19 | viewVideo, |
14 | getVideosList, | ||
15 | waitJobs, | 20 | waitJobs, |
16 | makeGetRequest | 21 | waitUntilLog |
17 | } from '../../../shared/extra-utils' | 22 | } from '@shared/extra-utils' |
18 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | ||
19 | import { expect } from 'chai' | ||
20 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
21 | 23 | ||
22 | function postCommand (server: ServerInfo, command: string, bodyArg?: object) { | 24 | function postCommand (server: ServerInfo, command: string, bodyArg?: object) { |
23 | const body = { command } | 25 | const body = { command } |
@@ -42,11 +44,7 @@ describe('Test plugin helpers', function () { | |||
42 | 44 | ||
43 | await doubleFollow(servers[0], servers[1]) | 45 | await doubleFollow(servers[0], servers[1]) |
44 | 46 | ||
45 | await installPlugin({ | 47 | await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-four') }) |
46 | url: servers[0].url, | ||
47 | accessToken: servers[0].accessToken, | ||
48 | path: getPluginTestPath('-four') | ||
49 | }) | ||
50 | }) | 48 | }) |
51 | 49 | ||
52 | describe('Logger', function () { | 50 | describe('Logger', function () { |
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts index 24e6a1e83..81e18dabd 100644 --- a/server/tests/plugins/plugin-router.ts +++ b/server/tests/plugins/plugin-router.ts | |||
@@ -1,16 +1,17 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
5 | import { | 6 | import { |
6 | getPluginTestPath, | 7 | cleanupTests, |
7 | installPlugin, | 8 | flushAndRunServer, |
8 | makeGetRequest, | 9 | makeGetRequest, |
9 | makePostBodyRequest, | 10 | makePostBodyRequest, |
10 | setAccessTokensToServers, uninstallPlugin | 11 | PluginsCommand, |
11 | } from '../../../shared/extra-utils' | 12 | ServerInfo, |
12 | import { expect } from 'chai' | 13 | setAccessTokensToServers |
13 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 14 | } from '@shared/extra-utils' |
14 | 15 | ||
15 | describe('Test plugin helpers', function () { | 16 | describe('Test plugin helpers', function () { |
16 | let server: ServerInfo | 17 | let server: ServerInfo |
@@ -25,11 +26,7 @@ describe('Test plugin helpers', function () { | |||
25 | server = await flushAndRunServer(1) | 26 | server = await flushAndRunServer(1) |
26 | await setAccessTokensToServers([ server ]) | 27 | await setAccessTokensToServers([ server ]) |
27 | 28 | ||
28 | await installPlugin({ | 29 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-five') }) |
29 | url: server.url, | ||
30 | accessToken: server.accessToken, | ||
31 | path: getPluginTestPath('-five') | ||
32 | }) | ||
33 | }) | 30 | }) |
34 | 31 | ||
35 | it('Should answer "pong"', async function () { | 32 | it('Should answer "pong"', async function () { |
@@ -85,11 +82,7 @@ describe('Test plugin helpers', function () { | |||
85 | }) | 82 | }) |
86 | 83 | ||
87 | it('Should remove the plugin and remove the routes', async function () { | 84 | it('Should remove the plugin and remove the routes', async function () { |
88 | await uninstallPlugin({ | 85 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-five' }) |
89 | url: server.url, | ||
90 | accessToken: server.accessToken, | ||
91 | npmName: 'peertube-plugin-test-five' | ||
92 | }) | ||
93 | 86 | ||
94 | for (const path of basePaths) { | 87 | for (const path of basePaths) { |
95 | await makeGetRequest({ | 88 | await makeGetRequest({ |
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index 3c46b2585..4c65463f2 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts | |||
@@ -7,13 +7,14 @@ import { join } from 'path' | |||
7 | import { HttpStatusCode } from '@shared/core-utils' | 7 | import { HttpStatusCode } from '@shared/core-utils' |
8 | import { | 8 | import { |
9 | buildServerDirectory, | 9 | buildServerDirectory, |
10 | getPluginTestPath, | 10 | cleanupTests, |
11 | installPlugin, | 11 | flushAndRunServer, |
12 | makeGetRequest, | 12 | makeGetRequest, |
13 | PluginsCommand, | ||
14 | ServerInfo, | ||
13 | setAccessTokensToServers, | 15 | setAccessTokensToServers, |
14 | uninstallPlugin | 16 | waitUntilLog |
15 | } from '../../../shared/extra-utils' | 17 | } from '@shared/extra-utils' |
16 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | ||
17 | 18 | ||
18 | describe('Test plugin storage', function () { | 19 | describe('Test plugin storage', function () { |
19 | let server: ServerInfo | 20 | let server: ServerInfo |
@@ -24,11 +25,7 @@ describe('Test plugin storage', function () { | |||
24 | server = await flushAndRunServer(1) | 25 | server = await flushAndRunServer(1) |
25 | await setAccessTokensToServers([ server ]) | 26 | await setAccessTokensToServers([ server ]) |
26 | 27 | ||
27 | await installPlugin({ | 28 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
28 | url: server.url, | ||
29 | accessToken: server.accessToken, | ||
30 | path: getPluginTestPath('-six') | ||
31 | }) | ||
32 | }) | 29 | }) |
33 | 30 | ||
34 | describe('DB storage', function () { | 31 | describe('DB storage', function () { |
@@ -76,22 +73,14 @@ describe('Test plugin storage', function () { | |||
76 | }) | 73 | }) |
77 | 74 | ||
78 | it('Should still have the file after an uninstallation', async function () { | 75 | it('Should still have the file after an uninstallation', async function () { |
79 | await uninstallPlugin({ | 76 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' }) |
80 | url: server.url, | ||
81 | accessToken: server.accessToken, | ||
82 | npmName: 'peertube-plugin-test-six' | ||
83 | }) | ||
84 | 77 | ||
85 | const content = await getFileContent() | 78 | const content = await getFileContent() |
86 | expect(content).to.equal('Prince Ali') | 79 | expect(content).to.equal('Prince Ali') |
87 | }) | 80 | }) |
88 | 81 | ||
89 | it('Should still have the file after the reinstallation', async function () { | 82 | it('Should still have the file after the reinstallation', async function () { |
90 | await installPlugin({ | 83 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') }) |
91 | url: server.url, | ||
92 | accessToken: server.accessToken, | ||
93 | path: getPluginTestPath('-six') | ||
94 | }) | ||
95 | 84 | ||
96 | const content = await getFileContent() | 85 | const content = await getFileContent() |
97 | expect(content).to.equal('Prince Ali') | 86 | expect(content).to.equal('Prince Ali') |
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index eefb2294d..f1ff91077 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts | |||
@@ -4,25 +4,25 @@ import 'mocha' | |||
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' | 6 | import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' |
7 | import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' | ||
8 | import { | 7 | import { |
9 | buildServerDirectory, | 8 | buildServerDirectory, |
9 | cleanupTests, | ||
10 | createLive, | 10 | createLive, |
11 | flushAndRunServer, | ||
11 | getConfig, | 12 | getConfig, |
12 | getPluginTestPath, | ||
13 | getVideo, | 13 | getVideo, |
14 | installPlugin, | 14 | PluginsCommand, |
15 | sendRTMPStreamInVideo, | 15 | sendRTMPStreamInVideo, |
16 | ServerInfo, | ||
16 | setAccessTokensToServers, | 17 | setAccessTokensToServers, |
17 | setDefaultVideoChannel, | 18 | setDefaultVideoChannel, |
18 | testFfmpegStreamError, | 19 | testFfmpegStreamError, |
19 | uninstallPlugin, | ||
20 | updateCustomSubConfig, | 20 | updateCustomSubConfig, |
21 | uploadVideoAndGetId, | 21 | uploadVideoAndGetId, |
22 | waitJobs, | 22 | waitJobs, |
23 | waitUntilLivePublished | 23 | waitUntilLivePublished |
24 | } from '../../../shared/extra-utils' | 24 | } from '@shared/extra-utils' |
25 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 25 | import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' |
26 | 26 | ||
27 | async function createLiveWrapper (server: ServerInfo) { | 27 | async function createLiveWrapper (server: ServerInfo) { |
28 | const liveAttributes = { | 28 | const liveAttributes = { |
@@ -109,11 +109,7 @@ describe('Test transcoding plugins', function () { | |||
109 | } | 109 | } |
110 | 110 | ||
111 | before(async function () { | 111 | before(async function () { |
112 | await installPlugin({ | 112 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') }) |
113 | url: server.url, | ||
114 | accessToken: server.accessToken, | ||
115 | path: getPluginTestPath('-transcoding-one') | ||
116 | }) | ||
117 | }) | 113 | }) |
118 | 114 | ||
119 | it('Should have the appropriate available profiles', async function () { | 115 | it('Should have the appropriate available profiles', async function () { |
@@ -225,7 +221,7 @@ describe('Test transcoding plugins', function () { | |||
225 | it('Should default to the default profile if the specified profile does not exist', async function () { | 221 | it('Should default to the default profile if the specified profile does not exist', async function () { |
226 | this.timeout(240000) | 222 | this.timeout(240000) |
227 | 223 | ||
228 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) | 224 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) |
229 | 225 | ||
230 | const res = await getConfig(server.url) | 226 | const res = await getConfig(server.url) |
231 | const config = res.body as ServerConfig | 227 | const config = res.body as ServerConfig |
@@ -244,11 +240,7 @@ describe('Test transcoding plugins', function () { | |||
244 | describe('When using a plugin adding new encoders', function () { | 240 | describe('When using a plugin adding new encoders', function () { |
245 | 241 | ||
246 | before(async function () { | 242 | before(async function () { |
247 | await installPlugin({ | 243 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') }) |
248 | url: server.url, | ||
249 | accessToken: server.accessToken, | ||
250 | path: getPluginTestPath('-transcoding-two') | ||
251 | }) | ||
252 | 244 | ||
253 | await updateConf(server, 'test-vod-profile', 'test-live-profile') | 245 | await updateConf(server, 'test-vod-profile', 'test-live-profile') |
254 | }) | 246 | }) |
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts index 74ca82e2f..f430f82b8 100644 --- a/server/tests/plugins/plugin-unloading.ts +++ b/server/tests/plugins/plugin-unloading.ts | |||
@@ -1,18 +1,9 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { | ||
5 | cleanupTests, | ||
6 | flushAndRunServer, | ||
7 | getPluginTestPath, | ||
8 | makeGetRequest, | ||
9 | installPlugin, | ||
10 | uninstallPlugin, | ||
11 | ServerInfo, | ||
12 | setAccessTokensToServers | ||
13 | } from '../../../shared/extra-utils' | ||
14 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
15 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
6 | import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' | ||
16 | 7 | ||
17 | describe('Test plugins module unloading', function () { | 8 | describe('Test plugins module unloading', function () { |
18 | let server: ServerInfo = null | 9 | let server: ServerInfo = null |
@@ -25,11 +16,7 @@ describe('Test plugins module unloading', function () { | |||
25 | server = await flushAndRunServer(1) | 16 | server = await flushAndRunServer(1) |
26 | await setAccessTokensToServers([ server ]) | 17 | await setAccessTokensToServers([ server ]) |
27 | 18 | ||
28 | await installPlugin({ | 19 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) |
29 | url: server.url, | ||
30 | accessToken: server.accessToken, | ||
31 | path: getPluginTestPath('-unloading') | ||
32 | }) | ||
33 | }) | 20 | }) |
34 | 21 | ||
35 | it('Should return a numeric value', async function () { | 22 | it('Should return a numeric value', async function () { |
@@ -54,11 +41,7 @@ describe('Test plugins module unloading', function () { | |||
54 | }) | 41 | }) |
55 | 42 | ||
56 | it('Should uninstall the plugin and free the route', async function () { | 43 | it('Should uninstall the plugin and free the route', async function () { |
57 | await uninstallPlugin({ | 44 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-unloading' }) |
58 | url: server.url, | ||
59 | accessToken: server.accessToken, | ||
60 | npmName: 'peertube-plugin-test-unloading' | ||
61 | }) | ||
62 | 45 | ||
63 | await makeGetRequest({ | 46 | await makeGetRequest({ |
64 | url: server.url, | 47 | url: server.url, |
@@ -68,11 +51,8 @@ describe('Test plugins module unloading', function () { | |||
68 | }) | 51 | }) |
69 | 52 | ||
70 | it('Should return a different numeric value', async function () { | 53 | it('Should return a different numeric value', async function () { |
71 | await installPlugin({ | 54 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') }) |
72 | url: server.url, | 55 | |
73 | accessToken: server.accessToken, | ||
74 | path: getPluginTestPath('-unloading') | ||
75 | }) | ||
76 | const res = await makeGetRequest({ | 56 | const res = await makeGetRequest({ |
77 | url: server.url, | 57 | url: server.url, |
78 | path: requestPath, | 58 | path: requestPath, |
diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts index 9fd2ba1c5..0e11a0b53 100644 --- a/server/tests/plugins/translations.ts +++ b/server/tests/plugins/translations.ts | |||
@@ -1,20 +1,15 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { PluginsCommand, setAccessTokensToServers } from '../../../shared/extra-utils' | ||
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 6 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
6 | import { | ||
7 | getPluginTestPath, | ||
8 | getPluginTranslations, | ||
9 | installPlugin, | ||
10 | setAccessTokensToServers, | ||
11 | uninstallPlugin | ||
12 | } from '../../../shared/extra-utils' | ||
13 | 7 | ||
14 | const expect = chai.expect | 8 | const expect = chai.expect |
15 | 9 | ||
16 | describe('Test plugin translations', function () { | 10 | describe('Test plugin translations', function () { |
17 | let server: ServerInfo | 11 | let server: ServerInfo |
12 | let command: PluginsCommand | ||
18 | 13 | ||
19 | before(async function () { | 14 | before(async function () { |
20 | this.timeout(30000) | 15 | this.timeout(30000) |
@@ -22,29 +17,22 @@ describe('Test plugin translations', function () { | |||
22 | server = await flushAndRunServer(1) | 17 | server = await flushAndRunServer(1) |
23 | await setAccessTokensToServers([ server ]) | 18 | await setAccessTokensToServers([ server ]) |
24 | 19 | ||
25 | await installPlugin({ | 20 | command = server.pluginsCommand |
26 | url: server.url, | ||
27 | accessToken: server.accessToken, | ||
28 | path: getPluginTestPath() | ||
29 | }) | ||
30 | 21 | ||
31 | await installPlugin({ | 22 | await command.install({ path: PluginsCommand.getPluginTestPath() }) |
32 | url: server.url, | 23 | await command.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) |
33 | accessToken: server.accessToken, | ||
34 | path: getPluginTestPath('-filter-translations') | ||
35 | }) | ||
36 | }) | 24 | }) |
37 | 25 | ||
38 | it('Should not have translations for locale pt', async function () { | 26 | it('Should not have translations for locale pt', async function () { |
39 | const res = await getPluginTranslations({ url: server.url, locale: 'pt' }) | 27 | const body = await command.getTranslations({ locale: 'pt' }) |
40 | 28 | ||
41 | expect(res.body).to.deep.equal({}) | 29 | expect(body).to.deep.equal({}) |
42 | }) | 30 | }) |
43 | 31 | ||
44 | it('Should have translations for locale fr', async function () { | 32 | it('Should have translations for locale fr', async function () { |
45 | const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) | 33 | const body = await command.getTranslations({ locale: 'fr-FR' }) |
46 | 34 | ||
47 | expect(res.body).to.deep.equal({ | 35 | expect(body).to.deep.equal({ |
48 | 'peertube-plugin-test': { | 36 | 'peertube-plugin-test': { |
49 | Hi: 'Coucou' | 37 | Hi: 'Coucou' |
50 | }, | 38 | }, |
@@ -55,9 +43,9 @@ describe('Test plugin translations', function () { | |||
55 | }) | 43 | }) |
56 | 44 | ||
57 | it('Should have translations of locale it', async function () { | 45 | it('Should have translations of locale it', async function () { |
58 | const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) | 46 | const body = await command.getTranslations({ locale: 'it-IT' }) |
59 | 47 | ||
60 | expect(res.body).to.deep.equal({ | 48 | expect(body).to.deep.equal({ |
61 | 'peertube-plugin-test-filter-translations': { | 49 | 'peertube-plugin-test-filter-translations': { |
62 | 'Hello world': 'Ciao, mondo!' | 50 | 'Hello world': 'Ciao, mondo!' |
63 | } | 51 | } |
@@ -65,12 +53,12 @@ describe('Test plugin translations', function () { | |||
65 | }) | 53 | }) |
66 | 54 | ||
67 | it('Should remove the plugin and remove the locales', async function () { | 55 | it('Should remove the plugin and remove the locales', async function () { |
68 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-filter-translations' }) | 56 | await command.uninstall({ npmName: 'peertube-plugin-test-filter-translations' }) |
69 | 57 | ||
70 | { | 58 | { |
71 | const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) | 59 | const body = await command.getTranslations({ locale: 'fr-FR' }) |
72 | 60 | ||
73 | expect(res.body).to.deep.equal({ | 61 | expect(body).to.deep.equal({ |
74 | 'peertube-plugin-test': { | 62 | 'peertube-plugin-test': { |
75 | Hi: 'Coucou' | 63 | Hi: 'Coucou' |
76 | } | 64 | } |
@@ -78,9 +66,9 @@ describe('Test plugin translations', function () { | |||
78 | } | 66 | } |
79 | 67 | ||
80 | { | 68 | { |
81 | const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) | 69 | const body = await command.getTranslations({ locale: 'it-IT' }) |
82 | 70 | ||
83 | expect(res.body).to.deep.equal({}) | 71 | expect(body).to.deep.equal({}) |
84 | } | 72 | } |
85 | }) | 73 | }) |
86 | 74 | ||
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index eb014c596..4124e8a52 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts | |||
@@ -1,22 +1,24 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
6 | import { | 6 | import { |
7 | cleanupTests, | ||
7 | createVideoPlaylist, | 8 | createVideoPlaylist, |
8 | getPluginTestPath, | 9 | flushAndRunServer, |
9 | getVideo, | 10 | getVideo, |
10 | getVideoCategories, | 11 | getVideoCategories, |
11 | getVideoLanguages, | 12 | getVideoLanguages, |
12 | getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, | 13 | getVideoLicences, |
13 | installPlugin, | 14 | getVideoPlaylistPrivacies, |
15 | getVideoPrivacies, | ||
16 | PluginsCommand, | ||
17 | ServerInfo, | ||
14 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
15 | uninstallPlugin, | ||
16 | uploadVideo | 19 | uploadVideo |
17 | } from '../../../shared/extra-utils' | 20 | } from '@shared/extra-utils' |
18 | import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' | 21 | import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models' |
19 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
20 | 22 | ||
21 | const expect = chai.expect | 23 | const expect = chai.expect |
22 | 24 | ||
@@ -29,11 +31,7 @@ describe('Test plugin altering video constants', function () { | |||
29 | server = await flushAndRunServer(1) | 31 | server = await flushAndRunServer(1) |
30 | await setAccessTokensToServers([ server ]) | 32 | await setAccessTokensToServers([ server ]) |
31 | 33 | ||
32 | await installPlugin({ | 34 | await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) |
33 | url: server.url, | ||
34 | accessToken: server.accessToken, | ||
35 | path: getPluginTestPath('-video-constants') | ||
36 | }) | ||
37 | }) | 35 | }) |
38 | 36 | ||
39 | it('Should have updated languages', async function () { | 37 | it('Should have updated languages', async function () { |
@@ -117,7 +115,7 @@ describe('Test plugin altering video constants', function () { | |||
117 | }) | 115 | }) |
118 | 116 | ||
119 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { | 117 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { |
120 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) | 118 | await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) |
121 | 119 | ||
122 | { | 120 | { |
123 | const res = await getVideoLanguages(server.url) | 121 | const res = await getVideoLanguages(server.url) |
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 652779eea..cf6418249 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -15,7 +15,6 @@ export * from './requests/requests' | |||
15 | 15 | ||
16 | export * from './server/clients' | 16 | export * from './server/clients' |
17 | export * from './server/config' | 17 | export * from './server/config' |
18 | export * from './server/plugins' | ||
19 | export * from './server/servers' | 18 | export * from './server/servers' |
20 | 19 | ||
21 | export * from './users/accounts' | 20 | export * from './users/accounts' |
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index b5b6b2116..e602fec7e 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -4,3 +4,5 @@ export * from './follows-command' | |||
4 | export * from './follows' | 4 | export * from './follows' |
5 | export * from './jobs' | 5 | export * from './jobs' |
6 | export * from './jobs-command' | 6 | export * from './jobs-command' |
7 | export * from './plugins-command' | ||
8 | export * from './plugins' | ||
diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.ts new file mode 100644 index 000000000..f06e58a22 --- /dev/null +++ b/shared/extra-utils/server/plugins-command.ts | |||
@@ -0,0 +1,245 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { readJSON, writeJSON } from 'fs-extra' | ||
4 | import { join } from 'path' | ||
5 | import { root } from '@server/helpers/core-utils' | ||
6 | import { HttpStatusCode } from '@shared/core-utils' | ||
7 | import { | ||
8 | PeerTubePlugin, | ||
9 | PeerTubePluginIndex, | ||
10 | PeertubePluginIndexList, | ||
11 | PluginPackageJson, | ||
12 | PluginTranslation, | ||
13 | PluginType, | ||
14 | PublicServerSetting, | ||
15 | RegisteredServerSettings, | ||
16 | ResultList | ||
17 | } from '@shared/models' | ||
18 | import { buildServerDirectory } from '../miscs' | ||
19 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
20 | |||
21 | export class PluginsCommand extends AbstractCommand { | ||
22 | |||
23 | static getPluginTestPath (suffix = '') { | ||
24 | return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) | ||
25 | } | ||
26 | |||
27 | list (options: OverrideCommandOptions & { | ||
28 | start?: number | ||
29 | count?: number | ||
30 | sort?: string | ||
31 | pluginType?: PluginType | ||
32 | uninstalled?: boolean | ||
33 | }) { | ||
34 | const { start, count, sort, pluginType, uninstalled } = options | ||
35 | const path = '/api/v1/plugins' | ||
36 | |||
37 | return this.getRequestBody<ResultList<PeerTubePlugin>>({ | ||
38 | ...options, | ||
39 | |||
40 | path, | ||
41 | query: { | ||
42 | start, | ||
43 | count, | ||
44 | sort, | ||
45 | pluginType, | ||
46 | uninstalled | ||
47 | }, | ||
48 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
49 | }) | ||
50 | } | ||
51 | |||
52 | listAvailable (options: OverrideCommandOptions & { | ||
53 | start?: number | ||
54 | count?: number | ||
55 | sort?: string | ||
56 | pluginType?: PluginType | ||
57 | currentPeerTubeEngine?: string | ||
58 | search?: string | ||
59 | expectedStatus?: HttpStatusCode | ||
60 | }) { | ||
61 | const { start, count, sort, pluginType, search, currentPeerTubeEngine } = options | ||
62 | const path = '/api/v1/plugins/available' | ||
63 | |||
64 | const query: PeertubePluginIndexList = { | ||
65 | start, | ||
66 | count, | ||
67 | sort, | ||
68 | pluginType, | ||
69 | currentPeerTubeEngine, | ||
70 | search | ||
71 | } | ||
72 | |||
73 | return this.getRequestBody<ResultList<PeerTubePluginIndex>>({ | ||
74 | ...options, | ||
75 | |||
76 | path, | ||
77 | query, | ||
78 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
79 | }) | ||
80 | } | ||
81 | |||
82 | get (options: OverrideCommandOptions & { | ||
83 | npmName: string | ||
84 | }) { | ||
85 | const path = '/api/v1/plugins/' + options.npmName | ||
86 | |||
87 | return this.getRequestBody<PeerTubePlugin>({ | ||
88 | ...options, | ||
89 | |||
90 | path, | ||
91 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
92 | }) | ||
93 | } | ||
94 | |||
95 | updateSettings (options: OverrideCommandOptions & { | ||
96 | npmName: string | ||
97 | settings: any | ||
98 | }) { | ||
99 | const { npmName, settings } = options | ||
100 | const path = '/api/v1/plugins/' + npmName + '/settings' | ||
101 | |||
102 | return this.putBodyRequest({ | ||
103 | ...options, | ||
104 | |||
105 | path, | ||
106 | fields: { settings }, | ||
107 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
108 | }) | ||
109 | } | ||
110 | |||
111 | getRegisteredSettings (options: OverrideCommandOptions & { | ||
112 | npmName: string | ||
113 | }) { | ||
114 | const path = '/api/v1/plugins/' + options.npmName + '/registered-settings' | ||
115 | |||
116 | return this.getRequestBody<RegisteredServerSettings>({ | ||
117 | ...options, | ||
118 | |||
119 | path, | ||
120 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
121 | }) | ||
122 | } | ||
123 | |||
124 | getPublicSettings (options: OverrideCommandOptions & { | ||
125 | npmName: string | ||
126 | }) { | ||
127 | const { npmName } = options | ||
128 | const path = '/api/v1/plugins/' + npmName + '/public-settings' | ||
129 | |||
130 | return this.getRequestBody<PublicServerSetting>({ | ||
131 | ...options, | ||
132 | |||
133 | path, | ||
134 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
135 | }) | ||
136 | } | ||
137 | |||
138 | getTranslations (options: OverrideCommandOptions & { | ||
139 | locale: string | ||
140 | }) { | ||
141 | const { locale } = options | ||
142 | const path = '/plugins/translations/' + locale + '.json' | ||
143 | |||
144 | return this.getRequestBody<PluginTranslation>({ | ||
145 | ...options, | ||
146 | |||
147 | path, | ||
148 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
149 | }) | ||
150 | } | ||
151 | |||
152 | install (options: OverrideCommandOptions & { | ||
153 | path?: string | ||
154 | npmName?: string | ||
155 | }) { | ||
156 | const { npmName, path } = options | ||
157 | const apiPath = '/api/v1/plugins/install' | ||
158 | |||
159 | return this.postBodyRequest({ | ||
160 | ...options, | ||
161 | |||
162 | path: apiPath, | ||
163 | fields: { npmName, path }, | ||
164 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
165 | }) | ||
166 | } | ||
167 | |||
168 | update (options: OverrideCommandOptions & { | ||
169 | path?: string | ||
170 | npmName?: string | ||
171 | }) { | ||
172 | const { npmName, path } = options | ||
173 | const apiPath = '/api/v1/plugins/update' | ||
174 | |||
175 | return this.postBodyRequest({ | ||
176 | ...options, | ||
177 | |||
178 | path: apiPath, | ||
179 | fields: { npmName, path }, | ||
180 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
181 | }) | ||
182 | } | ||
183 | |||
184 | uninstall (options: OverrideCommandOptions & { | ||
185 | npmName: string | ||
186 | }) { | ||
187 | const { npmName } = options | ||
188 | const apiPath = '/api/v1/plugins/uninstall' | ||
189 | |||
190 | return this.postBodyRequest({ | ||
191 | ...options, | ||
192 | |||
193 | path: apiPath, | ||
194 | fields: { npmName }, | ||
195 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
196 | }) | ||
197 | } | ||
198 | |||
199 | getCSS (options: OverrideCommandOptions = {}) { | ||
200 | const path = '/plugins/global.css' | ||
201 | |||
202 | return this.getRequestText({ | ||
203 | ...options, | ||
204 | |||
205 | path, | ||
206 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
207 | }) | ||
208 | } | ||
209 | |||
210 | getExternalAuth (options: OverrideCommandOptions & { | ||
211 | npmName: string | ||
212 | npmVersion: string | ||
213 | authName: string | ||
214 | query?: any | ||
215 | }) { | ||
216 | const { npmName, npmVersion, authName, query } = options | ||
217 | |||
218 | const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName | ||
219 | |||
220 | return this.getRequest({ | ||
221 | ...options, | ||
222 | |||
223 | path, | ||
224 | query, | ||
225 | defaultExpectedStatus: HttpStatusCode.OK_200, | ||
226 | redirects: 0 | ||
227 | }) | ||
228 | } | ||
229 | |||
230 | updatePackageJSON (npmName: string, json: any) { | ||
231 | const path = this.getPackageJSONPath(npmName) | ||
232 | |||
233 | return writeJSON(path, json) | ||
234 | } | ||
235 | |||
236 | getPackageJSON (npmName: string): Promise<PluginPackageJson> { | ||
237 | const path = this.getPackageJSONPath(npmName) | ||
238 | |||
239 | return readJSON(path) | ||
240 | } | ||
241 | |||
242 | private getPackageJSONPath (npmName: string) { | ||
243 | return buildServerDirectory(this.server, join('plugins', 'node_modules', npmName, 'package.json')) | ||
244 | } | ||
245 | } | ||
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts index d53e5b382..1084ea4f4 100644 --- a/shared/extra-utils/server/plugins.ts +++ b/shared/extra-utils/server/plugins.ts | |||
@@ -1,307 +1,18 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { readJSON, writeJSON } from 'fs-extra' | 4 | import { ServerInfo } from '../server/servers' |
5 | import { join } from 'path' | ||
6 | import { RegisteredServerSettings } from '@shared/models' | ||
7 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { PeertubePluginIndexList } from '../../models/plugins/plugin-index/peertube-plugin-index-list.model' | ||
9 | import { PluginType } from '../../models/plugins/plugin.type' | ||
10 | import { buildServerDirectory, root } from '../miscs/miscs' | ||
11 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
12 | import { ServerInfo } from './servers' | ||
13 | |||
14 | function listPlugins (parameters: { | ||
15 | url: string | ||
16 | accessToken: string | ||
17 | start?: number | ||
18 | count?: number | ||
19 | sort?: string | ||
20 | pluginType?: PluginType | ||
21 | uninstalled?: boolean | ||
22 | expectedStatus?: HttpStatusCode | ||
23 | }) { | ||
24 | const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
25 | const path = '/api/v1/plugins' | ||
26 | |||
27 | return makeGetRequest({ | ||
28 | url, | ||
29 | path, | ||
30 | token: accessToken, | ||
31 | query: { | ||
32 | start, | ||
33 | count, | ||
34 | sort, | ||
35 | pluginType, | ||
36 | uninstalled | ||
37 | }, | ||
38 | statusCodeExpected: expectedStatus | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | function listAvailablePlugins (parameters: { | ||
43 | url: string | ||
44 | accessToken: string | ||
45 | start?: number | ||
46 | count?: number | ||
47 | sort?: string | ||
48 | pluginType?: PluginType | ||
49 | currentPeerTubeEngine?: string | ||
50 | search?: string | ||
51 | expectedStatus?: HttpStatusCode | ||
52 | }) { | ||
53 | const { | ||
54 | url, | ||
55 | accessToken, | ||
56 | start, | ||
57 | count, | ||
58 | sort, | ||
59 | pluginType, | ||
60 | search, | ||
61 | currentPeerTubeEngine, | ||
62 | expectedStatus = HttpStatusCode.OK_200 | ||
63 | } = parameters | ||
64 | const path = '/api/v1/plugins/available' | ||
65 | |||
66 | const query: PeertubePluginIndexList = { | ||
67 | start, | ||
68 | count, | ||
69 | sort, | ||
70 | pluginType, | ||
71 | currentPeerTubeEngine, | ||
72 | search | ||
73 | } | ||
74 | |||
75 | return makeGetRequest({ | ||
76 | url, | ||
77 | path, | ||
78 | token: accessToken, | ||
79 | query, | ||
80 | statusCodeExpected: expectedStatus | ||
81 | }) | ||
82 | } | ||
83 | |||
84 | function getPlugin (parameters: { | ||
85 | url: string | ||
86 | accessToken: string | ||
87 | npmName: string | ||
88 | expectedStatus?: HttpStatusCode | ||
89 | }) { | ||
90 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
91 | const path = '/api/v1/plugins/' + npmName | ||
92 | |||
93 | return makeGetRequest({ | ||
94 | url, | ||
95 | path, | ||
96 | token: accessToken, | ||
97 | statusCodeExpected: expectedStatus | ||
98 | }) | ||
99 | } | ||
100 | |||
101 | function updatePluginSettings (parameters: { | ||
102 | url: string | ||
103 | accessToken: string | ||
104 | npmName: string | ||
105 | settings: any | ||
106 | expectedStatus?: HttpStatusCode | ||
107 | }) { | ||
108 | const { url, accessToken, npmName, settings, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters | ||
109 | const path = '/api/v1/plugins/' + npmName + '/settings' | ||
110 | |||
111 | return makePutBodyRequest({ | ||
112 | url, | ||
113 | path, | ||
114 | token: accessToken, | ||
115 | fields: { settings }, | ||
116 | statusCodeExpected: expectedStatus | ||
117 | }) | ||
118 | } | ||
119 | |||
120 | function getPluginRegisteredSettings (parameters: { | ||
121 | url: string | ||
122 | accessToken: string | ||
123 | npmName: string | ||
124 | expectedStatus?: HttpStatusCode | ||
125 | }) { | ||
126 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
127 | const path = '/api/v1/plugins/' + npmName + '/registered-settings' | ||
128 | |||
129 | return makeGetRequest({ | ||
130 | url, | ||
131 | path, | ||
132 | token: accessToken, | ||
133 | statusCodeExpected: expectedStatus | ||
134 | }) | ||
135 | } | ||
136 | 5 | ||
137 | async function testHelloWorldRegisteredSettings (server: ServerInfo) { | 6 | async function testHelloWorldRegisteredSettings (server: ServerInfo) { |
138 | const res = await getPluginRegisteredSettings({ | 7 | const body = await server.pluginsCommand.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) |
139 | url: server.url, | ||
140 | accessToken: server.accessToken, | ||
141 | npmName: 'peertube-plugin-hello-world' | ||
142 | }) | ||
143 | |||
144 | const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings | ||
145 | 8 | ||
9 | const registeredSettings = body.registeredSettings | ||
146 | expect(registeredSettings).to.have.length.at.least(1) | 10 | expect(registeredSettings).to.have.length.at.least(1) |
147 | 11 | ||
148 | const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') | 12 | const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') |
149 | expect(adminNameSettings).to.not.be.undefined | 13 | expect(adminNameSettings).to.not.be.undefined |
150 | } | 14 | } |
151 | 15 | ||
152 | function getPublicSettings (parameters: { | ||
153 | url: string | ||
154 | npmName: string | ||
155 | expectedStatus?: HttpStatusCode | ||
156 | }) { | ||
157 | const { url, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
158 | const path = '/api/v1/plugins/' + npmName + '/public-settings' | ||
159 | |||
160 | return makeGetRequest({ | ||
161 | url, | ||
162 | path, | ||
163 | statusCodeExpected: expectedStatus | ||
164 | }) | ||
165 | } | ||
166 | |||
167 | function getPluginTranslations (parameters: { | ||
168 | url: string | ||
169 | locale: string | ||
170 | expectedStatus?: HttpStatusCode | ||
171 | }) { | ||
172 | const { url, locale, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
173 | const path = '/plugins/translations/' + locale + '.json' | ||
174 | |||
175 | return makeGetRequest({ | ||
176 | url, | ||
177 | path, | ||
178 | statusCodeExpected: expectedStatus | ||
179 | }) | ||
180 | } | ||
181 | |||
182 | function installPlugin (parameters: { | ||
183 | url: string | ||
184 | accessToken: string | ||
185 | path?: string | ||
186 | npmName?: string | ||
187 | expectedStatus?: HttpStatusCode | ||
188 | }) { | ||
189 | const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
190 | const apiPath = '/api/v1/plugins/install' | ||
191 | |||
192 | return makePostBodyRequest({ | ||
193 | url, | ||
194 | path: apiPath, | ||
195 | token: accessToken, | ||
196 | fields: { npmName, path }, | ||
197 | statusCodeExpected: expectedStatus | ||
198 | }) | ||
199 | } | ||
200 | |||
201 | function updatePlugin (parameters: { | ||
202 | url: string | ||
203 | accessToken: string | ||
204 | path?: string | ||
205 | npmName?: string | ||
206 | expectedStatus?: HttpStatusCode | ||
207 | }) { | ||
208 | const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters | ||
209 | const apiPath = '/api/v1/plugins/update' | ||
210 | |||
211 | return makePostBodyRequest({ | ||
212 | url, | ||
213 | path: apiPath, | ||
214 | token: accessToken, | ||
215 | fields: { npmName, path }, | ||
216 | statusCodeExpected: expectedStatus | ||
217 | }) | ||
218 | } | ||
219 | |||
220 | function uninstallPlugin (parameters: { | ||
221 | url: string | ||
222 | accessToken: string | ||
223 | npmName: string | ||
224 | expectedStatus?: HttpStatusCode | ||
225 | }) { | ||
226 | const { url, accessToken, npmName, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters | ||
227 | const apiPath = '/api/v1/plugins/uninstall' | ||
228 | |||
229 | return makePostBodyRequest({ | ||
230 | url, | ||
231 | path: apiPath, | ||
232 | token: accessToken, | ||
233 | fields: { npmName }, | ||
234 | statusCodeExpected: expectedStatus | ||
235 | }) | ||
236 | } | ||
237 | |||
238 | function getPluginsCSS (url: string) { | ||
239 | const path = '/plugins/global.css' | ||
240 | |||
241 | return makeGetRequest({ | ||
242 | url, | ||
243 | path, | ||
244 | statusCodeExpected: HttpStatusCode.OK_200 | ||
245 | }) | ||
246 | } | ||
247 | |||
248 | function getPackageJSONPath (server: ServerInfo, npmName: string) { | ||
249 | return buildServerDirectory(server, join('plugins', 'node_modules', npmName, 'package.json')) | ||
250 | } | ||
251 | |||
252 | function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) { | ||
253 | const path = getPackageJSONPath(server, npmName) | ||
254 | |||
255 | return writeJSON(path, json) | ||
256 | } | ||
257 | |||
258 | function getPluginPackageJSON (server: ServerInfo, npmName: string) { | ||
259 | const path = getPackageJSONPath(server, npmName) | ||
260 | |||
261 | return readJSON(path) | ||
262 | } | ||
263 | |||
264 | function getPluginTestPath (suffix = '') { | ||
265 | return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix) | ||
266 | } | ||
267 | |||
268 | function getExternalAuth (options: { | ||
269 | url: string | ||
270 | npmName: string | ||
271 | npmVersion: string | ||
272 | authName: string | ||
273 | query?: any | ||
274 | statusCodeExpected?: HttpStatusCode | ||
275 | }) { | ||
276 | const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options | ||
277 | |||
278 | const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName | ||
279 | |||
280 | return makeGetRequest({ | ||
281 | url, | ||
282 | path, | ||
283 | query, | ||
284 | statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200, | ||
285 | redirects: 0 | ||
286 | }) | ||
287 | } | ||
288 | |||
289 | export { | 16 | export { |
290 | listPlugins, | 17 | testHelloWorldRegisteredSettings |
291 | listAvailablePlugins, | ||
292 | installPlugin, | ||
293 | getPluginTranslations, | ||
294 | getPluginsCSS, | ||
295 | updatePlugin, | ||
296 | getPlugin, | ||
297 | uninstallPlugin, | ||
298 | testHelloWorldRegisteredSettings, | ||
299 | updatePluginSettings, | ||
300 | getPluginRegisteredSettings, | ||
301 | getPackageJSONPath, | ||
302 | updatePluginPackageJSON, | ||
303 | getPluginPackageJSON, | ||
304 | getPluginTestPath, | ||
305 | getPublicSettings, | ||
306 | getExternalAuth | ||
307 | } | 18 | } |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 5511ce0b0..79d6b7b1a 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -20,6 +20,7 @@ import { ContactFormCommand } from './contact-form-command' | |||
20 | import { DebugCommand } from './debug-command' | 20 | import { DebugCommand } from './debug-command' |
21 | import { FollowsCommand } from './follows-command' | 21 | import { FollowsCommand } from './follows-command' |
22 | import { JobsCommand } from './jobs-command' | 22 | import { JobsCommand } from './jobs-command' |
23 | import { PluginsCommand } from './plugins-command' | ||
23 | 24 | ||
24 | interface ServerInfo { | 25 | interface ServerInfo { |
25 | app: ChildProcess | 26 | app: ChildProcess |
@@ -85,6 +86,7 @@ interface ServerInfo { | |||
85 | debugCommand?: DebugCommand | 86 | debugCommand?: DebugCommand |
86 | followsCommand?: FollowsCommand | 87 | followsCommand?: FollowsCommand |
87 | jobsCommand?: JobsCommand | 88 | jobsCommand?: JobsCommand |
89 | pluginsCommand?: PluginsCommand | ||
88 | } | 90 | } |
89 | 91 | ||
90 | function parallelTests () { | 92 | function parallelTests () { |
@@ -302,6 +304,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
302 | server.debugCommand = new DebugCommand(server) | 304 | server.debugCommand = new DebugCommand(server) |
303 | server.followsCommand = new FollowsCommand(server) | 305 | server.followsCommand = new FollowsCommand(server) |
304 | server.jobsCommand = new JobsCommand(server) | 306 | server.jobsCommand = new JobsCommand(server) |
307 | server.pluginsCommand = new PluginsCommand(server) | ||
305 | 308 | ||
306 | res(server) | 309 | res(server) |
307 | }) | 310 | }) |
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 3815fab0e..dd4598a91 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts | |||
@@ -16,6 +16,7 @@ interface GetCommandOptions extends CommonCommandOptions { | |||
16 | query?: { [ id: string ]: any } | 16 | query?: { [ id: string ]: any } |
17 | contentType?: string | 17 | contentType?: string |
18 | accept?: string | 18 | accept?: string |
19 | redirects?: number | ||
19 | } | 20 | } |
20 | 21 | ||
21 | abstract class AbstractCommand { | 22 | abstract class AbstractCommand { |
@@ -44,6 +45,19 @@ abstract class AbstractCommand { | |||
44 | return unwrapText(this.getRequest(options)) | 45 | return unwrapText(this.getRequest(options)) |
45 | } | 46 | } |
46 | 47 | ||
48 | protected getRequest (options: GetCommandOptions) { | ||
49 | const { redirects, query, contentType, accept } = options | ||
50 | |||
51 | return makeGetRequest({ | ||
52 | ...this.buildCommonRequestOptions(options), | ||
53 | |||
54 | redirects, | ||
55 | query, | ||
56 | contentType, | ||
57 | accept | ||
58 | }) | ||
59 | } | ||
60 | |||
47 | protected deleteRequest (options: CommonCommandOptions) { | 61 | protected deleteRequest (options: CommonCommandOptions) { |
48 | return makeDeleteRequest(this.buildCommonRequestOptions(options)) | 62 | return makeDeleteRequest(this.buildCommonRequestOptions(options)) |
49 | } | 63 | } |
@@ -85,18 +99,6 @@ abstract class AbstractCommand { | |||
85 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus | 99 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus |
86 | } | 100 | } |
87 | } | 101 | } |
88 | |||
89 | private getRequest (options: GetCommandOptions) { | ||
90 | const { query, contentType, accept } = options | ||
91 | |||
92 | return makeGetRequest({ | ||
93 | ...this.buildCommonRequestOptions(options), | ||
94 | |||
95 | query, | ||
96 | contentType, | ||
97 | accept | ||
98 | }) | ||
99 | } | ||
100 | } | 102 | } |
101 | 103 | ||
102 | export { | 104 | export { |