ActivityPub-federated video streaming platform using P2P directly in your web browser
Introduce plugins command
Chocobozzzae2abfd3aed3
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.tsindex a833fe6ffe..d372221d05 100644--- a/server/tests/api/check-params/plugins.ts+++ b/server/tests/api/check-params/plugins.ts@@ -10,7 +10,6 @@ import {createUser,flushAndRunServer,immutableAssign,- installPlugin,makeGetRequest,makePostBodyRequest,makePutBodyRequest,@@ -50,13 +49,13 @@ describe('Test server plugins API validators', function () {userAccessToken = await userLogin(server, user){- const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin })+ const res = await server.pluginsCommand.install({ npmName: npmPlugin })const plugin = res.body as PeerTubePluginnpmVersion = plugin.version}{- const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin })+ const res = await server.pluginsCommand.install({ npmName: themePlugin })const plugin = res.body as PeerTubePluginthemeVersion = plugin.version}diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.tsindex 91681c9d6a..da9767b740 100644--- a/server/tests/api/notifications/admin-notifications.ts+++ b/server/tests/api/notifications/admin-notifications.ts@@ -2,18 +2,20 @@import 'mocha'import { expect } from 'chai'-import { MockJoinPeerTubeVersions } from '@shared/extra-utils'-import { PluginType } from '@shared/models'-import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'-import { ServerInfo } from '../../../../shared/extra-utils/index'-import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'import {CheckerBaseParams,checkNewPeerTubeVersion,checkNewPluginVersion,- prepareNotificationsTest-} from '../../../../shared/extra-utils/users/user-notifications'-import { UserNotification, UserNotificationType } from '../../../../shared/models/users'+ cleanupTests,+ MockJoinPeerTubeVersions,+ MockSmtpServer,+ prepareNotificationsTest,+ ServerInfo,+ setPluginLatestVersion,+ setPluginVersion,+ wait+} from '@shared/extra-utils'+import { PluginType, UserNotification, UserNotificationType } from '@shared/models'describe('Test admin notifications', function () {let server: ServerInfo@@ -58,17 +60,8 @@ describe('Test admin notifications', function () {token: server.accessToken}- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-theme-background-red'- })+ await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' })+ await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })})describe('Latest PeerTube version notification', function () {diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.tsindex 6b61c7c337..1536997d5f 100644--- a/server/tests/api/server/plugins.ts+++ b/server/tests/api/server/plugins.ts@@ -9,34 +9,25 @@ import {flushAndRunServer,getConfig,getMyUserInformation,- getPlugin,- getPluginPackageJSON,- getPluginTestPath,- getPublicSettings,- installPlugin,killallServers,- listAvailablePlugins,- listPlugins,+ PluginsCommand,reRunServer,ServerInfo,setAccessTokensToServers,setPluginVersion,testHelloWorldRegisteredSettings,- uninstallPlugin,updateCustomSubConfig,updateMyUser,- updatePlugin,- updatePluginPackageJSON,- updatePluginSettings,wait,waitUntilLog} from '@shared/extra-utils'-import { PeerTubePlugin, PeerTubePluginIndex, PluginPackageJson, PluginType, PublicServerSetting, ServerConfig, User } from '@shared/models'+import { PluginType, ServerConfig, User } from '@shared/models'const expect = chai.expectdescribe('Test plugins', function () {let server: ServerInfo = null+ let command: PluginsCommandbefore(async function () {this.timeout(30000)@@ -54,60 +45,51 @@ describe('Test plugins', function () {this.timeout(30000){- const res = await listAvailablePlugins({- url: server.url,- accessToken: server.accessToken,+ const body = await command.listAvailable({count: 1,start: 0,pluginType: PluginType.THEME,search: 'background-red'})- expect(res.body.total).to.be.at.least(1)- expect(res.body.data).to.have.lengthOf(1)+ expect(body.total).to.be.at.least(1)+ expect(body.data).to.have.lengthOf(1)}{- const res1 = await listAvailablePlugins({- url: server.url,- accessToken: server.accessToken,+ const body1 = await command.listAvailable({count: 2,start: 0,sort: 'npmName'})- const data1: PeerTubePluginIndex[] = res1.body.data+ expect(body1.total).to.be.at.least(2)- expect(res1.body.total).to.be.at.least(2)+ const data1 = body1.dataexpect(data1).to.have.lengthOf(2)- const res2 = await listAvailablePlugins({- url: server.url,- accessToken: server.accessToken,+ const body2 = await command.listAvailable({count: 2,start: 0,sort: '-npmName'})- const data2: PeerTubePluginIndex[] = res2.body.data+ expect(body2.total).to.be.at.least(2)- expect(res2.body.total).to.be.at.least(2)+ const data2 = body2.dataexpect(data2).to.have.lengthOf(2)expect(data1[0].npmName).to.not.equal(data2[0].npmName)}{- const res = await listAvailablePlugins({- url: server.url,- accessToken: server.accessToken,+ const body = await command.listAvailable({count: 10,start: 0,pluginType: PluginType.THEME,search: 'background-red',currentPeerTubeEngine: '1.0.0'})- const data: PeerTubePluginIndex[] = res.body.data- const p = data.find(p => p.npmName === 'peertube-theme-background-red')+ const p = body.data.find(p => p.npmName === 'peertube-theme-background-red')expect(p).to.be.undefined}})@@ -115,17 +97,8 @@ describe('Test plugins', function () {it('Should install a plugin and a theme', async function () {this.timeout(30000)- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-theme-background-red'- })+ await command.install({ npmName: 'peertube-plugin-hello-world' })+ await command.install({ npmName: 'peertube-theme-background-red' })})it('Should have the plugin loaded in the configuration', async function () {@@ -161,45 +134,38 @@ describe('Test plugins', function () {it('Should list plugins and themes', async function () {{- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,+ const body = await command.list({count: 1,start: 0,pluginType: PluginType.THEME})- const data: PeerTubePlugin[] = res.body.data+ expect(body.total).to.be.at.least(1)- expect(res.body.total).to.be.at.least(1)+ const data = body.dataexpect(data).to.have.lengthOf(1)expect(data[0].name).to.equal('background-red')}{- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,+ const body = await command.list({count: 2,start: 0,sort: 'name'})- const data: PeerTubePlugin[] = res.body.data+ const data = bodyexpect(data[0].name).to.equal('background-red')expect(data[1].name).to.equal('hello-world')}{- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,+ const body = await command.list({count: 2,start: 1,sort: 'name'})- const data: PeerTubePlugin[] = res.body.data- expect(data[0].name).to.equal('hello-world')+ expect(body.data[0].name).to.equal('hello-world')}})@@ -208,9 +174,8 @@ describe('Test plugins', function () {})it('Should get public settings', async function () {- const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' })-- const publicSettings = (res.body as PublicServerSetting).publicSettings+ const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' })+ const publicSettings = body.publicSettingsexpect(Object.keys(publicSettings)).to.have.lengthOf(1)expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ])@@ -222,9 +187,7 @@ describe('Test plugins', function () {'admin-name': 'Cid'}- await updatePluginSettings({- url: server.url,- accessToken: server.accessToken,+ await command.updateSettings({npmName: 'peertube-plugin-hello-world',settings})@@ -238,13 +201,7 @@ describe('Test plugins', function () {it('Should get a plugin and a theme', async function () {{- const res = await getPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- const plugin: PeerTubePlugin = res.body+ const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' })expect(plugin.type).to.equal(PluginType.PLUGIN)expect(plugin.name).to.equal('hello-world')@@ -262,13 +219,7 @@ describe('Test plugins', function () {}{- const res = await getPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-theme-background-red'- })-- const plugin: PeerTubePlugin = res.body+ const plugin = await command.get({ npmName: 'peertube-theme-background-red' })expect(plugin.type).to.equal(PluginType.THEME)expect(plugin.name).to.equal('background-red')@@ -295,92 +246,59 @@ describe('Test plugins', function () {await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')// Fake update package.json- const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world')+ const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world')const oldVersion = packageJSON.versionpackageJSON.version = '0.0.1'- await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON)+ await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON)// Restart the server to take into account this changekillallServers([ server ])await reRunServer(server){- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,- pluginType: PluginType.PLUGIN- })-- const plugin: PeerTubePlugin = res.body.data[0]+ const body = await command.list({ pluginType: PluginType.PLUGIN })+ const plugin = body.data[0]expect(plugin.version).to.equal('0.0.1')expect(plugin.latestVersion).to.existexpect(plugin.latestVersion).to.not.equal('0.0.1')}{- await updatePlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,- pluginType: PluginType.PLUGIN- })+ await command.update({ npmName: 'peertube-plugin-hello-world' })- const plugin: PeerTubePlugin = res.body.data[0]+ const body = await command.list({ pluginType: PluginType.PLUGIN })+ const plugin = body.data[0]expect(plugin.version).to.equal(oldVersion)- const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world')+ const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world')expect(updatedPackageJSON.version).to.equal(oldVersion)}})it('Should uninstall the plugin', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,- pluginType: PluginType.PLUGIN- })+ await command.uninstall({ npmName: 'peertube-plugin-hello-world' })- expect(res.body.total).to.equal(0)- expect(res.body.data).to.have.lengthOf(0)+ const body = await command.list({ pluginType: PluginType.PLUGIN })+ expect(body.total).to.equal(0)+ expect(body.data).to.have.lengthOf(0)})it('Should list uninstalled plugins', async function () {- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,- pluginType: PluginType.PLUGIN,- uninstalled: true- })+ const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true })+ expect(body.total).to.equal(1)+ expect(body.data).to.have.lengthOf(1)- expect(res.body.total).to.equal(1)- expect(res.body.data).to.have.lengthOf(1)-- const plugin: PeerTubePlugin = res.body.data[0]+ const plugin = body.data[0]expect(plugin.name).to.equal('hello-world')expect(plugin.enabled).to.be.falseexpect(plugin.uninstalled).to.be.true})it('Should uninstall the theme', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-theme-background-red'- })+ await command.uninstall({ npmName: 'peertube-theme-background-red' })})it('Should have updated the configuration', async function () {@@ -406,21 +324,13 @@ describe('Test plugins', function () {this.timeout(60000)async function check () {- const res = await listPlugins({- url: server.url,- accessToken: server.accessToken,- pluginType: PluginType.PLUGIN- })-- const plugins: PeerTubePlugin[] = res.body.data-+ const body = await command.list({ pluginType: PluginType.PLUGIN })+ const plugins = body.dataexpect(plugins.find(p => p.name === 'test-broken')).to.not.exist}- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-broken'),+ await command.install({+ path: PluginsCommand.getPluginTestPath('-broken'),expectedStatus: HttpStatusCode.BAD_REQUEST_400})diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.tsindex 92927ea97f..ba4183e083 100644--- a/server/tests/api/users/users.ts+++ b/server/tests/api/users/users.ts@@ -23,7 +23,6 @@ import {getUsersListPaginationAndSort,getVideoChannel,getVideosList,- installPlugin,killallServers,login,logout,@@ -75,7 +74,7 @@ describe('Test users', function () {await setAccessTokensToServers([ server ])- await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })+ await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })})describe('OAuth client', function () {diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.tsindex efdc207482..7b8746a5d6 100644--- a/server/tests/cli/plugins.ts+++ b/server/tests/cli/plugins.ts@@ -6,8 +6,8 @@ import {cleanupTests,flushAndRunServer,getConfig,- getPluginTestPath,killallServers,+ PluginsCommand,reRunServer,ServerInfo,setAccessTokensToServers@@ -27,7 +27,7 @@ describe('Test plugin scripts', function () {it('Should install a plugin from stateless CLI', async function () {this.timeout(60000)- const packagePath = getPluginTestPath()+ const packagePath = PluginsCommand.getPluginTestPath()await server.cliCommand.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`)})diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.tsindex e4eae7e8c0..0d4edbee0f 100644--- a/server/tests/external-plugins/auth-ldap.ts+++ b/server/tests/external-plugins/auth-ldap.ts@@ -3,17 +3,7 @@import 'mocha'import { expect } from 'chai'import { User } from '@shared/models/users/user.model'-import {- blockUser,- getMyUserInformation,- installPlugin,- setAccessTokensToServers,- unblockUser,- uninstallPlugin,- updatePluginSettings,- uploadVideo,- userLogin-} from '../../../shared/extra-utils'+import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils'import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'describe('Official plugin auth-ldap', function () {@@ -27,11 +17,7 @@ describe('Official plugin auth-ldap', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-auth-ldap'- })+ await server.pluginsCommand.install({ npmName: 'peertube-plugin-auth-ldap' })})it('Should not login with without LDAP settings', async function () {@@ -39,9 +25,7 @@ describe('Official plugin auth-ldap', function () {})it('Should not login with bad LDAP settings', async function () {- await updatePluginSettings({- url: server.url,- accessToken: server.accessToken,+ await server.pluginsCommand.updateSettings({npmName: 'peertube-plugin-auth-ldap',settings: {'bind-credentials': 'GoodNewsEveryone',@@ -59,9 +43,7 @@ describe('Official plugin auth-ldap', function () {})it('Should not login with good LDAP settings but wrong username/password', async function () {- await updatePluginSettings({- url: server.url,- accessToken: server.accessToken,+ await server.pluginsCommand.updateSettings({npmName: 'peertube-plugin-auth-ldap',settings: {'bind-credentials': 'GoodNewsEveryone',@@ -114,7 +96,7 @@ describe('Official plugin auth-ldap', function () {})it('Should not login if the plugin is uninstalled', async function () {- await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-auth-ldap' })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })await userLogin(server, { username: '[email protected]', password: 'fry' }, 400)})diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.tsindex 18ea17d78c..6baf375660 100644--- a/server/tests/external-plugins/auto-block-videos.ts+++ b/server/tests/external-plugins/auto-block-videos.ts@@ -7,11 +7,9 @@ import {doubleFollow,getBlacklistedVideosList,getVideosList,- installPlugin,MockBlocklist,removeVideoFromBlacklist,setAccessTokensToServers,- updatePluginSettings,uploadVideoAndGetId,wait} from '../../../shared/extra-utils'@@ -28,11 +26,8 @@ async function check (server: ServerInfo, videoUUID: string, exists = true) {const video = res.body.data.find(v => v.uuid === videoUUID)- if (exists) {- expect(video).to.not.be.undefined- } else {- expect(video).to.be.undefined- }+ if (exists) expect(video).to.not.be.undefined+ else expect(video).to.be.undefined}describe('Official plugin auto-block videos', function () {@@ -49,11 +44,7 @@ describe('Official plugin auto-block videos', function () {await setAccessTokensToServers(servers)for (const server of servers) {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-auto-block-videos'- })+ await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-block-videos' })}blocklistServer = new MockBlocklist()@@ -78,9 +69,7 @@ describe('Official plugin auto-block videos', function () {})it('Should update plugin settings', async function () {- await updatePluginSettings({- url: servers[0].url,- accessToken: servers[0].accessToken,+ await servers[0].pluginsCommand.updateSettings({npmName: 'peertube-plugin-auto-block-videos',settings: {'blocklist-urls': `http://localhost:${port}/blocklist`,diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.tsindex 09355d9326..8fcf94452f 100644--- a/server/tests/external-plugins/auto-mute.ts+++ b/server/tests/external-plugins/auto-mute.ts@@ -2,30 +2,24 @@import 'mocha'import { expect } from 'chai'+import { HttpStatusCode } from '@shared/core-utils'import {addAccountToServerBlocklist,addServerToAccountBlocklist,- removeAccountFromServerBlocklist-} from '@shared/extra-utils/users/blocklist'-import {+ cleanupTests,doubleFollow,+ flushAndRunMultipleServers,getVideosList,- installPlugin,+ killallServers,makeGetRequest,MockBlocklist,+ removeAccountFromServerBlocklist,+ reRunServer,+ ServerInfo,setAccessTokensToServers,- updatePluginSettings,uploadVideoAndGetId,wait-} from '../../../shared/extra-utils'-import {- cleanupTests,- flushAndRunMultipleServers,- killallServers,- reRunServer,- ServerInfo-} from '../../../shared/extra-utils/server/servers'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+} from '@shared/extra-utils'describe('Official plugin auto-mute', function () {const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'@@ -40,11 +34,7 @@ describe('Official plugin auto-mute', function () {await setAccessTokensToServers(servers)for (const server of servers) {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-auto-mute'- })+ await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })}blocklistServer = new MockBlocklist()@@ -57,9 +47,7 @@ describe('Official plugin auto-mute', function () {})it('Should update plugin settings', async function () {- await updatePluginSettings({- url: servers[0].url,- accessToken: servers[0].accessToken,+ await servers[0].pluginsCommand.updateSettings({npmName: 'peertube-plugin-auto-mute',settings: {'blocklist-urls': `http://localhost:${port}/blocklist`,@@ -185,9 +173,7 @@ describe('Official plugin auto-mute', function () {})it('Should enable auto mute list', async function () {- await updatePluginSettings({- url: servers[0].url,- accessToken: servers[0].accessToken,+ await servers[0].pluginsCommand.updateSettings({npmName: 'peertube-plugin-auto-mute',settings: {'blocklist-urls': '',@@ -206,9 +192,7 @@ describe('Official plugin auto-mute', function () {it('Should mute an account on server 1, and server 2 auto mutes it', async function () {this.timeout(20000)- await updatePluginSettings({- url: servers[1].url,- accessToken: servers[1].accessToken,+ await servers[1].pluginsCommand.updateSettings({npmName: 'peertube-plugin-auto-mute',settings: {'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.tsindex 0f57ef7fee..0de5b523bc 100644--- a/server/tests/plugins/action-hooks.ts+++ b/server/tests/plugins/action-hooks.ts@@ -11,8 +11,7 @@ import {createUser,createVideoPlaylist,deleteVideoComment,- getPluginTestPath,- installPlugin,+ PluginsCommand,registerUser,removeUser,setAccessTokensToServers,@@ -49,11 +48,7 @@ describe('Test plugin action hooks', function () {await setAccessTokensToServers(servers)await setDefaultVideoChannel(servers)- await installPlugin({- url: servers[0].url,- accessToken: servers[0].accessToken,- path: getPluginTestPath()- })+ await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })killallServers([ servers[0] ])diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.tsindex 5addb45c78..4243027863 100644--- a/server/tests/plugins/external-auth.ts+++ b/server/tests/plugins/external-auth.ts@@ -2,27 +2,26 @@import 'mocha'import { expect } from 'chai'-import { ServerConfig, User, UserRole } from '@shared/models'+import { HttpStatusCode } from '@shared/core-utils'import {+ cleanupTests,+ createUser,decodeQueryString,+ flushAndRunServer,getConfig,- getExternalAuth,getMyUserInformation,- getPluginTestPath,- installPlugin,loginUsingExternalToken,logout,+ PluginsCommand,refreshToken,+ ServerInfo,setAccessTokensToServers,- uninstallPlugin,updateMyUser,- wait,userLogin,- updatePluginSettings,- createUser-} from '../../../shared/extra-utils'-import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+ wait,+ waitUntilLog+} from '@shared/extra-utils'+import { ServerConfig, User, UserRole } from '@shared/models'async function loginExternal (options: {server: ServerInfo@@ -33,13 +32,12 @@ async function loginExternal (options: {statusCodeExpected?: HttpStatusCodestatusCodeExpectedStep2?: HttpStatusCode}) {- const res = await getExternalAuth({- url: options.server.url,+ const res = await options.server.pluginsCommand.getExternalAuth({npmName: options.npmName,npmVersion: '0.0.1',authName: options.authName,query: options.query,- statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302+ expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302})if (res.status !== HttpStatusCode.FOUND_302) return@@ -75,11 +73,7 @@ describe('Test external auth plugins', function () {await setAccessTokensToServers([ server ])for (const suffix of [ 'one', 'two', 'three' ]) {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-external-auth-' + suffix)- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) })}})@@ -98,15 +92,14 @@ describe('Test external auth plugins', function () {})it('Should redirect for a Cyan login', async function () {- const res = await getExternalAuth({- url: server.url,+ const res = await server.pluginsCommand.getExternalAuth({npmName: 'test-external-auth-one',npmVersion: '0.0.1',authName: 'external-auth-1',query: {username: 'cyan'},- statusCodeExpected: HttpStatusCode.FOUND_302+ expectedStatus: HttpStatusCode.FOUND_302})const location = res.header.location@@ -275,9 +268,7 @@ describe('Test external auth plugins', function () {})it('Should unregister external-auth-2 and do not login existing Kefka', async function () {- await updatePluginSettings({- url: server.url,- accessToken: server.accessToken,+ await server.pluginsCommand.updateSettings({npmName: 'peertube-plugin-test-external-auth-one',settings: { disableKefka: true }})@@ -309,11 +300,7 @@ describe('Test external auth plugins', function () {})it('Should uninstall the plugin one and do not login Cyan', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-test-external-auth-one'- })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' })await loginExternal({server,diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.tsindex e2ec5457b8..c51e96ab78 100644--- a/server/tests/plugins/filter-hooks.ts+++ b/server/tests/plugins/filter-hooks.ts@@ -14,7 +14,6 @@ import {getAccountVideos,getConfig,getMyVideos,- getPluginTestPath,getVideo,getVideoChannelVideos,getVideoCommentThreads,@@ -23,8 +22,8 @@ import {getVideosListPagination,getVideoThreadComments,getVideoWithToken,- installPlugin,makeRawRequest,+ PluginsCommand,registerUser,ServerInfo,setAccessTokensToServers,@@ -63,17 +62,8 @@ describe('Test plugin filter hooks', function () {await setDefaultVideoChannel(servers)await doubleFollow(servers[0], servers[1])- await installPlugin({- url: servers[0].url,- accessToken: servers[0].accessToken,- path: getPluginTestPath()- })-- await installPlugin({- url: servers[0].url,- accessToken: servers[0].accessToken,- path: getPluginTestPath('-filter-translations')- })+ await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath() })+ await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })for (let i = 0; i < 10; i++) {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.tsindex 4fa8caa3a3..80d67ae0e4 100644--- a/server/tests/plugins/html-injection.ts+++ b/server/tests/plugins/html-injection.ts@@ -5,30 +5,31 @@ import * as chai from 'chai'import {cleanupTests,flushAndRunServer,- getPluginsCSS,- installPlugin,makeHTMLRequest,+ PluginsCommand,ServerInfo,- setAccessTokensToServers,- uninstallPlugin+ setAccessTokensToServers} from '../../../shared/extra-utils'const expect = chai.expectdescribe('Test plugins HTML injection', function () {let server: ServerInfo = null+ let command: PluginsCommandbefore(async function () {this.timeout(30000)server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])++ command = server.pluginsCommand})it('Should not inject global css file in HTML', async function () {{- const res = await getPluginsCSS(server.url)- expect(res.text).to.be.empty+ const text = await command.getCSS()+ expect(text).to.be.empty}for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {@@ -40,17 +41,13 @@ describe('Test plugins HTML injection', function () {it('Should install a plugin and a theme', async function () {this.timeout(30000)- await installPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })+ await command.install({ npmName: 'peertube-plugin-hello-world' })})it('Should have the correct global css', async function () {{- const res = await getPluginsCSS(server.url)- expect(res.text).to.contain('background-color: red')+ const text = await command.getCSS()+ expect(text).to.contain('background-color: red')}for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {@@ -60,15 +57,11 @@ describe('Test plugins HTML injection', function () {})it('Should have an empty global css on uninstall', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })+ await command.uninstall({ npmName: 'peertube-plugin-hello-world' }){- const res = await getPluginsCSS(server.url)- expect(res.text).to.be.empty+ const text = await command.getCSS()+ expect(text).to.be.empty}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.tsindex cbba638c2b..545968040f 100644--- a/server/tests/plugins/id-and-pass-auth.ts+++ b/server/tests/plugins/id-and-pass-auth.ts@@ -1,21 +1,25 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'-import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'+import { expect } from 'chai'import {+ cleanupTests,+ flushAndRunServer,+ getConfig,getMyUserInformation,- getPluginTestPath,- installPlugin,+ getUsersList,+ login,logout,+ PluginsCommand,+ refreshToken,+ ServerInfo,setAccessTokensToServers,- uninstallPlugin,updateMyUser,userLogin,wait,- login, refreshToken, getConfig, updatePluginSettings, getUsersList-} from '../../../shared/extra-utils'-import { User, UserRole, ServerConfig } from '@shared/models'-import { expect } from 'chai'+ waitUntilLog+} from '@shared/extra-utils'+import { ServerConfig, User, UserRole } from '@shared/models'describe('Test id and pass auth plugins', function () {let server: ServerInfo@@ -33,11 +37,7 @@ describe('Test id and pass auth plugins', function () {await setAccessTokensToServers([ server ])for (const suffix of [ 'one', 'two', 'three' ]) {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-id-pass-auth-' + suffix)- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) })}})@@ -180,9 +180,7 @@ describe('Test id and pass auth plugins', function () {})it('Should unregister spyro-auth and do not login existing Spyro', async function () {- await updatePluginSettings({- url: server.url,- accessToken: server.accessToken,+ await server.pluginsCommand.updateSettings({npmName: 'peertube-plugin-test-id-pass-auth-one',settings: { disableSpyro: true }})@@ -204,11 +202,7 @@ describe('Test id and pass auth plugins', function () {})it('Should uninstall the plugin one and do not login existing Crash', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-test-id-pass-auth-one'- })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' })await userLogin(server, { username: 'crash', password: 'crash password' }, 400)})diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.tsindex 0296d6eb73..0e0f616385 100644--- a/server/tests/plugins/plugin-helpers.ts+++ b/server/tests/plugins/plugin-helpers.ts@@ -1,23 +1,25 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'+import { expect } from 'chai'+import { HttpStatusCode } from '@shared/core-utils'import {checkVideoFilesWereRemoved,+ cleanupTests,doubleFollow,- getPluginTestPath,+ flushAndRunMultipleServers,getVideo,- installPlugin,+ getVideosList,+ makeGetRequest,makePostBodyRequest,+ PluginsCommand,+ ServerInfo,setAccessTokensToServers,uploadVideoAndGetId,viewVideo,- getVideosList,waitJobs,- makeGetRequest-} from '../../../shared/extra-utils'-import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'-import { expect } from 'chai'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+ waitUntilLog+} from '@shared/extra-utils'function postCommand (server: ServerInfo, command: string, bodyArg?: object) {const body = { command }@@ -42,11 +44,7 @@ describe('Test plugin helpers', function () {await doubleFollow(servers[0], servers[1])- await installPlugin({- url: servers[0].url,- accessToken: servers[0].accessToken,- path: getPluginTestPath('-four')- })+ await servers[0].pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-four') })})describe('Logger', function () {diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.tsindex 24e6a1e834..81e18dabd7 100644--- a/server/tests/plugins/plugin-router.ts+++ b/server/tests/plugins/plugin-router.ts@@ -1,16 +1,17 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'+import { expect } from 'chai'+import { HttpStatusCode } from '@shared/core-utils'import {- getPluginTestPath,- installPlugin,+ cleanupTests,+ flushAndRunServer,makeGetRequest,makePostBodyRequest,- setAccessTokensToServers, uninstallPlugin-} from '../../../shared/extra-utils'-import { expect } from 'chai'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+ PluginsCommand,+ ServerInfo,+ setAccessTokensToServers+} from '@shared/extra-utils'describe('Test plugin helpers', function () {let server: ServerInfo@@ -25,11 +26,7 @@ describe('Test plugin helpers', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-five')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-five') })})it('Should answer "pong"', async function () {@@ -85,11 +82,7 @@ describe('Test plugin helpers', function () {})it('Should remove the plugin and remove the routes', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-test-five'- })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-five' })for (const path of basePaths) {await makeGetRequest({diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.tsindex 3c46b2585c..4c65463f26 100644--- a/server/tests/plugins/plugin-storage.ts+++ b/server/tests/plugins/plugin-storage.ts@@ -7,13 +7,14 @@ import { join } from 'path'import { HttpStatusCode } from '@shared/core-utils'import {buildServerDirectory,- getPluginTestPath,- installPlugin,+ cleanupTests,+ flushAndRunServer,makeGetRequest,+ PluginsCommand,+ ServerInfo,setAccessTokensToServers,- uninstallPlugin-} from '../../../shared/extra-utils'-import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'+ waitUntilLog+} from '@shared/extra-utils'describe('Test plugin storage', function () {let server: ServerInfo@@ -24,11 +25,7 @@ describe('Test plugin storage', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-six')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })})describe('DB storage', function () {@@ -76,22 +73,14 @@ describe('Test plugin storage', function () {})it('Should still have the file after an uninstallation', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-test-six'- })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-six' })const content = await getFileContent()expect(content).to.equal('Prince Ali')})it('Should still have the file after the reinstallation', async function () {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-six')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-six') })const content = await getFileContent()expect(content).to.equal('Prince Ali')diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.tsindex eefb2294df..f1ff910777 100644--- a/server/tests/plugins/plugin-transcoding.ts+++ b/server/tests/plugins/plugin-transcoding.ts@@ -4,25 +4,25 @@ import 'mocha'import { expect } from 'chai'import { join } from 'path'import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'-import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models'import {buildServerDirectory,+ cleanupTests,createLive,+ flushAndRunServer,getConfig,- getPluginTestPath,getVideo,- installPlugin,+ PluginsCommand,sendRTMPStreamInVideo,+ ServerInfo,setAccessTokensToServers,setDefaultVideoChannel,testFfmpegStreamError,- uninstallPlugin,updateCustomSubConfig,uploadVideoAndGetId,waitJobs,waitUntilLivePublished-} from '../../../shared/extra-utils'-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'+} from '@shared/extra-utils'+import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models'async function createLiveWrapper (server: ServerInfo) {const liveAttributes = {@@ -109,11 +109,7 @@ describe('Test transcoding plugins', function () {}before(async function () {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-transcoding-one')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') })})it('Should have the appropriate available profiles', async function () {@@ -225,7 +221,7 @@ describe('Test transcoding plugins', function () {it('Should default to the default profile if the specified profile does not exist', async function () {this.timeout(240000)- await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })const res = await getConfig(server.url)const config = res.body as ServerConfig@@ -244,11 +240,7 @@ describe('Test transcoding plugins', function () {describe('When using a plugin adding new encoders', function () {before(async function () {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-transcoding-two')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') })await updateConf(server, 'test-vod-profile', 'test-live-profile')})diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.tsindex 74ca82e2f2..f430f82b82 100644--- a/server/tests/plugins/plugin-unloading.ts+++ b/server/tests/plugins/plugin-unloading.ts@@ -1,18 +1,9 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'-import {- cleanupTests,- flushAndRunServer,- getPluginTestPath,- makeGetRequest,- installPlugin,- uninstallPlugin,- ServerInfo,- setAccessTokensToServers-} from '../../../shared/extra-utils'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'import { expect } from 'chai'+import { HttpStatusCode } from '@shared/core-utils'+import { cleanupTests, flushAndRunServer, makeGetRequest, PluginsCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'describe('Test plugins module unloading', function () {let server: ServerInfo = null@@ -25,11 +16,7 @@ describe('Test plugins module unloading', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-unloading')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') })})it('Should return a numeric value', async function () {@@ -54,11 +41,7 @@ describe('Test plugins module unloading', function () {})it('Should uninstall the plugin and free the route', async function () {- await uninstallPlugin({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-test-unloading'- })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-unloading' })await makeGetRequest({url: server.url,@@ -68,11 +51,8 @@ describe('Test plugins module unloading', function () {})it('Should return a different numeric value', async function () {- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-unloading')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-unloading') })+const res = await makeGetRequest({url: server.url,path: requestPath,diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.tsindex 9fd2ba1c5e..0e11a0b537 100644--- a/server/tests/plugins/translations.ts+++ b/server/tests/plugins/translations.ts@@ -1,20 +1,15 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import * as chai from 'chai'import 'mocha'+import * as chai from 'chai'+import { PluginsCommand, setAccessTokensToServers } from '../../../shared/extra-utils'import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'-import {- getPluginTestPath,- getPluginTranslations,- installPlugin,- setAccessTokensToServers,- uninstallPlugin-} from '../../../shared/extra-utils'const expect = chai.expectdescribe('Test plugin translations', function () {let server: ServerInfo+ let command: PluginsCommandbefore(async function () {this.timeout(30000)@@ -22,29 +17,22 @@ describe('Test plugin translations', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath()- })+ command = server.pluginsCommand- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-filter-translations')- })+ await command.install({ path: PluginsCommand.getPluginTestPath() })+ await command.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })})it('Should not have translations for locale pt', async function () {- const res = await getPluginTranslations({ url: server.url, locale: 'pt' })+ const body = await command.getTranslations({ locale: 'pt' })- expect(res.body).to.deep.equal({})+ expect(body).to.deep.equal({})})it('Should have translations for locale fr', async function () {- const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' })+ const body = await command.getTranslations({ locale: 'fr-FR' })- expect(res.body).to.deep.equal({+ expect(body).to.deep.equal({'peertube-plugin-test': {Hi: 'Coucou'},@@ -55,9 +43,9 @@ describe('Test plugin translations', function () {})it('Should have translations of locale it', async function () {- const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' })+ const body = await command.getTranslations({ locale: 'it-IT' })- expect(res.body).to.deep.equal({+ expect(body).to.deep.equal({'peertube-plugin-test-filter-translations': {'Hello world': 'Ciao, mondo!'}@@ -65,12 +53,12 @@ describe('Test plugin translations', function () {})it('Should remove the plugin and remove the locales', async function () {- await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-filter-translations' })+ await command.uninstall({ npmName: 'peertube-plugin-test-filter-translations' }){- const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' })+ const body = await command.getTranslations({ locale: 'fr-FR' })- expect(res.body).to.deep.equal({+ expect(body).to.deep.equal({'peertube-plugin-test': {Hi: 'Coucou'}@@ -78,9 +66,9 @@ describe('Test plugin translations', function () {}{- const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' })+ const body = await command.getTranslations({ locale: 'it-IT' })- expect(res.body).to.deep.equal({})+ expect(body).to.deep.equal({})}})diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.tsindex eb014c596d..4124e8a523 100644--- a/server/tests/plugins/video-constants.ts+++ b/server/tests/plugins/video-constants.ts@@ -1,22 +1,24 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import * as chai from 'chai'import 'mocha'-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'+import * as chai from 'chai'+import { HttpStatusCode } from '@shared/core-utils'import {+ cleanupTests,createVideoPlaylist,- getPluginTestPath,+ flushAndRunServer,getVideo,getVideoCategories,getVideoLanguages,- getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies,- installPlugin,+ getVideoLicences,+ getVideoPlaylistPrivacies,+ getVideoPrivacies,+ PluginsCommand,+ ServerInfo,setAccessTokensToServers,- uninstallPlugin,uploadVideo-} from '../../../shared/extra-utils'-import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+} from '@shared/extra-utils'+import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'const expect = chai.expect@@ -29,11 +31,7 @@ describe('Test plugin altering video constants', function () {server = await flushAndRunServer(1)await setAccessTokensToServers([ server ])- await installPlugin({- url: server.url,- accessToken: server.accessToken,- path: getPluginTestPath('-video-constants')- })+ await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })})it('Should have updated languages', async function () {@@ -117,7 +115,7 @@ describe('Test plugin altering video constants', function () {})it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {- await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' })+ await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' }){const res = await getVideoLanguages(server.url)diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.tsindex 652779eea2..cf6418249b 100644--- a/shared/extra-utils/index.ts+++ b/shared/extra-utils/index.ts@@ -15,7 +15,6 @@ export * from './requests/requests'export * from './server/clients'export * from './server/config'-export * from './server/plugins'export * from './server/servers'export * from './users/accounts'diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.tsindex b5b6b21162..e602fec7e2 100644--- a/shared/extra-utils/server/index.ts+++ b/shared/extra-utils/server/index.ts@@ -4,3 +4,5 @@ export * from './follows-command'export * from './follows'export * from './jobs'export * from './jobs-command'+export * from './plugins-command'+export * from './plugins'diff --git a/shared/extra-utils/server/plugins-command.ts b/shared/extra-utils/server/plugins-command.tsnew file mode 100644index 0000000000..f06e58a22f--- /dev/null+++ b/shared/extra-utils/server/plugins-command.ts@@ -0,0 +1,245 @@+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */++import { readJSON, writeJSON } from 'fs-extra'+import { join } from 'path'+import { root } from '@server/helpers/core-utils'+import { HttpStatusCode } from '@shared/core-utils'+import {+ PeerTubePlugin,+ PeerTubePluginIndex,+ PeertubePluginIndexList,+ PluginPackageJson,+ PluginTranslation,+ PluginType,+ PublicServerSetting,+ RegisteredServerSettings,+ ResultList+} from '@shared/models'+import { buildServerDirectory } from '../miscs'+import { AbstractCommand, OverrideCommandOptions } from '../shared'++export class PluginsCommand extends AbstractCommand {++ static getPluginTestPath (suffix = '') {+ return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)+ }++ list (options: OverrideCommandOptions & {+ start?: number+ count?: number+ sort?: string+ pluginType?: PluginType+ uninstalled?: boolean+ }) {+ const { start, count, sort, pluginType, uninstalled } = options+ const path = '/api/v1/plugins'++ return this.getRequestBody<ResultList<PeerTubePlugin>>({+ ...options,++ path,+ query: {+ start,+ count,+ sort,+ pluginType,+ uninstalled+ },+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ listAvailable (options: OverrideCommandOptions & {+ start?: number+ count?: number+ sort?: string+ pluginType?: PluginType+ currentPeerTubeEngine?: string+ search?: string+ expectedStatus?: HttpStatusCode+ }) {+ const { start, count, sort, pluginType, search, currentPeerTubeEngine } = options+ const path = '/api/v1/plugins/available'++ const query: PeertubePluginIndexList = {+ start,+ count,+ sort,+ pluginType,+ currentPeerTubeEngine,+ search+ }++ return this.getRequestBody<ResultList<PeerTubePluginIndex>>({+ ...options,++ path,+ query,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ get (options: OverrideCommandOptions & {+ npmName: string+ }) {+ const path = '/api/v1/plugins/' + options.npmName++ return this.getRequestBody<PeerTubePlugin>({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ updateSettings (options: OverrideCommandOptions & {+ npmName: string+ settings: any+ }) {+ const { npmName, settings } = options+ const path = '/api/v1/plugins/' + npmName + '/settings'++ return this.putBodyRequest({+ ...options,++ path,+ fields: { settings },+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ getRegisteredSettings (options: OverrideCommandOptions & {+ npmName: string+ }) {+ const path = '/api/v1/plugins/' + options.npmName + '/registered-settings'++ return this.getRequestBody<RegisteredServerSettings>({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ getPublicSettings (options: OverrideCommandOptions & {+ npmName: string+ }) {+ const { npmName } = options+ const path = '/api/v1/plugins/' + npmName + '/public-settings'++ return this.getRequestBody<PublicServerSetting>({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ getTranslations (options: OverrideCommandOptions & {+ locale: string+ }) {+ const { locale } = options+ const path = '/plugins/translations/' + locale + '.json'++ return this.getRequestBody<PluginTranslation>({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ install (options: OverrideCommandOptions & {+ path?: string+ npmName?: string+ }) {+ const { npmName, path } = options+ const apiPath = '/api/v1/plugins/install'++ return this.postBodyRequest({+ ...options,++ path: apiPath,+ fields: { npmName, path },+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ update (options: OverrideCommandOptions & {+ path?: string+ npmName?: string+ }) {+ const { npmName, path } = options+ const apiPath = '/api/v1/plugins/update'++ return this.postBodyRequest({+ ...options,++ path: apiPath,+ fields: { npmName, path },+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ uninstall (options: OverrideCommandOptions & {+ npmName: string+ }) {+ const { npmName } = options+ const apiPath = '/api/v1/plugins/uninstall'++ return this.postBodyRequest({+ ...options,++ path: apiPath,+ fields: { npmName },+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204+ })+ }++ getCSS (options: OverrideCommandOptions = {}) {+ const path = '/plugins/global.css'++ return this.getRequestText({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ getExternalAuth (options: OverrideCommandOptions & {+ npmName: string+ npmVersion: string+ authName: string+ query?: any+ }) {+ const { npmName, npmVersion, authName, query } = options++ const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName++ return this.getRequest({+ ...options,++ path,+ query,+ defaultExpectedStatus: HttpStatusCode.OK_200,+ redirects: 0+ })+ }++ updatePackageJSON (npmName: string, json: any) {+ const path = this.getPackageJSONPath(npmName)++ return writeJSON(path, json)+ }++ getPackageJSON (npmName: string): Promise<PluginPackageJson> {+ const path = this.getPackageJSONPath(npmName)++ return readJSON(path)+ }++ private getPackageJSONPath (npmName: string) {+ return buildServerDirectory(this.server, join('plugins', 'node_modules', npmName, 'package.json'))+ }+}diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.tsindex d53e5b3828..1084ea4f43 100644--- a/shared/extra-utils/server/plugins.ts+++ b/shared/extra-utils/server/plugins.ts@@ -1,307 +1,18 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import { expect } from 'chai'-import { readJSON, writeJSON } from 'fs-extra'-import { join } from 'path'-import { RegisteredServerSettings } from '@shared/models'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'-import { PeertubePluginIndexList } from '../../models/plugins/plugin-index/peertube-plugin-index-list.model'-import { PluginType } from '../../models/plugins/plugin.type'-import { buildServerDirectory, root } from '../miscs/miscs'-import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'-import { ServerInfo } from './servers'--function listPlugins (parameters: {- url: string- accessToken: string- start?: number- count?: number- sort?: string- pluginType?: PluginType- uninstalled?: boolean- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = HttpStatusCode.OK_200 } = parameters- const path = '/api/v1/plugins'-- return makeGetRequest({- url,- path,- token: accessToken,- query: {- start,- count,- sort,- pluginType,- uninstalled- },- statusCodeExpected: expectedStatus- })-}--function listAvailablePlugins (parameters: {- url: string- accessToken: string- start?: number- count?: number- sort?: string- pluginType?: PluginType- currentPeerTubeEngine?: string- search?: string- expectedStatus?: HttpStatusCode-}) {- const {- url,- accessToken,- start,- count,- sort,- pluginType,- search,- currentPeerTubeEngine,- expectedStatus = HttpStatusCode.OK_200- } = parameters- const path = '/api/v1/plugins/available'-- const query: PeertubePluginIndexList = {- start,- count,- sort,- pluginType,- currentPeerTubeEngine,- search- }-- return makeGetRequest({- url,- path,- token: accessToken,- query,- statusCodeExpected: expectedStatus- })-}--function getPlugin (parameters: {- url: string- accessToken: string- npmName: string- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters- const path = '/api/v1/plugins/' + npmName-- return makeGetRequest({- url,- path,- token: accessToken,- statusCodeExpected: expectedStatus- })-}--function updatePluginSettings (parameters: {- url: string- accessToken: string- npmName: string- settings: any- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, settings, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters- const path = '/api/v1/plugins/' + npmName + '/settings'-- return makePutBodyRequest({- url,- path,- token: accessToken,- fields: { settings },- statusCodeExpected: expectedStatus- })-}--function getPluginRegisteredSettings (parameters: {- url: string- accessToken: string- npmName: string- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters- const path = '/api/v1/plugins/' + npmName + '/registered-settings'-- return makeGetRequest({- url,- path,- token: accessToken,- statusCodeExpected: expectedStatus- })-}+import { ServerInfo } from '../server/servers'async function testHelloWorldRegisteredSettings (server: ServerInfo) {- const res = await getPluginRegisteredSettings({- url: server.url,- accessToken: server.accessToken,- npmName: 'peertube-plugin-hello-world'- })-- const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings+ const body = await server.pluginsCommand.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' })+ const registeredSettings = body.registeredSettingsexpect(registeredSettings).to.have.length.at.least(1)const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')expect(adminNameSettings).to.not.be.undefined}-function getPublicSettings (parameters: {- url: string- npmName: string- expectedStatus?: HttpStatusCode-}) {- const { url, npmName, expectedStatus = HttpStatusCode.OK_200 } = parameters- const path = '/api/v1/plugins/' + npmName + '/public-settings'-- return makeGetRequest({- url,- path,- statusCodeExpected: expectedStatus- })-}--function getPluginTranslations (parameters: {- url: string- locale: string- expectedStatus?: HttpStatusCode-}) {- const { url, locale, expectedStatus = HttpStatusCode.OK_200 } = parameters- const path = '/plugins/translations/' + locale + '.json'-- return makeGetRequest({- url,- path,- statusCodeExpected: expectedStatus- })-}--function installPlugin (parameters: {- url: string- accessToken: string- path?: string- npmName?: string- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters- const apiPath = '/api/v1/plugins/install'-- return makePostBodyRequest({- url,- path: apiPath,- token: accessToken,- fields: { npmName, path },- statusCodeExpected: expectedStatus- })-}--function updatePlugin (parameters: {- url: string- accessToken: string- path?: string- npmName?: string- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, path, expectedStatus = HttpStatusCode.OK_200 } = parameters- const apiPath = '/api/v1/plugins/update'-- return makePostBodyRequest({- url,- path: apiPath,- token: accessToken,- fields: { npmName, path },- statusCodeExpected: expectedStatus- })-}--function uninstallPlugin (parameters: {- url: string- accessToken: string- npmName: string- expectedStatus?: HttpStatusCode-}) {- const { url, accessToken, npmName, expectedStatus = HttpStatusCode.NO_CONTENT_204 } = parameters- const apiPath = '/api/v1/plugins/uninstall'-- return makePostBodyRequest({- url,- path: apiPath,- token: accessToken,- fields: { npmName },- statusCodeExpected: expectedStatus- })-}--function getPluginsCSS (url: string) {- const path = '/plugins/global.css'-- return makeGetRequest({- url,- path,- statusCodeExpected: HttpStatusCode.OK_200- })-}--function getPackageJSONPath (server: ServerInfo, npmName: string) {- return buildServerDirectory(server, join('plugins', 'node_modules', npmName, 'package.json'))-}--function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {- const path = getPackageJSONPath(server, npmName)-- return writeJSON(path, json)-}--function getPluginPackageJSON (server: ServerInfo, npmName: string) {- const path = getPackageJSONPath(server, npmName)-- return readJSON(path)-}--function getPluginTestPath (suffix = '') {- return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)-}--function getExternalAuth (options: {- url: string- npmName: string- npmVersion: string- authName: string- query?: any- statusCodeExpected?: HttpStatusCode-}) {- const { url, npmName, npmVersion, authName, statusCodeExpected, query } = options-- const path = '/plugins/' + npmName + '/' + npmVersion + '/auth/' + authName-- return makeGetRequest({- url,- path,- query,- statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200,- redirects: 0- })-}-export {- listPlugins,- listAvailablePlugins,- installPlugin,- getPluginTranslations,- getPluginsCSS,- updatePlugin,- getPlugin,- uninstallPlugin,- testHelloWorldRegisteredSettings,- updatePluginSettings,- getPluginRegisteredSettings,- getPackageJSONPath,- updatePluginPackageJSON,- getPluginPackageJSON,- getPluginTestPath,- getPublicSettings,- getExternalAuth+ testHelloWorldRegisteredSettings}diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.tsindex 5511ce0b0d..79d6b7b1af 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'import { DebugCommand } from './debug-command'import { FollowsCommand } from './follows-command'import { JobsCommand } from './jobs-command'+import { PluginsCommand } from './plugins-command'interface ServerInfo {app: ChildProcess@@ -85,6 +86,7 @@ interface ServerInfo {debugCommand?: DebugCommandfollowsCommand?: FollowsCommandjobsCommand?: JobsCommand+ pluginsCommand?: PluginsCommand}function parallelTests () {@@ -302,6 +304,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []server.debugCommand = new DebugCommand(server)server.followsCommand = new FollowsCommand(server)server.jobsCommand = new JobsCommand(server)+ server.pluginsCommand = new PluginsCommand(server)res(server)})diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.tsindex 3815fab0e7..dd4598a913 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 {query?: { [ id: string ]: any }contentType?: stringaccept?: string+ redirects?: number}abstract class AbstractCommand {@@ -44,6 +45,19 @@ abstract class AbstractCommand {return unwrapText(this.getRequest(options))}+ protected getRequest (options: GetCommandOptions) {+ const { redirects, query, contentType, accept } = options++ return makeGetRequest({+ ...this.buildCommonRequestOptions(options),++ redirects,+ query,+ contentType,+ accept+ })+ }+protected deleteRequest (options: CommonCommandOptions) {return makeDeleteRequest(this.buildCommonRequestOptions(options))}@@ -85,18 +99,6 @@ abstract class AbstractCommand {statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus}}-- private getRequest (options: GetCommandOptions) {- const { query, contentType, accept } = options-- return makeGetRequest({- ...this.buildCommonRequestOptions(options),-- query,- contentType,- accept- })- }}export {