Verified Commit ae2abfd3 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce plugins command

parent 9c6327f8
......@@ -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 PeerTubePlugin
npmVersion = 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 PeerTubePlugin
themeVersion = plugin.version
}
......
......@@ -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 () {
......
......@@ -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.expect
describe('Test plugins', function () {
let server: ServerInfo = null
let command: PluginsCommand
before(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.data
expect(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.data
expect(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.data
expect(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 = body
expect(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.publicSettings
expect(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.version
packageJSON.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 change
killallServers([ 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.exist
expect(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.false
expect(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.data
expect(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
})
......
......@@ -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 () {
......
......@@ -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}`)
})
......
......@@ -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: 'fry@planetexpress.com', password: 'fry' }, 400)
})
......
......@@ -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`,
......
......@@ -2,30 +2,24 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'