X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fplugins.ts;h=d372221d051596f4870a60da736f46a2383d7932;hb=a54618880c394ad7571f3f3222dc96ec2dd10d9a;hp=cf80b35c297e6217c43b02b95df4c6291c677cec;hpb=a30a136c9896c656cab98d2c92cde32c534dc098;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index cf80b35c2..d372221d0 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import { HttpStatusCode } from '@shared/core-utils' import { checkBadCountPagination, checkBadSortPagination, @@ -10,14 +10,14 @@ import { 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 @@ -49,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 } @@ -64,6 +64,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 +73,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, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -80,12 +81,13 @@ describe('Test server plugins API validators', function () { 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', @@ -94,7 +96,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, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -108,10 +110,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, 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', @@ -121,7 +129,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, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -129,7 +137,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -143,8 +151,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, statusCodeExpected: HttpStatusCode.OK_200 }) } + + const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' + await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 }) }) }) @@ -162,7 +173,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -172,7 +183,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -216,7 +227,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -233,7 +244,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -243,7 +254,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -276,7 +287,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -290,7 +301,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -301,7 +312,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -312,7 +323,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } @@ -321,7 +332,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -332,7 +343,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -343,7 +354,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } }) @@ -359,7 +370,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -369,7 +380,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -379,7 +390,7 @@ describe('Test server plugins API validators', function () { path: path + 'toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePutBodyRequest({ @@ -387,7 +398,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-TOTO/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -397,7 +408,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -407,7 +418,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -422,7 +433,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -434,7 +445,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -446,7 +457,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'toto' }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } @@ -456,16 +467,18 @@ describe('Test server plugins API validators', function () { 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) {