From 4f32032fed8587ea97d45e235b167e8958efd81f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 7 Jul 2020 14:34:16 +0200 Subject: Add migrations --- .../tests/api/check-params/user-notifications.ts | 2 +- server/tests/api/ci-4.sh | 1 + server/tests/api/index.ts | 1 + server/tests/api/moderation/abuses.ts | 384 ++++++++++ server/tests/api/moderation/blocklist.ts | 828 +++++++++++++++++++++ server/tests/api/moderation/index.ts | 2 + .../api/notifications/moderation-notifications.ts | 14 +- server/tests/api/server/email.ts | 12 +- server/tests/api/users/blocklist.ts | 828 --------------------- server/tests/api/users/index.ts | 3 +- server/tests/api/users/users.ts | 40 +- server/tests/api/videos/video-abuse.ts | 12 +- 12 files changed, 1260 insertions(+), 867 deletions(-) create mode 100644 server/tests/api/moderation/abuses.ts create mode 100644 server/tests/api/moderation/blocklist.ts create mode 100644 server/tests/api/moderation/index.ts delete mode 100644 server/tests/api/users/blocklist.ts (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 2048fa667..883b1d29c 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -164,7 +164,7 @@ describe('Test user notifications API validators', function () { const correctFields: UserNotificationSetting = { newVideoFromSubscription: UserNotificationSettingValue.WEB, newCommentOnMyVideo: UserNotificationSettingValue.WEB, - videoAbuseAsModerator: UserNotificationSettingValue.WEB, + abuseAsModerator: UserNotificationSettingValue.WEB, videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB, blacklistOnMyVideo: UserNotificationSettingValue.WEB, myVideoImportFinished: UserNotificationSettingValue.WEB, diff --git a/server/tests/api/ci-4.sh b/server/tests/api/ci-4.sh index 14a014f07..4998de364 100644 --- a/server/tests/api/ci-4.sh +++ b/server/tests/api/ci-4.sh @@ -2,6 +2,7 @@ set -eu +activitypubFiles=$(find server/tests/api/moderation -type f | grep -v index.ts | xargs echo) redundancyFiles=$(find server/tests/api/redundancy -type f | grep -v index.ts | xargs echo) activitypubFiles=$(find server/tests/api/activitypub -type f | grep -v index.ts | xargs echo) diff --git a/server/tests/api/index.ts b/server/tests/api/index.ts index bac77ab2e..b62e2f5f7 100644 --- a/server/tests/api/index.ts +++ b/server/tests/api/index.ts @@ -1,6 +1,7 @@ // Order of the tests we want to execute import './activitypub' import './check-params' +import './moderation' import './notifications' import './redundancy' import './search' diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts new file mode 100644 index 000000000..28c5a5531 --- /dev/null +++ b/server/tests/api/moderation/abuses.ts @@ -0,0 +1,384 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import 'mocha' +import * as chai from 'chai' +import { Abuse, AbusePredefinedReasonsString, AbuseState } from '@shared/models' +import { + cleanupTests, + createUser, + deleteVideoAbuse, + flushAndRunMultipleServers, + getVideoAbusesList, + getVideosList, + removeVideo, + reportVideoAbuse, + ServerInfo, + setAccessTokensToServers, + updateVideoAbuse, + uploadVideo, + userLogin +} from '../../../../shared/extra-utils/index' +import { doubleFollow } from '../../../../shared/extra-utils/server/follows' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { + addAccountToServerBlocklist, + addServerToServerBlocklist, + removeAccountFromServerBlocklist, + removeServerFromServerBlocklist +} from '../../../../shared/extra-utils/users/blocklist' + +const expect = chai.expect + +describe('Test abuses', function () { + let servers: ServerInfo[] = [] + let abuseServer2: Abuse + + before(async function () { + this.timeout(50000) + + // Run servers + servers = await flushAndRunMultipleServers(2) + + // Get the access tokens + await setAccessTokensToServers(servers) + + // Server 1 and server 2 follow each other + await doubleFollow(servers[0], servers[1]) + + // Upload some videos on each servers + const video1Attributes = { + name: 'my super name for server 1', + description: 'my super description for server 1' + } + await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) + + const video2Attributes = { + name: 'my super name for server 2', + description: 'my super description for server 2' + } + await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) + + // Wait videos propagation, server 2 has transcoding enabled + await waitJobs(servers) + + const res = await getVideosList(servers[0].url) + const videos = res.body.data + + expect(videos.length).to.equal(2) + + servers[0].video = videos.find(video => video.name === 'my super name for server 1') + servers[1].video = videos.find(video => video.name === 'my super name for server 2') + }) + + it('Should not have video abuses', async function () { + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + }) + + it('Should report abuse on a local video', async function () { + this.timeout(15000) + + const reason = 'my super bad reason' + await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) + + // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 + await waitJobs(servers) + }) + + it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { + const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + + expect(res1.body.total).to.equal(1) + expect(res1.body.data).to.be.an('array') + expect(res1.body.data.length).to.equal(1) + + const abuse: Abuse = res1.body.data[0] + expect(abuse.reason).to.equal('my super bad reason') + expect(abuse.reporterAccount.name).to.equal('root') + expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) + expect(abuse.video.id).to.equal(servers[0].video.id) + expect(abuse.video.channel).to.exist + expect(abuse.count).to.equal(1) + expect(abuse.nth).to.equal(1) + expect(abuse.countReportsForReporter).to.equal(1) + expect(abuse.countReportsForReportee).to.equal(1) + + const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res2.body.total).to.equal(0) + expect(res2.body.data).to.be.an('array') + expect(res2.body.data.length).to.equal(0) + }) + + it('Should report abuse on a remote video', async function () { + this.timeout(10000) + + const reason = 'my super bad reason 2' + await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) + + // We wait requests propagation + await waitJobs(servers) + }) + + it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { + const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res1.body.total).to.equal(2) + expect(res1.body.data).to.be.an('array') + expect(res1.body.data.length).to.equal(2) + + const abuse1: Abuse = res1.body.data[0] + expect(abuse1.reason).to.equal('my super bad reason') + expect(abuse1.reporterAccount.name).to.equal('root') + expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) + expect(abuse1.video.id).to.equal(servers[0].video.id) + expect(abuse1.state.id).to.equal(AbuseState.PENDING) + expect(abuse1.state.label).to.equal('Pending') + expect(abuse1.moderationComment).to.be.null + expect(abuse1.count).to.equal(1) + expect(abuse1.nth).to.equal(1) + + const abuse2: Abuse = res1.body.data[1] + expect(abuse2.reason).to.equal('my super bad reason 2') + expect(abuse2.reporterAccount.name).to.equal('root') + expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) + expect(abuse2.video.id).to.equal(servers[1].video.id) + expect(abuse2.state.id).to.equal(AbuseState.PENDING) + expect(abuse2.state.label).to.equal('Pending') + expect(abuse2.moderationComment).to.be.null + + const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res2.body.total).to.equal(1) + expect(res2.body.data).to.be.an('array') + expect(res2.body.data.length).to.equal(1) + + abuseServer2 = res2.body.data[0] + expect(abuseServer2.reason).to.equal('my super bad reason 2') + expect(abuseServer2.reporterAccount.name).to.equal('root') + expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) + expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) + expect(abuseServer2.state.label).to.equal('Pending') + expect(abuseServer2.moderationComment).to.be.null + }) + + it('Should update the state of a video abuse', async function () { + const body = { state: AbuseState.REJECTED } + await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) + + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) + }) + + it('Should add a moderation comment', async function () { + const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } + await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) + + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) + expect(res.body.data[0].moderationComment).to.equal('It is valid') + }) + + it('Should hide video abuses from blocked accounts', async function () { + this.timeout(10000) + + { + await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') + await waitJobs(servers) + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(3) + } + + const accountToBlock = 'root@localhost:' + servers[1].port + + { + await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(2) + + const abuse = res.body.data.find(a => a.reason === 'will mute this') + expect(abuse).to.be.undefined + } + + { + await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(3) + } + }) + + it('Should hide video abuses from blocked servers', async function () { + const serverToBlock = servers[1].host + + { + await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(2) + + const abuse = res.body.data.find(a => a.reason === 'will mute this') + expect(abuse).to.be.undefined + } + + { + await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(3) + } + }) + + it('Should keep the video abuse when deleting the video', async function () { + this.timeout(10000) + + await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) + + await waitJobs(servers) + + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res.body.total).to.equal(2, "wrong number of videos returned") + expect(res.body.data.length).to.equal(2, "wrong number of videos returned") + expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video") + + const abuse: Abuse = res.body.data[0] + expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") + expect(abuse.video.channel).to.exist + expect(abuse.video.deleted).to.be.true + }) + + it('Should include counts of reports from reporter and reportee', async function () { + this.timeout(10000) + + // register a second user to have two reporters/reportees + const user = { username: 'user2', password: 'password' } + await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) + const userAccessToken = await userLogin(servers[0], user) + + // upload a third video via this user + const video3Attributes = { + name: 'my second super name for server 1', + description: 'my second super description for server 1' + } + await uploadVideo(servers[0].url, userAccessToken, video3Attributes) + + const res1 = await getVideosList(servers[0].url) + const videos = res1.body.data + const video3 = videos.find(video => video.name === 'my second super name for server 1') + + // resume with the test + const reason3 = 'my super bad reason 3' + await reportVideoAbuse(servers[0].url, servers[0].accessToken, video3.id, reason3) + const reason4 = 'my super bad reason 4' + await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4) + + const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + + { + for (const abuse of res2.body.data as Abuse[]) { + if (abuse.video.id === video3.id) { + expect(abuse.count).to.equal(1, "wrong reports count for video 3") + expect(abuse.nth).to.equal(1, "wrong report position in report list for video 3") + expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") + expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") + } + if (abuse.video.id === servers[0].video.id) { + expect(abuse.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") + } + } + } + }) + + it('Should list predefined reasons as well as timestamps for the reported video', async function () { + this.timeout(10000) + + const reason5 = 'my super bad reason 5' + const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] + const createdAbuse = (await reportVideoAbuse( + servers[0].url, + servers[0].accessToken, + servers[0].video.id, + reason5, + predefinedReasons5, + 1, + 5 + )).body.abuse + + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + + { + const abuse = (res.body.data as Abuse[]).find(a => a.id === createdAbuse.id) + expect(abuse.reason).to.equals(reason5) + expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") + expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") + expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported") + } + }) + + it('Should delete the video abuse', async function () { + this.timeout(10000) + + await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) + + await waitJobs(servers) + + { + const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) + expect(res.body.total).to.equal(1) + expect(res.body.data.length).to.equal(1) + expect(res.body.data[0].id).to.not.equal(abuseServer2.id) + } + + { + const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) + expect(res.body.total).to.equal(6) + } + }) + + it('Should list and filter video abuses', async function () { + async function list (query: Omit[0], 'url' | 'token'>) { + const options = { + url: servers[0].url, + token: servers[0].accessToken + } + + Object.assign(options, query) + + const res = await getVideoAbusesList(options) + + return res.body.data as Abuse[] + } + + expect(await list({ id: 56 })).to.have.lengthOf(0) + expect(await list({ id: 1 })).to.have.lengthOf(1) + + expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4) + expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) + + expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) + + expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4) + expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) + + expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) + expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5) + + expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5) + expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) + + expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) + expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) + + expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0) + expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6) + + expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1) + expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0) + }) + + after(async function () { + await cleanupTests(servers) + }) +}) diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts new file mode 100644 index 000000000..8c9107a50 --- /dev/null +++ b/server/tests/api/moderation/blocklist.ts @@ -0,0 +1,828 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import * as chai from 'chai' +import 'mocha' +import { AccountBlock, ServerBlock, Video, UserNotification, UserNotificationType } from '../../../../shared/index' +import { + cleanupTests, + createUser, + deleteVideoComment, + doubleFollow, + flushAndRunMultipleServers, + ServerInfo, + uploadVideo, + userLogin, + follow, + unfollow +} from '../../../../shared/extra-utils/index' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' +import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos' +import { + addVideoCommentReply, + addVideoCommentThread, + getVideoCommentThreads, + getVideoThreadComments, + findCommentId +} from '../../../../shared/extra-utils/videos/video-comments' +import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' +import { + addAccountToAccountBlocklist, + addAccountToServerBlocklist, + addServerToAccountBlocklist, + addServerToServerBlocklist, + getAccountBlocklistByAccount, + getAccountBlocklistByServer, + getServerBlocklistByAccount, + getServerBlocklistByServer, + removeAccountFromAccountBlocklist, + removeAccountFromServerBlocklist, + removeServerFromAccountBlocklist, + removeServerFromServerBlocklist +} from '../../../../shared/extra-utils/users/blocklist' +import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications' + +const expect = chai.expect + +async function checkAllVideos (url: string, token: string) { + { + const res = await getVideosListWithToken(url, token) + + expect(res.body.data).to.have.lengthOf(5) + } + + { + const res = await getVideosList(url) + + expect(res.body.data).to.have.lengthOf(5) + } +} + +async function checkAllComments (url: string, token: string, videoUUID: string) { + const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) + + const allThreads: VideoComment[] = resThreads.body.data + const threads = allThreads.filter(t => t.isDeleted === false) + expect(threads).to.have.lengthOf(2) + + for (const thread of threads) { + const res = await getVideoThreadComments(url, videoUUID, thread.id, token) + + const tree: VideoCommentThreadTree = res.body + expect(tree.children).to.have.lengthOf(1) + } +} + +async function checkCommentNotification ( + mainServer: ServerInfo, + comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, + check: 'presence' | 'absence' +) { + const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) + const created = resComment.body.comment as VideoComment + const threadId = created.id + const createdAt = created.createdAt + + await waitJobs([ mainServer, comment.server ]) + + const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) + const commentNotifications = (res.body.data as UserNotification[]) + .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) + + if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) + else expect(commentNotifications).to.have.lengthOf(0) + + await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) + + await waitJobs([ mainServer, comment.server ]) +} + +describe('Test blocklist', function () { + let servers: ServerInfo[] + let videoUUID1: string + let videoUUID2: string + let videoUUID3: string + let userToken1: string + let userModeratorToken: string + let userToken2: string + + before(async function () { + this.timeout(60000) + + servers = await flushAndRunMultipleServers(3) + await setAccessTokensToServers(servers) + + { + const user = { username: 'user1', password: 'password' } + await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + + userToken1 = await userLogin(servers[0], user) + await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) + } + + { + const user = { username: 'moderator', password: 'password' } + await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) + + userModeratorToken = await userLogin(servers[0], user) + } + + { + const user = { username: 'user2', password: 'password' } + await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) + + userToken2 = await userLogin(servers[1], user) + await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) + } + + { + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) + videoUUID1 = res.body.video.uuid + } + + { + const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) + videoUUID2 = res.body.video.uuid + } + + { + const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) + videoUUID3 = res.body.video.uuid + } + + await doubleFollow(servers[0], servers[1]) + await doubleFollow(servers[0], servers[2]) + + { + const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') + const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') + await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') + } + + { + const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') + await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') + } + + await waitJobs(servers) + }) + + describe('User blocklist', function () { + + describe('When managing account blocklist', function () { + it('Should list all videos', function () { + return checkAllVideos(servers[0].url, servers[0].accessToken) + }) + + it('Should list the comments', function () { + return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + }) + + it('Should block a remote account', async function () { + await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + }) + + it('Should hide its videos', async function () { + const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(4) + + const v = videos.find(v => v.name === 'video user 2') + expect(v).to.be.undefined + }) + + it('Should block a local account', async function () { + await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + }) + + it('Should hide its videos', async function () { + const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(3) + + const v = videos.find(v => v.name === 'video user 1') + expect(v).to.be.undefined + }) + + it('Should hide its comments', async function () { + const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) + + const threads: VideoComment[] = resThreads.body.data + expect(threads).to.have.lengthOf(1) + expect(threads[0].totalReplies).to.equal(0) + + const t = threads.find(t => t.text === 'comment user 1') + expect(t).to.be.undefined + + for (const thread of threads) { + const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) + + const tree: VideoCommentThreadTree = res.body + expect(tree.children).to.have.lengthOf(0) + } + }) + + it('Should not have notifications from blocked accounts', async function () { + this.timeout(20000) + + { + const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } + await checkCommentNotification(servers[0], comment, 'absence') + } + + { + const comment = { + server: servers[0], + token: userToken1, + videoUUID: videoUUID2, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'absence') + } + }) + + it('Should list all the videos with another user', async function () { + return checkAllVideos(servers[0].url, userToken1) + }) + + 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 + + expect(res.body.total).to.equal(2) + + const block = blocks[0] + expect(block.byAccount.displayName).to.equal('root') + expect(block.byAccount.name).to.equal('root') + expect(block.blockedAccount.displayName).to.equal('user2') + expect(block.blockedAccount.name).to.equal('user2') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) + } + + { + 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 block = blocks[0] + expect(block.byAccount.displayName).to.equal('root') + expect(block.byAccount.name).to.equal('root') + expect(block.blockedAccount.displayName).to.equal('user1') + expect(block.blockedAccount.name).to.equal('user1') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) + } + }) + + it('Should not allow a remote blocked user to comment my videos', async function () { + this.timeout(60000) + + { + await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') + await waitJobs(servers) + + await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') + await waitJobs(servers) + + const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') + const message = 'reply by user 2' + const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) + await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') + + await waitJobs(servers) + } + + // Server 2 has all the comments + { + const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') + const threads: VideoComment[] = resThreads.body.data + + expect(threads).to.have.lengthOf(2) + expect(threads[0].text).to.equal('uploader') + expect(threads[1].text).to.equal('comment user 2') + + const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) + + const tree: VideoCommentThreadTree = resReplies.body + expect(tree.children).to.have.lengthOf(1) + expect(tree.children[0].comment.text).to.equal('reply by user 2') + expect(tree.children[0].children).to.have.lengthOf(1) + expect(tree.children[0].children[0].comment.text).to.equal('another reply') + } + + // Server 1 and 3 should only have uploader comments + for (const server of [ servers[0], servers[2] ]) { + const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') + const threads: VideoComment[] = resThreads.body.data + + expect(threads).to.have.lengthOf(1) + expect(threads[0].text).to.equal('uploader') + + const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + + const tree: VideoCommentThreadTree = resReplies.body + if (server.serverNumber === 1) { + expect(tree.children).to.have.lengthOf(0) + } else { + expect(tree.children).to.have.lengthOf(1) + } + } + }) + + it('Should unblock the remote account', async function () { + await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + }) + + it('Should display its videos', async function () { + const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(4) + + const v = videos.find(v => v.name === 'video user 2') + expect(v).not.to.be.undefined + }) + + it('Should display its comments on my video', async function () { + for (const server of servers) { + const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') + const threads: VideoComment[] = resThreads.body.data + + // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment + if (server.serverNumber === 3) { + expect(threads).to.have.lengthOf(1) + continue + } + + expect(threads).to.have.lengthOf(2) + expect(threads[0].text).to.equal('uploader') + expect(threads[1].text).to.equal('comment user 2') + + const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) + + const tree: VideoCommentThreadTree = resReplies.body + expect(tree.children).to.have.lengthOf(1) + expect(tree.children[0].comment.text).to.equal('reply by user 2') + expect(tree.children[0].children).to.have.lengthOf(1) + expect(tree.children[0].children[0].comment.text).to.equal('another reply') + } + }) + + it('Should unblock the local account', async function () { + await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') + }) + + it('Should display its comments', function () { + return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + }) + + it('Should have a notification from a non blocked account', async function () { + this.timeout(20000) + + { + const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } + await checkCommentNotification(servers[0], comment, 'presence') + } + + { + const comment = { + server: servers[0], + token: userToken1, + videoUUID: videoUUID2, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'presence') + } + }) + }) + + describe('When managing server blocklist', function () { + it('Should list all videos', function () { + return checkAllVideos(servers[0].url, servers[0].accessToken) + }) + + it('Should list the comments', function () { + return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + }) + + it('Should block a remote server', async function () { + await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + }) + + it('Should hide its videos', async function () { + const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(3) + + const v1 = videos.find(v => v.name === 'video user 2') + const v2 = videos.find(v => v.name === 'video server 2') + + expect(v1).to.be.undefined + expect(v2).to.be.undefined + }) + + it('Should list all the videos with another user', async function () { + return checkAllVideos(servers[0].url, userToken1) + }) + + it('Should hide its comments', async function () { + this.timeout(10000) + + const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') + const threadId = resThreads.body.comment.id + + await waitJobs(servers) + + await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + + await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + }) + + it('Should not have notifications from blocked server', async function () { + this.timeout(20000) + + { + const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } + await checkCommentNotification(servers[0], comment, 'absence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'absence') + } + }) + + 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 block = blocks[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) + }) + + it('Should display its videos', function () { + return checkAllVideos(servers[0].url, servers[0].accessToken) + }) + + it('Should display its comments', function () { + return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + }) + + it('Should have notification from unblocked server', async function () { + this.timeout(20000) + + { + const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } + await checkCommentNotification(servers[0], comment, 'presence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'presence') + } + }) + }) + }) + + describe('Server blocklist', function () { + + describe('When managing account blocklist', function () { + it('Should list all videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllVideos(servers[0].url, token) + } + }) + + it('Should list the comments', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllComments(servers[0].url, token, videoUUID1) + } + }) + + it('Should block a remote account', async function () { + await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + }) + + it('Should hide its videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + const res = await getVideosListWithToken(servers[0].url, token) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(4) + + const v = videos.find(v => v.name === 'video user 2') + expect(v).to.be.undefined + } + }) + + it('Should block a local account', async function () { + await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + }) + + it('Should hide its videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + const res = await getVideosListWithToken(servers[0].url, token) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(3) + + const v = videos.find(v => v.name === 'video user 1') + expect(v).to.be.undefined + } + }) + + it('Should hide its comments', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) + + let threads: VideoComment[] = resThreads.body.data + threads = threads.filter(t => t.isDeleted === false) + + expect(threads).to.have.lengthOf(1) + expect(threads[0].totalReplies).to.equal(0) + + const t = threads.find(t => t.text === 'comment user 1') + expect(t).to.be.undefined + + for (const thread of threads) { + const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) + + const tree: VideoCommentThreadTree = res.body + expect(tree.children).to.have.lengthOf(0) + } + } + }) + + it('Should not have notification from blocked accounts by instance', async function () { + this.timeout(20000) + + { + const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } + await checkCommentNotification(servers[0], comment, 'absence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'absence') + } + }) + + 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 block = blocks[0] + expect(block.byAccount.displayName).to.equal('peertube') + expect(block.byAccount.name).to.equal('peertube') + expect(block.blockedAccount.displayName).to.equal('user2') + expect(block.blockedAccount.name).to.equal('user2') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) + } + + { + const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') + const blocks: AccountBlock[] = res.body.data + + expect(res.body.total).to.equal(2) + + const block = blocks[0] + expect(block.byAccount.displayName).to.equal('peertube') + expect(block.byAccount.name).to.equal('peertube') + expect(block.blockedAccount.displayName).to.equal('user1') + expect(block.blockedAccount.name).to.equal('user1') + expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) + } + }) + + it('Should unblock the remote account', async function () { + await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) + }) + + it('Should display its videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + const res = await getVideosListWithToken(servers[0].url, token) + + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(4) + + const v = videos.find(v => v.name === 'video user 2') + expect(v).not.to.be.undefined + } + }) + + it('Should unblock the local account', async function () { + await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') + }) + + it('Should display its comments', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllComments(servers[0].url, token, videoUUID1) + } + }) + + it('Should have notifications from unblocked accounts', async function () { + this.timeout(20000) + + { + const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' } + await checkCommentNotification(servers[0], comment, 'presence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'presence') + } + }) + }) + + describe('When managing server blocklist', function () { + it('Should list all videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllVideos(servers[0].url, token) + } + }) + + it('Should list the comments', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllComments(servers[0].url, token, videoUUID1) + } + }) + + it('Should block a remote server', async function () { + await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + }) + + it('Should hide its videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + const res1 = await getVideosList(servers[0].url) + const res2 = await getVideosListWithToken(servers[0].url, token) + + for (const res of [ res1, res2 ]) { + const videos: Video[] = res.body.data + expect(videos).to.have.lengthOf(3) + + const v1 = videos.find(v => v.name === 'video user 2') + const v2 = videos.find(v => v.name === 'video server 2') + + expect(v1).to.be.undefined + expect(v2).to.be.undefined + } + } + }) + + it('Should hide its comments', async function () { + this.timeout(10000) + + const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') + const threadId = resThreads.body.comment.id + + await waitJobs(servers) + + await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) + + await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) + }) + + it('Should not have notification from blocked instances by instance', async function () { + this.timeout(50000) + + { + const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } + await checkCommentNotification(servers[0], comment, 'absence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'absence') + } + + { + const now = new Date() + await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await waitJobs(servers) + await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) + + await waitJobs(servers) + + const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) + const commentNotifications = (res.body.data as UserNotification[]) + .filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && + n.createdAt >= now.toISOString() + }) + + expect(commentNotifications).to.have.lengthOf(0) + } + }) + + 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 block = blocks[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) + }) + + it('Should list all videos', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllVideos(servers[0].url, token) + } + }) + + it('Should list the comments', async function () { + for (const token of [ userModeratorToken, servers[0].accessToken ]) { + await checkAllComments(servers[0].url, token, videoUUID1) + } + }) + + it('Should have notification from unblocked instances', async function () { + this.timeout(50000) + + { + const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } + await checkCommentNotification(servers[0], comment, 'presence') + } + + { + const comment = { + server: servers[1], + token: userToken2, + videoUUID: videoUUID1, + text: 'hello @root@localhost:' + servers[0].port + } + await checkCommentNotification(servers[0], comment, 'presence') + } + + { + const now = new Date() + await unfollow(servers[1].url, servers[1].accessToken, servers[0]) + await waitJobs(servers) + await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) + + await waitJobs(servers) + + const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) + const commentNotifications = (res.body.data as UserNotification[]) + .filter(n => { + return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && + n.createdAt >= now.toISOString() + }) + + expect(commentNotifications).to.have.lengthOf(1) + } + }) + }) + }) + + after(async function () { + await cleanupTests(servers) + }) +}) diff --git a/server/tests/api/moderation/index.ts b/server/tests/api/moderation/index.ts new file mode 100644 index 000000000..cb018d88e --- /dev/null +++ b/server/tests/api/moderation/index.ts @@ -0,0 +1,2 @@ +export * from './abuses' +export * from './blocklist' diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index b90732a7a..a27681603 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -11,7 +11,7 @@ import { MockInstancesIndex, registerUser, removeVideoFromBlacklist, - reportVideoAbuse, + reportAbuse, unfollow, updateCustomConfig, updateCustomSubConfig, @@ -74,12 +74,12 @@ describe('Test moderation notifications', function () { const name = 'video for abuse ' + uuidv4() const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const video = resVideo.body.video - await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') + await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') + await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') }) it('Should send a notification to moderators on remote video abuse', async function () { @@ -87,14 +87,14 @@ describe('Test moderation notifications', function () { const name = 'video for abuse ' + uuidv4() const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) - const uuid = resVideo.body.video.uuid + const video = resVideo.body.video await waitJobs(servers) - await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') + await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId: video.id, reason: 'super reason' }) await waitJobs(servers) - await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') + await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') }) }) diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 95b64a459..9c3299618 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { addVideoToBlacklist, askResetPassword, @@ -11,7 +11,7 @@ import { createUser, flushAndRunServer, removeVideoFromBlacklist, - reportVideoAbuse, + reportAbuse, resetPassword, ServerInfo, setAccessTokensToServers, @@ -30,10 +30,15 @@ describe('Test emails', function () { let userId: number let userId2: number let userAccessToken: string + let videoUUID: string + let videoId: number + let videoUserUUID: string + let verificationString: string let verificationString2: string + const emails: object[] = [] const user = { username: 'user_1', @@ -76,6 +81,7 @@ describe('Test emails', function () { } const res = await uploadVideo(server.url, server.accessToken, attributes) videoUUID = res.body.video.uuid + videoId = res.body.video.id } }) @@ -179,7 +185,7 @@ describe('Test emails', function () { this.timeout(10000) const reason = 'my super bad reason' - await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason) + await reportAbuse({ url: server.url, token: server.accessToken, videoId, reason }) await waitJobs(server) expect(emails).to.have.lengthOf(3) diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts deleted file mode 100644 index 8c9107a50..000000000 --- a/server/tests/api/users/blocklist.ts +++ /dev/null @@ -1,828 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import * as chai from 'chai' -import 'mocha' -import { AccountBlock, ServerBlock, Video, UserNotification, UserNotificationType } from '../../../../shared/index' -import { - cleanupTests, - createUser, - deleteVideoComment, - doubleFollow, - flushAndRunMultipleServers, - ServerInfo, - uploadVideo, - userLogin, - follow, - unfollow -} from '../../../../shared/extra-utils/index' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos' -import { - addVideoCommentReply, - addVideoCommentThread, - getVideoCommentThreads, - getVideoThreadComments, - findCommentId -} from '../../../../shared/extra-utils/videos/video-comments' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' -import { - addAccountToAccountBlocklist, - addAccountToServerBlocklist, - addServerToAccountBlocklist, - addServerToServerBlocklist, - getAccountBlocklistByAccount, - getAccountBlocklistByServer, - getServerBlocklistByAccount, - getServerBlocklistByServer, - removeAccountFromAccountBlocklist, - removeAccountFromServerBlocklist, - removeServerFromAccountBlocklist, - removeServerFromServerBlocklist -} from '../../../../shared/extra-utils/users/blocklist' -import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications' - -const expect = chai.expect - -async function checkAllVideos (url: string, token: string) { - { - const res = await getVideosListWithToken(url, token) - - expect(res.body.data).to.have.lengthOf(5) - } - - { - const res = await getVideosList(url) - - expect(res.body.data).to.have.lengthOf(5) - } -} - -async function checkAllComments (url: string, token: string, videoUUID: string) { - const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token) - - const allThreads: VideoComment[] = resThreads.body.data - const threads = allThreads.filter(t => t.isDeleted === false) - expect(threads).to.have.lengthOf(2) - - for (const thread of threads) { - const res = await getVideoThreadComments(url, videoUUID, thread.id, token) - - const tree: VideoCommentThreadTree = res.body - expect(tree.children).to.have.lengthOf(1) - } -} - -async function checkCommentNotification ( - mainServer: ServerInfo, - comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, - check: 'presence' | 'absence' -) { - const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text) - const created = resComment.body.comment as VideoComment - const threadId = created.id - const createdAt = created.createdAt - - await waitJobs([ mainServer, comment.server ]) - - const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) - - if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) - else expect(commentNotifications).to.have.lengthOf(0) - - await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId) - - await waitJobs([ mainServer, comment.server ]) -} - -describe('Test blocklist', function () { - let servers: ServerInfo[] - let videoUUID1: string - let videoUUID2: string - let videoUUID3: string - let userToken1: string - let userModeratorToken: string - let userToken2: string - - before(async function () { - this.timeout(60000) - - servers = await flushAndRunMultipleServers(3) - await setAccessTokensToServers(servers) - - { - const user = { username: 'user1', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - - userToken1 = await userLogin(servers[0], user) - await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) - } - - { - const user = { username: 'moderator', password: 'password' } - await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) - - userModeratorToken = await userLogin(servers[0], user) - } - - { - const user = { username: 'user2', password: 'password' } - await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) - - userToken2 = await userLogin(servers[1], user) - await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) - } - - { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) - videoUUID1 = res.body.video.uuid - } - - { - const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) - videoUUID2 = res.body.video.uuid - } - - { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) - videoUUID3 = res.body.video.uuid - } - - await doubleFollow(servers[0], servers[1]) - await doubleFollow(servers[0], servers[2]) - - { - const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1') - const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') - } - - { - const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1') - await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') - } - - await waitJobs(servers) - }) - - describe('User blocklist', function () { - - describe('When managing account blocklist', function () { - it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) - }) - - it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - }) - - it('Should block a remote account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) - }) - - it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') - expect(v).to.be.undefined - }) - - it('Should block a local account', async function () { - await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') - }) - - it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) - - const v = videos.find(v => v.name === 'video user 1') - expect(v).to.be.undefined - }) - - it('Should hide its comments', async function () { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken) - - const threads: VideoComment[] = resThreads.body.data - expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(0) - - const t = threads.find(t => t.text === 'comment user 1') - expect(t).to.be.undefined - - for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) - - const tree: VideoCommentThreadTree = res.body - expect(tree.children).to.have.lengthOf(0) - } - }) - - it('Should not have notifications from blocked accounts', async function () { - this.timeout(20000) - - { - const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } - await checkCommentNotification(servers[0], comment, 'absence') - } - - { - const comment = { - server: servers[0], - token: userToken1, - videoUUID: videoUUID2, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'absence') - } - }) - - it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) - }) - - 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 - - expect(res.body.total).to.equal(2) - - const block = blocks[0] - expect(block.byAccount.displayName).to.equal('root') - expect(block.byAccount.name).to.equal('root') - expect(block.blockedAccount.displayName).to.equal('user2') - expect(block.blockedAccount.name).to.equal('user2') - expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) - } - - { - 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 block = blocks[0] - expect(block.byAccount.displayName).to.equal('root') - expect(block.byAccount.name).to.equal('root') - expect(block.blockedAccount.displayName).to.equal('user1') - expect(block.blockedAccount.name).to.equal('user1') - expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) - } - }) - - it('Should not allow a remote blocked user to comment my videos', async function () { - this.timeout(60000) - - { - await addVideoCommentThread(servers[1].url, userToken2, videoUUID3, 'comment user 2') - await waitJobs(servers) - - await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID3, 'uploader') - await waitJobs(servers) - - const commentId = await findCommentId(servers[1].url, videoUUID3, 'uploader') - const message = 'reply by user 2' - const resReply = await addVideoCommentReply(servers[1].url, userToken2, videoUUID3, commentId, message) - await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID3, resReply.body.comment.id, 'another reply') - - await waitJobs(servers) - } - - // Server 2 has all the comments - { - const resThreads = await getVideoCommentThreads(servers[1].url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data - - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') - - const resReplies = await getVideoThreadComments(servers[1].url, videoUUID3, threads[0].id) - - const tree: VideoCommentThreadTree = resReplies.body - expect(tree.children).to.have.lengthOf(1) - expect(tree.children[0].comment.text).to.equal('reply by user 2') - expect(tree.children[0].children).to.have.lengthOf(1) - expect(tree.children[0].children[0].comment.text).to.equal('another reply') - } - - // Server 1 and 3 should only have uploader comments - for (const server of [ servers[0], servers[2] ]) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data - - expect(threads).to.have.lengthOf(1) - expect(threads[0].text).to.equal('uploader') - - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) - - const tree: VideoCommentThreadTree = resReplies.body - if (server.serverNumber === 1) { - expect(tree.children).to.have.lengthOf(0) - } else { - expect(tree.children).to.have.lengthOf(1) - } - } - }) - - it('Should unblock the remote account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) - }) - - it('Should display its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') - expect(v).not.to.be.undefined - }) - - it('Should display its comments on my video', async function () { - for (const server of servers) { - const resThreads = await getVideoCommentThreads(server.url, videoUUID3, 0, 25, '-createdAt') - const threads: VideoComment[] = resThreads.body.data - - // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment - if (server.serverNumber === 3) { - expect(threads).to.have.lengthOf(1) - continue - } - - expect(threads).to.have.lengthOf(2) - expect(threads[0].text).to.equal('uploader') - expect(threads[1].text).to.equal('comment user 2') - - const resReplies = await getVideoThreadComments(server.url, videoUUID3, threads[0].id) - - const tree: VideoCommentThreadTree = resReplies.body - expect(tree.children).to.have.lengthOf(1) - expect(tree.children[0].comment.text).to.equal('reply by user 2') - expect(tree.children[0].children).to.have.lengthOf(1) - expect(tree.children[0].children[0].comment.text).to.equal('another reply') - } - }) - - it('Should unblock the local account', async function () { - await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') - }) - - it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - }) - - it('Should have a notification from a non blocked account', async function () { - this.timeout(20000) - - { - const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } - await checkCommentNotification(servers[0], comment, 'presence') - } - - { - const comment = { - server: servers[0], - token: userToken1, - videoUUID: videoUUID2, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'presence') - } - }) - }) - - describe('When managing server blocklist', function () { - it('Should list all videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) - }) - - it('Should list the comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - }) - - it('Should block a remote server', async function () { - await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) - }) - - it('Should hide its videos', async function () { - const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) - - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') - - expect(v1).to.be.undefined - expect(v2).to.be.undefined - }) - - it('Should list all the videos with another user', async function () { - return checkAllVideos(servers[0].url, userToken1) - }) - - it('Should hide its comments', async function () { - this.timeout(10000) - - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id - - await waitJobs(servers) - - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) - }) - - it('Should not have notifications from blocked server', async function () { - this.timeout(20000) - - { - const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } - await checkCommentNotification(servers[0], comment, 'absence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'absence') - } - }) - - 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 block = blocks[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) - }) - - it('Should display its videos', function () { - return checkAllVideos(servers[0].url, servers[0].accessToken) - }) - - it('Should display its comments', function () { - return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - }) - - it('Should have notification from unblocked server', async function () { - this.timeout(20000) - - { - const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } - await checkCommentNotification(servers[0], comment, 'presence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'presence') - } - }) - }) - }) - - describe('Server blocklist', function () { - - describe('When managing account blocklist', function () { - it('Should list all videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) - } - }) - - it('Should list the comments', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) - } - }) - - it('Should block a remote account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) - }) - - it('Should hide its videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') - expect(v).to.be.undefined - } - }) - - it('Should block a local account', async function () { - await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') - }) - - it('Should hide its videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) - - const v = videos.find(v => v.name === 'video user 1') - expect(v).to.be.undefined - } - }) - - it('Should hide its comments', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token) - - let threads: VideoComment[] = resThreads.body.data - threads = threads.filter(t => t.isDeleted === false) - - expect(threads).to.have.lengthOf(1) - expect(threads[0].totalReplies).to.equal(0) - - const t = threads.find(t => t.text === 'comment user 1') - expect(t).to.be.undefined - - for (const thread of threads) { - const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token) - - const tree: VideoCommentThreadTree = res.body - expect(tree.children).to.have.lengthOf(0) - } - } - }) - - it('Should not have notification from blocked accounts by instance', async function () { - this.timeout(20000) - - { - const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } - await checkCommentNotification(servers[0], comment, 'absence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'absence') - } - }) - - 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 block = blocks[0] - expect(block.byAccount.displayName).to.equal('peertube') - expect(block.byAccount.name).to.equal('peertube') - expect(block.blockedAccount.displayName).to.equal('user2') - expect(block.blockedAccount.name).to.equal('user2') - expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port) - } - - { - const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt') - const blocks: AccountBlock[] = res.body.data - - expect(res.body.total).to.equal(2) - - const block = blocks[0] - expect(block.byAccount.displayName).to.equal('peertube') - expect(block.byAccount.name).to.equal('peertube') - expect(block.blockedAccount.displayName).to.equal('user1') - expect(block.blockedAccount.name).to.equal('user1') - expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port) - } - }) - - it('Should unblock the remote account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port) - }) - - it('Should display its videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res = await getVideosListWithToken(servers[0].url, token) - - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(4) - - const v = videos.find(v => v.name === 'video user 2') - expect(v).not.to.be.undefined - } - }) - - it('Should unblock the local account', async function () { - await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1') - }) - - it('Should display its comments', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) - } - }) - - it('Should have notifications from unblocked accounts', async function () { - this.timeout(20000) - - { - const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' } - await checkCommentNotification(servers[0], comment, 'presence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'presence') - } - }) - }) - - describe('When managing server blocklist', function () { - it('Should list all videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) - } - }) - - it('Should list the comments', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) - } - }) - - it('Should block a remote server', async function () { - await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) - }) - - it('Should hide its videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - const res1 = await getVideosList(servers[0].url) - const res2 = await getVideosListWithToken(servers[0].url, token) - - for (const res of [ res1, res2 ]) { - const videos: Video[] = res.body.data - expect(videos).to.have.lengthOf(3) - - const v1 = videos.find(v => v.name === 'video user 2') - const v2 = videos.find(v => v.name === 'video server 2') - - expect(v1).to.be.undefined - expect(v2).to.be.undefined - } - } - }) - - it('Should hide its comments', async function () { - this.timeout(10000) - - const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2') - const threadId = resThreads.body.comment.id - - await waitJobs(servers) - - await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) - - await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId) - }) - - it('Should not have notification from blocked instances by instance', async function () { - this.timeout(50000) - - { - const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } - await checkCommentNotification(servers[0], comment, 'absence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'absence') - } - - { - const now = new Date() - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) - await waitJobs(servers) - await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) - - await waitJobs(servers) - - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) - - expect(commentNotifications).to.have.lengthOf(0) - } - }) - - 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 block = blocks[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) - }) - - it('Should list all videos', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllVideos(servers[0].url, token) - } - }) - - it('Should list the comments', async function () { - for (const token of [ userModeratorToken, servers[0].accessToken ]) { - await checkAllComments(servers[0].url, token, videoUUID1) - } - }) - - it('Should have notification from unblocked instances', async function () { - this.timeout(50000) - - { - const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } - await checkCommentNotification(servers[0], comment, 'presence') - } - - { - const comment = { - server: servers[1], - token: userToken2, - videoUUID: videoUUID1, - text: 'hello @root@localhost:' + servers[0].port - } - await checkCommentNotification(servers[0], comment, 'presence') - } - - { - const now = new Date() - await unfollow(servers[1].url, servers[1].accessToken, servers[0]) - await waitJobs(servers) - await follow(servers[1].url, [ servers[0].host ], servers[1].accessToken) - - await waitJobs(servers) - - const res = await getUserNotifications(servers[0].url, servers[0].accessToken, 0, 30) - const commentNotifications = (res.body.data as UserNotification[]) - .filter(n => { - return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && - n.createdAt >= now.toISOString() - }) - - expect(commentNotifications).to.have.lengthOf(1) - } - }) - }) - }) - - after(async function () { - await cleanupTests(servers) - }) -}) diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts index fcd022429..a244a6edb 100644 --- a/server/tests/api/users/index.ts +++ b/server/tests/api/users/index.ts @@ -1,5 +1,4 @@ -import './users-verification' -import './blocklist' import './user-subscriptions' import './users' import './users-multiple-servers' +import './users-verification' diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 88b68d977..ea74bde6a 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { MyUser, User, UserRole, Video, AbuseState, AbuseUpdate, VideoPlaylistType } from '@shared/models' +import * as chai from 'chai' +import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { CustomConfig } from '@shared/models/server' import { addVideoCommentThread, blockUser, @@ -10,6 +11,7 @@ import { createUser, deleteMe, flushAndRunServer, + getAbusesList, getAccountRatings, getBlacklistedVideosList, getCustomConfig, @@ -19,7 +21,6 @@ import { getUserInformation, getUsersList, getUsersListPaginationAndSort, - getVideoAbusesList, getVideoChannel, getVideosList, installPlugin, @@ -29,15 +30,15 @@ import { registerUserWithChannel, removeUser, removeVideo, - reportVideoAbuse, + reportAbuse, ServerInfo, testImage, unblockUser, + updateAbuse, updateCustomSubConfig, updateMyAvatar, updateMyUser, updateUser, - updateVideoAbuse, uploadVideo, userLogin, waitJobs @@ -46,7 +47,6 @@ import { follow } from '../../../../shared/extra-utils/server/follows' import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { CustomConfig } from '@shared/models/server' const expect = chai.expect @@ -302,10 +302,10 @@ describe('Test users', function () { expect(userGet.videosCount).to.equal(0) expect(userGet.videoCommentsCount).to.be.a('number') expect(userGet.videoCommentsCount).to.equal(0) - expect(userGet.videoAbusesCount).to.be.a('number') - expect(userGet.videoAbusesCount).to.equal(0) - expect(userGet.videoAbusesAcceptedCount).to.be.a('number') - expect(userGet.videoAbusesAcceptedCount).to.equal(0) + expect(userGet.abusesCount).to.be.a('number') + expect(userGet.abusesCount).to.equal(0) + expect(userGet.abusesAcceptedCount).to.be.a('number') + expect(userGet.abusesAcceptedCount).to.equal(0) }) }) @@ -895,9 +895,9 @@ describe('Test users', function () { expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) - expect(user.videoAbusesCount).to.equal(0) - expect(user.videoAbusesCreatedCount).to.equal(0) - expect(user.videoAbusesAcceptedCount).to.equal(0) + expect(user.abusesCount).to.equal(0) + expect(user.abusesCreatedCount).to.equal(0) + expect(user.abusesAcceptedCount).to.equal(0) }) it('Should report correct videos count', async function () { @@ -924,26 +924,26 @@ describe('Test users', function () { expect(user.videoCommentsCount).to.equal(1) }) - it('Should report correct video abuses counts', async function () { + it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) + await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) - const res1 = await getVideoAbusesList({ url: server.url, token: server.accessToken }) + const res1 = await getAbusesList({ url: server.url, token: server.accessToken }) const abuseId = res1.body.data[0].id const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user2: User = res2.body - expect(user2.videoAbusesCount).to.equal(1) // number of incriminations - expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created + expect(user2.abusesCount).to.equal(1) // number of incriminations + expect(user2.abusesCreatedCount).to.equal(1) // number of reports created const body: AbuseUpdate = { state: AbuseState.ACCEPTED } - await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body) + await updateAbuse(server.url, server.accessToken, abuseId, body) const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user3: User = res3.body - expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted + expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) }) diff --git a/server/tests/api/videos/video-abuse.ts b/server/tests/api/videos/video-abuse.ts index 20975aa4a..baeb543e0 100644 --- a/server/tests/api/videos/video-abuse.ts +++ b/server/tests/api/videos/video-abuse.ts @@ -103,8 +103,8 @@ describe('Test video abuses', function () { expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) expect(abuse.video.id).to.equal(servers[0].video.id) expect(abuse.video.channel).to.exist - expect(abuse.count).to.equal(1) - expect(abuse.nth).to.equal(1) + expect(abuse.video.countReports).to.equal(1) + expect(abuse.video.nthReport).to.equal(1) expect(abuse.countReportsForReporter).to.equal(1) expect(abuse.countReportsForReportee).to.equal(1) @@ -138,8 +138,8 @@ describe('Test video abuses', function () { expect(abuse1.state.id).to.equal(AbuseState.PENDING) expect(abuse1.state.label).to.equal('Pending') expect(abuse1.moderationComment).to.be.null - expect(abuse1.count).to.equal(1) - expect(abuse1.nth).to.equal(1) + expect(abuse1.video.countReports).to.equal(1) + expect(abuse1.video.nthReport).to.equal(1) const abuse2: Abuse = res1.body.data[1] expect(abuse2.reason).to.equal('my super bad reason 2') @@ -281,8 +281,8 @@ describe('Test video abuses', function () { { for (const abuse of res2.body.data as Abuse[]) { if (abuse.video.id === video3.id) { - expect(abuse.count).to.equal(1, "wrong reports count for video 3") - expect(abuse.nth).to.equal(1, "wrong report position in report list for video 3") + expect(abuse.video.countReports).to.equal(1, "wrong reports count for video 3") + expect(abuse.video.nthReport).to.equal(1, "wrong report position in report list for video 3") expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") } -- cgit v1.2.3