From 5f8bd4cbb178290da7d8f81e996f19f0eccc8e4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:02:46 +0200 Subject: Introduce blocklist command --- server/tests/api/moderation/abuses.ts | 14 ++- .../tests/api/moderation/blocklist-notification.ts | 41 ++++----- server/tests/api/moderation/blocklist.ts | 100 ++++++++------------- 3 files changed, 59 insertions(+), 96 deletions(-) (limited to 'server/tests/api/moderation') diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index 124833cf6..a2bd07b12 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts @@ -4,8 +4,6 @@ import 'mocha' import * as chai from 'chai' import { AbusesCommand, - addAccountToServerBlocklist, - addServerToServerBlocklist, addVideoCommentThread, cleanupTests, createUser, @@ -16,8 +14,6 @@ import { getVideoCommentThreads, getVideoIdFromUUID, getVideosList, - removeAccountFromServerBlocklist, - removeServerFromServerBlocklist, removeUser, removeVideo, ServerInfo, @@ -27,7 +23,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' +import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse, VideoComment } from '@shared/models' const expect = chai.expect @@ -225,7 +221,7 @@ describe('Test abuses', function () { const accountToBlock = 'root@' + servers[1].host { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.addToServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -235,7 +231,7 @@ describe('Test abuses', function () { } { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: accountToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) @@ -246,7 +242,7 @@ describe('Test abuses', function () { const serverToBlock = servers[1].host { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(2) @@ -256,7 +252,7 @@ describe('Test abuses', function () { } { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) + await servers[0].blocklistCommand.removeFromServerBlocklist({ server: serverToBlock }) const body = await commands[0].getAdminList() expect(body.total).to.equal(3) diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index 4fb3c95f2..99da64a2d 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,30 +2,23 @@ import 'mocha' import * as chai from 'chai' -import { getUserNotifications, markAsReadAllNotifications } from '@shared/extra-utils/users/user-notifications' -import { addUserSubscription, removeUserSubscription } from '@shared/extra-utils/users/user-subscriptions' -import { UserNotification, UserNotificationType } from '@shared/models' import { + addUserSubscription, + addVideoCommentThread, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, + getUserNotifications, + markAsReadAllNotifications, + removeUserSubscription, ServerInfo, + setAccessTokensToServers, uploadVideo, - userLogin -} from '../../../../shared/extra-utils/index' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' + userLogin, + waitJobs +} from '@shared/extra-utils' +import { UserNotification, UserNotificationType } from '@shared/models' const expect = chai.expect @@ -134,7 +127,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -147,7 +140,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeAccountFromAccountBlocklist(servers[0].url, userToken1, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) }) }) @@ -167,7 +160,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken1, server: servers[1].host }) await waitJobs(servers) }) @@ -180,7 +173,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken2, notifs) - await removeServerFromAccountBlocklist(servers[0].url, userToken1, servers[1].host) + await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) }) }) @@ -207,7 +200,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ account: 'user3@' + servers[1].host }) await waitJobs(servers) }) @@ -215,7 +208,7 @@ describe('Test blocklist', function () { await checkNotifications(servers[0].url, userToken1, []) await checkNotifications(servers[0].url, userToken2, []) - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user3@' + servers[1].host) + await servers[0].blocklistCommand.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) }) }) @@ -242,7 +235,7 @@ describe('Test blocklist', function () { it('Should block an account', async function () { this.timeout(10000) - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + await servers[0].blocklistCommand.addToServerBlocklist({ server: servers[1].host }) await waitJobs(servers) }) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 9ca6324c2..1b8860571 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts @@ -3,46 +3,27 @@ import 'mocha' import * as chai from 'chai' import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, addVideoCommentReply, addVideoCommentThread, + BlocklistCommand, cleanupTests, createUser, deleteVideoComment, doubleFollow, findCommentId, flushAndRunMultipleServers, - getAccountBlocklistByAccount, - getAccountBlocklistByServer, - getServerBlocklistByAccount, - getServerBlocklistByServer, getUserNotifications, getVideoCommentThreads, getVideosList, getVideosListWithToken, getVideoThreadComments, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist, ServerInfo, setAccessTokensToServers, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { - AccountBlock, - ServerBlock, - UserNotification, - UserNotificationType, - Video, - VideoComment, - VideoCommentThreadTree -} from '@shared/models' +import { UserNotification, UserNotificationType, Video, VideoComment, VideoCommentThreadTree } from '@shared/models' const expect = chai.expect @@ -108,6 +89,8 @@ describe('Test blocklist', function () { let userModeratorToken: string let userToken2: string + let command: BlocklistCommand + before(async function () { this.timeout(120000) @@ -167,6 +150,8 @@ describe('Test blocklist', function () { } await waitJobs(servers) + + command = servers[0].blocklistCommand }) describe('User blocklist', function () { @@ -181,7 +166,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -195,7 +180,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToMyBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -251,12 +236,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user2') @@ -265,12 +248,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedAccount.displayName).to.equal('user1') @@ -335,7 +316,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -374,7 +355,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromMyBlocklist({ account: 'user1' }) }) it('Should display its comments', function () { @@ -402,6 +383,7 @@ describe('Test blocklist', function () { }) describe('When managing server blocklist', function () { + it('Should list all videos', function () { return checkAllVideos(servers[0].url, servers[0].accessToken) }) @@ -411,7 +393,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -464,19 +446,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('root') expect(block.byAccount.name).to.equal('root') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should display its videos', function () { @@ -524,7 +504,7 @@ describe('Test blocklist', function () { }) it('Should block a remote account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.addToServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -540,7 +520,7 @@ describe('Test blocklist', function () { }) it('Should block a local account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.addToServerBlocklist({ account: 'user1' }) }) it('Should hide its videos', async function () { @@ -598,12 +578,10 @@ describe('Test blocklist', function () { it('Should list blocked accounts', async function () { { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) + const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user2') @@ -612,12 +590,10 @@ describe('Test blocklist', function () { } { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data + const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) + expect(body.total).to.equal(2) - expect(res.body.total).to.equal(2) - - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedAccount.displayName).to.equal('user1') @@ -627,7 +603,7 @@ describe('Test blocklist', function () { }) it('Should unblock the remote account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) }) it('Should display its videos', async function () { @@ -643,7 +619,7 @@ describe('Test blocklist', function () { }) it('Should unblock the local account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + await command.removeFromServerBlocklist({ account: 'user1' }) }) it('Should display its comments', async function () { @@ -686,7 +662,7 @@ describe('Test blocklist', function () { }) it('Should block a remote server', async function () { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.addToServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should hide its videos', async function () { @@ -758,19 +734,17 @@ describe('Test blocklist', function () { }) it('Should list blocked servers', async function () { - const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt') - const blocks: ServerBlock[] = res.body.data - - expect(res.body.total).to.equal(1) + const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const block = blocks[0] + const block = body.data[0] expect(block.byAccount.displayName).to.equal('peertube') expect(block.byAccount.name).to.equal('peertube') expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) }) it('Should unblock the remote server', async function () { - await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) }) it('Should list all videos', async function () { -- cgit v1.2.3