X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fplugins.ts;h=33f84ecbc4d0d2c8b7141c27c9d2bb73f8f59872;hb=c4fa01f7c45b66b112ebd08abce744b7c4041feb;hp=83ce6f4517bf25fdc4439c7aa5981ac7be6b1e34;hpb=09071200c73f5358e1d0bfb61a274e4f2c4ec52b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 83ce6f451..33f84ecbc 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -1,26 +1,22 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, cleanupTests, - createUser, - flushAndRunServer, - immutableAssign, - installPlugin, - 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' + createSingleServer, + makeGetRequest, + makePostBodyRequest, + makePutBodyRequest, + PeerTubeServer, + setAccessTokensToServers +} from '@shared/extra-utils' +import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models' describe('Test server plugins API validators', function () { - let server: ServerInfo + let server: PeerTubeServer let userAccessToken = null const npmPlugin = 'peertube-plugin-hello-world' @@ -36,7 +32,7 @@ describe('Test server plugins API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) @@ -45,17 +41,17 @@ describe('Test server plugins API validators', function () { password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - userAccessToken = await userLogin(server, user) + await server.users.create({ username: user.username, password: user.password }) + userAccessToken = await server.login.getAccessToken(user) { - const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) + const res = await server.plugins.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.plugins.install({ npmName: themePlugin }) const plugin = res.body as PeerTubePlugin themeVersion = plugin.version } @@ -64,6 +60,7 @@ describe('Test server plugins API validators', function () { 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', @@ -72,7 +69,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -80,12 +77,13 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', - statusCodeExpected: 404 + expectedStatus: 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', @@ -94,7 +92,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -108,10 +106,16 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: 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, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) + }) + it('Should fail with an unknown static file', async function () { const paths = [ '/plugins/' + pluginName + '/' + npmVersion + '/static/fake/chocobo.png', @@ -121,7 +125,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -129,7 +133,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', - statusCodeExpected: 404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -143,8 +147,11 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.OK_200 }) } + + const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' + await makeGetRequest({ url: server.url, path: authPath, expectedStatus: HttpStatusCode.FOUND_302 }) }) }) @@ -162,7 +169,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -172,7 +179,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -189,7 +196,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ url: server.url, @@ -200,7 +207,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid current peertube engine', async function () { - const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) + const query = { ...baseQuery, currentPeerTubeEngine: '1.0' } await makeGetRequest({ url: server.url, @@ -216,7 +223,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -233,7 +240,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -243,7 +250,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -260,7 +267,7 @@ describe('Test server plugins API validators', function () { }) it('Should fail with an invalid plugin type', async function () { - const query = immutableAssign(baseQuery, { pluginType: 5 }) + const query = { ...baseQuery, pluginType: 5 } await makeGetRequest({ url: server.url, @@ -276,12 +283,12 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + expectedStatus: 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 () { @@ -290,7 +297,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: 'fake_token', - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -301,49 +308,49 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: userAccessToken, - statusCodeExpected: 403 + expectedStatus: 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 + expectedStatus: 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 + expectedStatus: 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 + expectedStatus: 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 + expectedStatus: HttpStatusCode.OK_200 }) } }) @@ -359,7 +366,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: 'fake_token', - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -369,7 +376,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: userAccessToken, - statusCodeExpected: 403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -379,7 +386,7 @@ describe('Test server plugins API validators', function () { path: path + 'toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) await makePutBodyRequest({ @@ -387,7 +394,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-TOTO/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -397,7 +404,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -407,7 +414,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -422,7 +429,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: 'fake_token', - statusCodeExpected: 401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -434,7 +441,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: userAccessToken, - statusCodeExpected: 403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -446,7 +453,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'toto' }, token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) } @@ -456,16 +463,18 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'peertube-plugin-TOTO' }, token: server.accessToken, - statusCodeExpected: 400 + expectedStatus: 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) { @@ -474,7 +483,7 @@ describe('Test server plugins API validators', function () { path: path + obj.suffix, fields: { npmName: npmPlugin }, token: server.accessToken, - statusCodeExpected: obj.status + expectedStatus: obj.status }) } })