X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fplugins%2Ffilter-hooks.ts;h=4d354b68e64be5deb8155a865916985866e51f2c;hb=b488ba1e26b803ac6c637e8b11bdd444ca4c803f;hp=ec0679b04f3d1d8f607ea89610d4fa7f85e6e659;hpb=6691c52280363fc42f7865230ebb3741f02fff23;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index ec0679b04..4d354b68e 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -1,38 +1,32 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { - cleanupTests, - flushAndRunMultipleServers, - flushAndRunServer, killallServers, reRunServer, - ServerInfo, - waitUntilLog -} from '../../../shared/extra-utils/server/servers' +import * as chai from 'chai' +import { ServerConfig } from '@shared/models' import { addVideoCommentReply, addVideoCommentThread, - deleteVideoComment, + doubleFollow, + getConfig, getPluginTestPath, - getVideosList, - installPlugin, - removeVideo, - setAccessTokensToServers, - updateVideo, - uploadVideo, - viewVideo, - getVideosListPagination, getVideo, getVideoCommentThreads, + getVideosList, + getVideosListPagination, getVideoThreadComments, getVideoWithToken, + installPlugin, + registerUser, + setAccessTokensToServers, setDefaultVideoChannel, - waitJobs, - doubleFollow + updateVideo, + uploadVideo, + waitJobs } from '../../../shared/extra-utils' +import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' +import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' +import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' -import { VideoDetails } from '../../../shared/models/videos' -import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports' const expect = chai.expect @@ -93,6 +87,84 @@ describe('Test plugin filter hooks', function () { await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) }) + it('Should run filter:api.video.pre-import-url.accept.result', async function () { + const baseAttributes = { + name: 'normal title', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + targetUrl: getGoodVideoUrl() + 'bad' + } + await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) + }) + + it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { + const baseAttributes = { + name: 'bad torrent', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + torrentfile: 'video-720p.torrent' as any + } + await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) + }) + + it('Should run filter:api.video.post-import-url.accept.result', async function () { + this.timeout(60000) + + let videoImportId: number + + { + const baseAttributes = { + name: 'title with bad word', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + targetUrl: getGoodVideoUrl() + } + const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) + videoImportId = res.body.id + } + + await waitJobs(servers) + + { + const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) + const videoImports = res.body.data as VideoImport[] + + const videoImport = videoImports.find(i => i.id === videoImportId) + + expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) + expect(videoImport.state.label).to.equal('Rejected') + } + }) + + it('Should run filter:api.video.post-import-torrent.accept.result', async function () { + this.timeout(60000) + + let videoImportId: number + + { + const baseAttributes = { + name: 'title with bad word', + privacy: VideoPrivacy.PUBLIC, + channelId: servers[0].videoChannel.id, + torrentfile: 'video-720p.torrent' as any + } + const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) + videoImportId = res.body.id + } + + await waitJobs(servers) + + { + const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) + const videoImports = res.body.data as VideoImport[] + + const videoImport = videoImports.find(i => i.id === videoImportId) + + expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) + expect(videoImport.state.label).to.equal('Rejected') + } + }) + it('Should run filter:api.video-thread.create.accept.result', async function () { await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403) }) @@ -139,14 +211,16 @@ describe('Test plugin filter hooks', function () { } it('Should blacklist on upload', async function () { - const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video please blacklist me' }) + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) await checkIsBlacklisted(res, true) }) it('Should blacklist on import', async function () { + this.timeout(15000) + const attributes = { name: 'video please blacklist me', - targetUrl: getYoutubeVideoUrl(), + targetUrl: getGoodVideoUrl(), channelId: servers[0].videoChannel.id } const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) @@ -154,18 +228,18 @@ describe('Test plugin filter hooks', function () { }) it('Should blacklist on update', async function () { - const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video' }) + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) const videoId = res.body.video.uuid await checkIsBlacklisted(res, false) - await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, { name: 'please blacklist me' }) + await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) await checkIsBlacklisted(res, true) }) it('Should blacklist on remote upload', async function () { this.timeout(45000) - const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'remote please blacklist me' }) + const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) await waitJobs(servers) await checkIsBlacklisted(res, true) @@ -174,7 +248,7 @@ describe('Test plugin filter hooks', function () { it('Should blacklist on remote update', async function () { this.timeout(45000) - const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video' }) + const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) await waitJobs(servers) const videoId = res.body.video.uuid @@ -187,6 +261,24 @@ describe('Test plugin filter hooks', function () { }) }) + describe('Should run filter:api.user.signup.allowed.result', function () { + + it('Should run on config endpoint', async function () { + const res = await getConfig(servers[0].url) + expect((res.body as ServerConfig).signup.allowed).to.be.true + }) + + it('Should allow a signup', async function () { + await registerUser(servers[0].url, 'john', 'password') + }) + + it('Should not allow a signup', async function () { + const res = await registerUser(servers[0].url, 'jma', 'password', 403) + + expect(res.body.error).to.equal('No jma') + }) + }) + after(async function () { await cleanupTests(servers) })