-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
-
+import { HttpStatusCode } from '@shared/core-utils'
import {
checkBadCountPagination,
checkBadSortPagination,
createUser,
flushAndRunServer,
immutableAssign,
- installPlugin,
- makeGetRequest, makePostBodyRequest, makePutBodyRequest,
+ makeGetRequest,
+ makePostBodyRequest,
+ makePutBodyRequest,
ServerInfo,
setAccessTokensToServers,
userLogin
-} from '../../../../shared/extra-utils'
-import { PluginType } from '../../../../shared/models/plugins/plugin.type'
-import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
+} from '@shared/extra-utils'
+import { PeerTubePlugin, PluginType } from '@shared/models'
describe('Test server plugins API validators', function () {
let server: ServerInfo
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
}
describe('With static plugin routes', function () {
it('Should fail with an unknown plugin name/plugin version', async function () {
const paths = [
+ '/plugins/' + pluginName + '/0.0.1/auth/fake-auth',
'/plugins/' + pluginName + '/0.0.1/static/images/chocobo.png',
'/plugins/' + pluginName + '/0.0.1/client-scripts/client/common-client-plugin.js',
'/themes/' + themeName + '/0.0.1/static/images/chocobo.png',
]
for (const p of paths) {
- await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 })
+ await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
}
})
await makeGetRequest({
url: server.url,
path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png',
- statusCodeExpected: 404
+ statusCodeExpected: HttpStatusCode.NOT_FOUND_404
})
})
it('Should fail with invalid versions', async function () {
const paths = [
+ '/plugins/' + pluginName + '/0.0.1.1/auth/fake-auth',
'/plugins/' + pluginName + '/0.0.1.1/static/images/chocobo.png',
'/plugins/' + pluginName + '/0.1/client-scripts/client/common-client-plugin.js',
'/themes/' + themeName + '/1/static/images/chocobo.png',
]
for (const p of paths) {
- await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 })
+ await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
}
})
]
for (const p of paths) {
- await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 })
+ await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
}
})
+ it('Should fail with an unknown auth name', async function () {
+ const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth'
+
+ await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
+ })
+
it('Should fail with an unknown static file', async function () {
const paths = [
'/plugins/' + pluginName + '/' + npmVersion + '/static/fake/chocobo.png',
]
for (const p of paths) {
- await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 })
+ await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
}
})
await makeGetRequest({
url: server.url,
path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css',
- statusCodeExpected: 404
+ statusCodeExpected: HttpStatusCode.NOT_FOUND_404
})
})
]
for (const p of paths) {
- await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 200 })
+ await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 })
}
+
+ const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth'
+ await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 })
})
})
const path = '/api/v1/plugins/available'
const baseQuery = {
search: 'super search',
- pluginType: PluginType.PLUGIN
+ pluginType: PluginType.PLUGIN,
+ currentPeerTubeEngine: '1.2.3'
}
it('Should fail with an invalid token', async function () {
path,
token: 'fake_token',
query: baseQuery,
- statusCodeExpected: 401
+ statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
})
path,
token: userAccessToken,
query: baseQuery,
- statusCodeExpected: 403
+ statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
})
})
})
+ it('Should fail with an invalid current peertube engine', async function () {
+ const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' })
+
+ await makeGetRequest({
+ url: server.url,
+ path,
+ token: server.accessToken,
+ query
+ })
+ })
+
it('Should success with the correct parameters', async function () {
await makeGetRequest({
url: server.url,
path,
token: server.accessToken,
query: baseQuery,
- statusCodeExpected: 200
+ statusCodeExpected: HttpStatusCode.OK_200
})
})
})
path,
token: 'fake_token',
query: baseQuery,
- statusCodeExpected: 401
+ statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
})
path,
token: userAccessToken,
query: baseQuery,
- statusCodeExpected: 403
+ statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
})
path,
token: server.accessToken,
query: baseQuery,
- statusCodeExpected: 200
+ statusCodeExpected: HttpStatusCode.OK_200
})
})
})
- describe('When getting a plugin or the registered settings', function () {
+ describe('When getting a plugin or the registered settings or public settings', function () {
const path = '/api/v1/plugins/'
it('Should fail with an invalid token', async function () {
url: server.url,
path: path + suffix,
token: 'fake_token',
- statusCodeExpected: 401
+ statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
}
})
url: server.url,
path: path + suffix,
token: userAccessToken,
- statusCodeExpected: 403
+ statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
}
})
it('Should fail with an invalid npm name', async function () {
- for (const suffix of [ 'toto', 'toto/registered-settings' ]) {
+ for (const suffix of [ 'toto', 'toto/registered-settings', 'toto/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
}
- for (const suffix of [ 'peertube-plugin-TOTO', 'peertube-plugin-TOTO/registered-settings' ]) {
+ for (const suffix of [ 'peertube-plugin-TOTO', 'peertube-plugin-TOTO/registered-settings', 'peertube-plugin-TOTO/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
}
})
it('Should fail with an unknown plugin', async function () {
- for (const suffix of [ 'peertube-plugin-toto', 'peertube-plugin-toto/registered-settings' ]) {
+ for (const suffix of [ 'peertube-plugin-toto', 'peertube-plugin-toto/registered-settings', 'peertube-plugin-toto/public-settings' ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
token: server.accessToken,
- statusCodeExpected: 404
+ statusCodeExpected: HttpStatusCode.NOT_FOUND_404
})
}
})
it('Should succeed with the correct parameters', async function () {
- for (const suffix of [ npmPlugin, `${npmPlugin}/registered-settings` ]) {
+ for (const suffix of [ npmPlugin, `${npmPlugin}/registered-settings`, `${npmPlugin}/public-settings` ]) {
await makeGetRequest({
url: server.url,
path: path + suffix,
token: server.accessToken,
- statusCodeExpected: 200
+ statusCodeExpected: HttpStatusCode.OK_200
})
}
})
path: path + npmPlugin + '/settings',
fields: { settings },
token: 'fake_token',
- statusCodeExpected: 401
+ statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
})
path: path + npmPlugin + '/settings',
fields: { settings },
token: userAccessToken,
- statusCodeExpected: 403
+ statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
})
path: path + 'toto/settings',
fields: { settings },
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
await makePutBodyRequest({
path: path + 'peertube-plugin-TOTO/settings',
fields: { settings },
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
})
path: path + 'peertube-plugin-toto/settings',
fields: { settings },
token: server.accessToken,
- statusCodeExpected: 404
+ statusCodeExpected: HttpStatusCode.NOT_FOUND_404
})
})
path: path + npmPlugin + '/settings',
fields: { settings },
token: server.accessToken,
- statusCodeExpected: 204
+ statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
})
})
path: path + suffix,
fields: { npmName: npmPlugin },
token: 'fake_token',
- statusCodeExpected: 401
+ statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
}
})
path: path + suffix,
fields: { npmName: npmPlugin },
token: userAccessToken,
- statusCodeExpected: 403
+ statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
}
})
path: path + suffix,
fields: { npmName: 'toto' },
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
}
path: path + suffix,
fields: { npmName: 'peertube-plugin-TOTO' },
token: server.accessToken,
- statusCodeExpected: 400
+ statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
}
})
it('Should succeed with the correct parameters', async function () {
+ this.timeout(10000)
+
const it = [
- { suffix: 'install', status: 200 },
- { suffix: 'update', status: 200 },
- { suffix: 'uninstall', status: 204 }
+ { suffix: 'install', status: HttpStatusCode.OK_200 },
+ { suffix: 'update', status: HttpStatusCode.OK_200 },
+ { suffix: 'uninstall', status: HttpStatusCode.NO_CONTENT_204 }
]
for (const obj of it) {