aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-30 11:45:06 +0200
committerChocobozzz <me@florianbigard.com>2021-06-30 11:45:20 +0200
commit9c2e051c56e1ef6b9c9901f492fb506ee5d16def (patch)
treeba9d731b0e3d89e2a3004c047c59c0c4e4e7bac0
parent4c0a6954fb6df177f842de4bf3e3a97eb171a11b (diff)
downloadPeerTube-9c2e051c56e1ef6b9c9901f492fb506ee5d16def.tar.gz
PeerTube-9c2e051c56e1ef6b9c9901f492fb506ee5d16def.tar.zst
PeerTube-9c2e051c56e1ef6b9c9901f492fb506ee5d16def.zip
Handle broken plugin install
-rw-r--r--server/lib/plugins/plugin-manager.ts27
-rw-r--r--server/tests/api/server/plugins.ts32
-rw-r--r--server/tests/fixtures/peertube-plugin-test-broken/main.js12
-rw-r--r--server/tests/fixtures/peertube-plugin-test-broken/package.json20
4 files changed, 80 insertions, 11 deletions
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts
index 6b9a255a4..6599bccca 100644
--- a/server/lib/plugins/plugin-manager.ts
+++ b/server/lib/plugins/plugin-manager.ts
@@ -304,22 +304,28 @@ export class PluginManager implements ServerHook {
304 uninstalled: false, 304 uninstalled: false,
305 peertubeEngine: packageJSON.engine.peertube 305 peertubeEngine: packageJSON.engine.peertube
306 }, { returning: true }) 306 }, { returning: true })
307 } catch (err) { 307
308 logger.error('Cannot install plugin %s, removing it...', toInstall, { err }) 308 logger.info('Successful installation of plugin %s.', toInstall)
309
310 await this.registerPluginOrTheme(plugin)
311 } catch (rootErr) {
312 logger.error('Cannot install plugin %s, removing it...', toInstall, { err: rootErr })
309 313
310 try { 314 try {
311 await removeNpmPlugin(npmName) 315 await this.uninstall(npmName)
312 } catch (err) { 316 } catch (err) {
313 logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err }) 317 logger.error('Cannot uninstall plugin %s after failed installation.', toInstall, { err })
318
319 try {
320 await removeNpmPlugin(npmName)
321 } catch (err) {
322 logger.error('Cannot remove plugin %s after failed installation.', toInstall, { err })
323 }
314 } 324 }
315 325
316 throw err 326 throw rootErr
317 } 327 }
318 328
319 logger.info('Successful installation of plugin %s.', toInstall)
320
321 await this.registerPluginOrTheme(plugin)
322
323 return plugin 329 return plugin
324 } 330 }
325 331
@@ -425,8 +431,7 @@ export class PluginManager implements ServerHook {
425 431
426 await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath()) 432 await ensureDir(registerOptions.peertubeHelpers.plugin.getDataDirectoryPath())
427 433
428 library.register(registerOptions) 434 await library.register(registerOptions)
429 .catch(err => logger.error('Cannot register plugin %s.', npmName, { err }))
430 435
431 logger.info('Add plugin %s CSS to global file.', npmName) 436 logger.info('Add plugin %s CSS to global file.', npmName)
432 437
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 6046ab97e..6b61c7c33 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 closeAllSequelize, 8 closeAllSequelize,
@@ -10,6 +11,7 @@ import {
10 getMyUserInformation, 11 getMyUserInformation,
11 getPlugin, 12 getPlugin,
12 getPluginPackageJSON, 13 getPluginPackageJSON,
14 getPluginTestPath,
13 getPublicSettings, 15 getPublicSettings,
14 installPlugin, 16 installPlugin,
15 killallServers, 17 killallServers,
@@ -400,6 +402,36 @@ describe('Test plugins', function () {
400 expect((res.body as User).theme).to.equal('instance-default') 402 expect((res.body as User).theme).to.equal('instance-default')
401 }) 403 })
402 404
405 it('Should not install a broken plugin', async function () {
406 this.timeout(60000)
407
408 async function check () {
409 const res = await listPlugins({
410 url: server.url,
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
418 }
419
420 await installPlugin({
421 url: server.url,
422 accessToken: server.accessToken,
423 path: getPluginTestPath('-broken'),
424 expectedStatus: HttpStatusCode.BAD_REQUEST_400
425 })
426
427 await check()
428
429 killallServers([ server ])
430 await reRunServer(server)
431
432 await check()
433 })
434
403 after(async function () { 435 after(async function () {
404 await closeAllSequelize([ server ]) 436 await closeAllSequelize([ server ])
405 await cleanupTests([ server ]) 437 await cleanupTests([ server ])
diff --git a/server/tests/fixtures/peertube-plugin-test-broken/main.js b/server/tests/fixtures/peertube-plugin-test-broken/main.js
new file mode 100644
index 000000000..afdb6f7a0
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-broken/main.js
@@ -0,0 +1,12 @@
1async function register (options) {
2 options.unknownFunction()
3}
4
5async function unregister () {
6 return
7}
8
9module.exports = {
10 register,
11 unregister
12}
diff --git a/server/tests/fixtures/peertube-plugin-test-broken/package.json b/server/tests/fixtures/peertube-plugin-test-broken/package.json
new file mode 100644
index 000000000..fd03df216
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-broken/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-broken",
3 "version": "0.0.1",
4 "description": "Plugin test broken",
5 "engine": {
6 "peertube": ">=1.3.0"
7 },
8 "keywords": [
9 "peertube",
10 "plugin"
11 ],
12 "homepage": "https://github.com/Chocobozzz/PeerTube",
13 "author": "Chocobozzz",
14 "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
15 "library": "./main.js",
16 "staticDirs": {},
17 "css": [],
18 "clientScripts": [],
19 "translations": {}
20}