Introduce plugins command
This commit is contained in:
parent
9c6327f803
commit
ae2abfd3ae
|
@ -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'
|
||||
})
|
||||
await command.update({ npmName: 'peertube-plugin-hello-world' })
|
||||
|
||||
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(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'
|
||||
})
|
||||
await command.uninstall({ npmName: 'peertube-plugin-hello-world' })
|
||||
|
||||
const res = await listPlugins({
|
||||
url: server.url,
|
||||
accessToken: server.accessToken,
|
||||
pluginType: PluginType.PLUGIN
|
||||
})
|
||||
|
||||
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'
|
||||
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,
|
||||
|
|
|
@ -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] ])
|
||||
|
||||
|
|
|
@ -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?: HttpStatusCode
|
||||
statusCodeExpectedStep2?: 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,
|
||||
|
|
|
@ -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 })
|
||||
|
|
|
@ -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.expect
|
||||
|
||||
describe('Test plugins HTML injection', function () {
|
||||
let server: ServerInfo = null
|
||||
let command: PluginsCommand
|
||||
|
||||
before(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' ]) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.expect
|
||||
|
||||
describe('Test plugin translations', function () {
|
||||
let server: ServerInfo
|
||||
let command: PluginsCommand
|
||||
|
||||
before(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({})
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'))
|
||||
}
|
||||
}
|
|
@ -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.registeredSettings
|
||||
expect(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
|
||||
}
|
||||
|
|
|
@ -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?: DebugCommand
|
||||
followsCommand?: FollowsCommand
|
||||
jobsCommand?: 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)
|
||||
})
|
||||
|
|
|
@ -16,6 +16,7 @@ interface GetCommandOptions extends CommonCommandOptions {
|
|||
query?: { [ id: string ]: any }
|
||||
contentType?: string
|
||||
accept?: 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 {
|
||||
|
|
Loading…
Reference in New Issue