Init commit
This commit is contained in:
883
packages/tests/src/api/moderation/abuses.ts
Normal file
883
packages/tests/src/api/moderation/abuses.ts
Normal file
@@ -0,0 +1,883 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { expect } from 'chai'
|
||||
import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@peertube/peertube-models'
|
||||
import {
|
||||
AbusesCommand,
|
||||
cleanupTests,
|
||||
createMultipleServers,
|
||||
doubleFollow,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultAccountAvatar,
|
||||
setDefaultChannelAvatar,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
|
||||
describe('Test abuses', function () {
|
||||
let servers: PeerTubeServer[] = []
|
||||
let abuseServer1: AdminAbuse
|
||||
let abuseServer2: AdminAbuse
|
||||
let commands: AbusesCommand[]
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
// Run servers
|
||||
servers = await createMultipleServers(2)
|
||||
|
||||
await setAccessTokensToServers(servers)
|
||||
await setDefaultChannelAvatar(servers)
|
||||
await setDefaultAccountAvatar(servers)
|
||||
|
||||
// Server 1 and server 2 follow each other
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
|
||||
commands = servers.map(s => s.abuses)
|
||||
})
|
||||
|
||||
describe('Video abuses', function () {
|
||||
before(async function () {
|
||||
this.timeout(50000)
|
||||
|
||||
// Upload some videos on each servers
|
||||
{
|
||||
const attributes = {
|
||||
name: 'my super name for server 1',
|
||||
description: 'my super description for server 1'
|
||||
}
|
||||
await servers[0].videos.upload({ attributes })
|
||||
}
|
||||
|
||||
{
|
||||
const attributes = {
|
||||
name: 'my super name for server 2',
|
||||
description: 'my super description for server 2'
|
||||
}
|
||||
await servers[1].videos.upload({ attributes })
|
||||
}
|
||||
|
||||
// Wait videos propagation, server 2 has transcoding enabled
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].videos.list()
|
||||
expect(data.length).to.equal(2)
|
||||
|
||||
servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1')
|
||||
servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2')
|
||||
})
|
||||
|
||||
it('Should not have abuses', async function () {
|
||||
const body = await commands[0].getAdminList()
|
||||
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.be.an('array')
|
||||
expect(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 commands[0].report({ videoId: servers[0].store.videoCreated.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 body = await commands[0].getAdminList()
|
||||
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data).to.be.an('array')
|
||||
expect(body.data.length).to.equal(1)
|
||||
|
||||
const abuse = 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(servers[0].host)
|
||||
|
||||
expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id)
|
||||
expect(abuse.video.channel).to.exist
|
||||
|
||||
expect(abuse.comment).to.be.null
|
||||
|
||||
expect(abuse.flaggedAccount.name).to.equal('root')
|
||||
expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList()
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.be.an('array')
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should report abuse on a remote video', async function () {
|
||||
const reason = 'my super bad reason 2'
|
||||
const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
|
||||
await commands[0].report({ videoId, 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 body = await commands[0].getAdminList()
|
||||
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data.length).to.equal(2)
|
||||
|
||||
const abuse1 = 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(servers[0].host)
|
||||
|
||||
expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id)
|
||||
expect(abuse1.video.countReports).to.equal(1)
|
||||
expect(abuse1.video.nthReport).to.equal(1)
|
||||
|
||||
expect(abuse1.comment).to.be.null
|
||||
|
||||
expect(abuse1.flaggedAccount.name).to.equal('root')
|
||||
expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuse1.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuse1.state.label).to.equal('Pending')
|
||||
expect(abuse1.moderationComment).to.be.null
|
||||
|
||||
const abuse2 = 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(servers[0].host)
|
||||
|
||||
expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
|
||||
|
||||
expect(abuse2.comment).to.be.null
|
||||
|
||||
expect(abuse2.flaggedAccount.name).to.equal('root')
|
||||
expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
|
||||
|
||||
expect(abuse2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuse2.state.label).to.equal('Pending')
|
||||
expect(abuse2.moderationComment).to.be.null
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList()
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data.length).to.equal(1)
|
||||
|
||||
abuseServer2 = 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(servers[0].host)
|
||||
|
||||
expect(abuseServer2.flaggedAccount.name).to.equal('root')
|
||||
expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
|
||||
|
||||
expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuseServer2.state.label).to.equal('Pending')
|
||||
expect(abuseServer2.moderationComment).to.be.null
|
||||
}
|
||||
})
|
||||
|
||||
it('Should hide video abuses from blocked accounts', async function () {
|
||||
{
|
||||
const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid })
|
||||
await commands[1].report({ videoId, reason: 'will mute this' })
|
||||
await waitJobs(servers)
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(3)
|
||||
}
|
||||
|
||||
const accountToBlock = 'root@' + servers[1].host
|
||||
|
||||
{
|
||||
await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock })
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuse = body.data.find(a => a.reason === 'will mute this')
|
||||
expect(abuse).to.be.undefined
|
||||
}
|
||||
|
||||
{
|
||||
await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock })
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(3)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should hide video abuses from blocked servers', async function () {
|
||||
const serverToBlock = servers[1].host
|
||||
|
||||
{
|
||||
await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock })
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuse = body.data.find(a => a.reason === 'will mute this')
|
||||
expect(abuse).to.be.undefined
|
||||
}
|
||||
|
||||
{
|
||||
await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock })
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(3)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should keep the video abuse when deleting the video', async function () {
|
||||
await servers[1].videos.remove({ id: abuseServer2.video.uuid })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const body = await commands[1].getAdminList()
|
||||
expect(body.total).to.equal(2, 'wrong number of videos returned')
|
||||
expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned')
|
||||
|
||||
const abuse = body.data[0]
|
||||
expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video')
|
||||
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 () {
|
||||
// register a second user to have two reporters/reportees
|
||||
const user = { username: 'user2', password: 'password' }
|
||||
await servers[0].users.create({ ...user })
|
||||
const userAccessToken = await servers[0].login.getAccessToken(user)
|
||||
|
||||
// upload a third video via this user
|
||||
const attributes = {
|
||||
name: 'my second super name for server 1',
|
||||
description: 'my second super description for server 1'
|
||||
}
|
||||
const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes })
|
||||
const video3Id = id
|
||||
|
||||
// resume with the test
|
||||
const reason3 = 'my super bad reason 3'
|
||||
await commands[0].report({ videoId: video3Id, reason: reason3 })
|
||||
|
||||
const reason4 = 'my super bad reason 4'
|
||||
await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 })
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList()
|
||||
const abuses = body.data
|
||||
|
||||
const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
|
||||
expect(abuseVideo3).to.not.be.undefined
|
||||
expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3')
|
||||
expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3')
|
||||
expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse')
|
||||
expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse')
|
||||
|
||||
const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id)
|
||||
expect(abuseServer1.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 () {
|
||||
const reason5 = 'my super bad reason 5'
|
||||
const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
|
||||
const createRes = await commands[0].report({
|
||||
videoId: servers[0].store.videoCreated.id,
|
||||
reason: reason5,
|
||||
predefinedReasons: predefinedReasons5,
|
||||
startAt: 1,
|
||||
endAt: 5
|
||||
})
|
||||
|
||||
const body = await commands[0].getAdminList()
|
||||
|
||||
{
|
||||
const abuse = body.data.find(a => a.id === createRes.abuse.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 () {
|
||||
await commands[1].delete({ abuseId: abuseServer2.id })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList()
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data.length).to.equal(1)
|
||||
expect(body.data[0].id).to.not.equal(abuseServer2.id)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList()
|
||||
expect(body.total).to.equal(6)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list and filter video abuses', async function () {
|
||||
async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
|
||||
const body = await commands[0].getAdminList(query)
|
||||
|
||||
return body.data
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Comment abuses', function () {
|
||||
async function getComment (server: PeerTubeServer, videoIdArg: number | string) {
|
||||
const videoId = typeof videoIdArg === 'string'
|
||||
? await server.videos.getId({ uuid: videoIdArg })
|
||||
: videoIdArg
|
||||
|
||||
const { data } = await server.comments.listThreads({ videoId })
|
||||
|
||||
return data[0]
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
this.timeout(50000)
|
||||
|
||||
servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' })
|
||||
servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' })
|
||||
|
||||
await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' })
|
||||
await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should report abuse on a comment', async function () {
|
||||
this.timeout(15000)
|
||||
|
||||
const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
|
||||
|
||||
const reason = 'it is a bad comment'
|
||||
await commands[0].report({ commentId: comment.id, reason })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
|
||||
{
|
||||
const comment = await getComment(servers[0], servers[0].store.videoCreated.id)
|
||||
const body = await commands[0].getAdminList({ filter: 'comment' })
|
||||
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data).to.have.lengthOf(1)
|
||||
|
||||
const abuse = body.data[0]
|
||||
expect(abuse.reason).to.equal('it is a bad comment')
|
||||
|
||||
expect(abuse.reporterAccount.name).to.equal('root')
|
||||
expect(abuse.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuse.video).to.be.null
|
||||
|
||||
expect(abuse.comment.deleted).to.be.false
|
||||
expect(abuse.comment.id).to.equal(comment.id)
|
||||
expect(abuse.comment.text).to.equal(comment.text)
|
||||
expect(abuse.comment.video.name).to.equal('server 1')
|
||||
expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id)
|
||||
expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid)
|
||||
|
||||
expect(abuse.countReportsForReporter).to.equal(5)
|
||||
expect(abuse.countReportsForReportee).to.equal(5)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should report abuse on a remote comment', async function () {
|
||||
const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid)
|
||||
|
||||
const reason = 'it is a really bad comment'
|
||||
await commands[0].report({ commentId: comment.id, reason })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
|
||||
const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID)
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data.length).to.equal(2)
|
||||
|
||||
const abuse = body.data[0]
|
||||
expect(abuse.reason).to.equal('it is a bad comment')
|
||||
expect(abuse.countReportsForReporter).to.equal(6)
|
||||
expect(abuse.countReportsForReportee).to.equal(5)
|
||||
|
||||
const abuse2 = body.data[1]
|
||||
|
||||
expect(abuse2.reason).to.equal('it is a really bad comment')
|
||||
|
||||
expect(abuse2.reporterAccount.name).to.equal('root')
|
||||
expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuse2.video).to.be.null
|
||||
|
||||
expect(abuse2.comment.deleted).to.be.false
|
||||
expect(abuse2.comment.id).to.equal(commentServer2.id)
|
||||
expect(abuse2.comment.text).to.equal(commentServer2.text)
|
||||
expect(abuse2.comment.video.name).to.equal('server 2')
|
||||
expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid)
|
||||
|
||||
expect(abuse2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuse2.state.label).to.equal('Pending')
|
||||
|
||||
expect(abuse2.moderationComment).to.be.null
|
||||
|
||||
expect(abuse2.countReportsForReporter).to.equal(6)
|
||||
expect(abuse2.countReportsForReportee).to.equal(2)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data.length).to.equal(1)
|
||||
|
||||
abuseServer2 = body.data[0]
|
||||
expect(abuseServer2.reason).to.equal('it is a really bad comment')
|
||||
expect(abuseServer2.reporterAccount.name).to.equal('root')
|
||||
expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuseServer2.state.label).to.equal('Pending')
|
||||
|
||||
expect(abuseServer2.moderationComment).to.be.null
|
||||
|
||||
expect(abuseServer2.countReportsForReporter).to.equal(1)
|
||||
expect(abuseServer2.countReportsForReportee).to.equal(1)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should keep the comment abuse when deleting the comment', async function () {
|
||||
const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid)
|
||||
|
||||
await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const body = await commands[0].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data).to.have.lengthOf(2)
|
||||
|
||||
const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
|
||||
expect(abuse).to.not.be.undefined
|
||||
|
||||
expect(abuse.comment.text).to.be.empty
|
||||
expect(abuse.comment.video.name).to.equal('server 2')
|
||||
expect(abuse.comment.deleted).to.be.true
|
||||
})
|
||||
|
||||
it('Should delete the comment abuse', async function () {
|
||||
await commands[1].delete({ abuseId: abuseServer2.id })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list and filter video abuses', async function () {
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
|
||||
expect(body.total).to.equal(0)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
|
||||
expect(body.total).to.equal(2)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
|
||||
expect(body.data).to.have.lengthOf(1)
|
||||
expect(body.data[0].comment.text).to.be.empty
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
|
||||
expect(body.data).to.have.lengthOf(1)
|
||||
expect(body.data[0].comment.text).to.equal('comment server 1')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('Account abuses', function () {
|
||||
function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) {
|
||||
return server.accounts.get({ accountName: targetName + '@' + targetServer.host })
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
this.timeout(50000)
|
||||
|
||||
await servers[0].users.create({ username: 'user_1', password: 'donald' })
|
||||
|
||||
const token = await servers[1].users.generateUserAndToken('user_2')
|
||||
await servers[1].videos.upload({ token, attributes: { name: 'super video' } })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should report abuse on an account', async function () {
|
||||
this.timeout(15000)
|
||||
|
||||
const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
|
||||
|
||||
const reason = 'it is a bad account'
|
||||
await commands[0].report({ accountId: account.id, reason })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'account' })
|
||||
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data).to.have.lengthOf(1)
|
||||
|
||||
const abuse = body.data[0]
|
||||
expect(abuse.reason).to.equal('it is a bad account')
|
||||
|
||||
expect(abuse.reporterAccount.name).to.equal('root')
|
||||
expect(abuse.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuse.video).to.be.null
|
||||
expect(abuse.comment).to.be.null
|
||||
|
||||
expect(abuse.flaggedAccount.name).to.equal('user_1')
|
||||
expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'comment' })
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should report abuse on a remote account', async function () {
|
||||
const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
|
||||
|
||||
const reason = 'it is a really bad account'
|
||||
await commands[0].report({ accountId: account.id, reason })
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'account' })
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data.length).to.equal(2)
|
||||
|
||||
const abuse: AdminAbuse = body.data[0]
|
||||
expect(abuse.reason).to.equal('it is a bad account')
|
||||
|
||||
const abuse2: AdminAbuse = body.data[1]
|
||||
expect(abuse2.reason).to.equal('it is a really bad account')
|
||||
|
||||
expect(abuse2.reporterAccount.name).to.equal('root')
|
||||
expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuse2.video).to.be.null
|
||||
expect(abuse2.comment).to.be.null
|
||||
|
||||
expect(abuse2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuse2.state.label).to.equal('Pending')
|
||||
|
||||
expect(abuse2.moderationComment).to.be.null
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'account' })
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data.length).to.equal(1)
|
||||
|
||||
abuseServer2 = body.data[0]
|
||||
|
||||
expect(abuseServer2.reason).to.equal('it is a really bad account')
|
||||
|
||||
expect(abuseServer2.reporterAccount.name).to.equal('root')
|
||||
expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
|
||||
|
||||
expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
|
||||
expect(abuseServer2.state.label).to.equal('Pending')
|
||||
|
||||
expect(abuseServer2.moderationComment).to.be.null
|
||||
}
|
||||
})
|
||||
|
||||
it('Should keep the account abuse when deleting the account', async function () {
|
||||
const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
|
||||
await servers[1].users.remove({ userId: account.userId })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const body = await commands[0].getAdminList({ filter: 'account' })
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data).to.have.lengthOf(2)
|
||||
|
||||
const abuse = body.data.find(a => a.reason === 'it is a really bad account')
|
||||
expect(abuse).to.not.be.undefined
|
||||
})
|
||||
|
||||
it('Should delete the account abuse', async function () {
|
||||
await commands[1].delete({ abuseId: abuseServer2.id })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
{
|
||||
const body = await commands[1].getAdminList({ filter: 'account' })
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getAdminList({ filter: 'account' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
abuseServer1 = body.data[0]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('Common actions on abuses', function () {
|
||||
it('Should update the state of an abuse', async function () {
|
||||
await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
|
||||
|
||||
const body = await commands[0].getAdminList({ id: abuseServer1.id })
|
||||
expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
|
||||
})
|
||||
|
||||
it('Should add a moderation comment', async function () {
|
||||
await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
|
||||
|
||||
const body = await commands[0].getAdminList({ id: abuseServer1.id })
|
||||
expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
|
||||
expect(body.data[0].moderationComment).to.equal('Valid')
|
||||
})
|
||||
})
|
||||
|
||||
describe('My abuses', async function () {
|
||||
let abuseId1: number
|
||||
let userAccessToken: string
|
||||
|
||||
before(async function () {
|
||||
userAccessToken = await servers[0].users.generateUserAndToken('user_42')
|
||||
|
||||
await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' })
|
||||
|
||||
const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid })
|
||||
await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
|
||||
})
|
||||
|
||||
it('Should correctly list my abuses', async function () {
|
||||
{
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuses = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 1')
|
||||
expect(abuses[1].reason).to.equal('user reason 2')
|
||||
|
||||
abuseId1 = abuses[0].id
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuses: UserAbuse[] = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 2')
|
||||
}
|
||||
|
||||
{
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuses: UserAbuse[] = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 1')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should correctly filter my abuses by id', async function () {
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
const abuses: UserAbuse[] = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 1')
|
||||
})
|
||||
|
||||
it('Should correctly filter my abuses by search', async function () {
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
const abuses: UserAbuse[] = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 2')
|
||||
})
|
||||
|
||||
it('Should correctly filter my abuses by state', async function () {
|
||||
await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
|
||||
|
||||
const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
const abuses: UserAbuse[] = body.data
|
||||
expect(abuses[0].reason).to.equal('user reason 1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Abuse messages', async function () {
|
||||
let abuseId: number
|
||||
let userToken: string
|
||||
let abuseMessageUserId: number
|
||||
let abuseMessageModerationId: number
|
||||
|
||||
before(async function () {
|
||||
userToken = await servers[0].users.generateUserAndToken('user_43')
|
||||
|
||||
const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' })
|
||||
abuseId = body.abuse.id
|
||||
})
|
||||
|
||||
it('Should create some messages on the abuse', async function () {
|
||||
await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
|
||||
await commands[0].addMessage({ abuseId, message: 'message 2' })
|
||||
await commands[0].addMessage({ abuseId, message: 'message 3' })
|
||||
await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
|
||||
})
|
||||
|
||||
it('Should have the correct messages count when listing abuses', async function () {
|
||||
const results = await Promise.all([
|
||||
commands[0].getAdminList({ start: 0, count: 50 }),
|
||||
commands[0].getUserList({ token: userToken, start: 0, count: 50 })
|
||||
])
|
||||
|
||||
for (const body of results) {
|
||||
const abuses = body.data
|
||||
const abuse = abuses.find(a => a.id === abuseId)
|
||||
expect(abuse.countMessages).to.equal(4)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should correctly list messages of this abuse', async function () {
|
||||
const results = await Promise.all([
|
||||
commands[0].listMessages({ abuseId }),
|
||||
commands[0].listMessages({ token: userToken, abuseId })
|
||||
])
|
||||
|
||||
for (const body of results) {
|
||||
expect(body.total).to.equal(4)
|
||||
|
||||
const abuseMessages: AbuseMessage[] = body.data
|
||||
|
||||
expect(abuseMessages[0].message).to.equal('message 1')
|
||||
expect(abuseMessages[0].byModerator).to.be.false
|
||||
expect(abuseMessages[0].account.name).to.equal('user_43')
|
||||
|
||||
abuseMessageUserId = abuseMessages[0].id
|
||||
|
||||
expect(abuseMessages[1].message).to.equal('message 2')
|
||||
expect(abuseMessages[1].byModerator).to.be.true
|
||||
expect(abuseMessages[1].account.name).to.equal('root')
|
||||
|
||||
expect(abuseMessages[2].message).to.equal('message 3')
|
||||
expect(abuseMessages[2].byModerator).to.be.true
|
||||
expect(abuseMessages[2].account.name).to.equal('root')
|
||||
abuseMessageModerationId = abuseMessages[2].id
|
||||
|
||||
expect(abuseMessages[3].message).to.equal('message 4')
|
||||
expect(abuseMessages[3].byModerator).to.be.false
|
||||
expect(abuseMessages[3].account.name).to.equal('user_43')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should delete messages', async function () {
|
||||
await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
|
||||
await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
|
||||
|
||||
const results = await Promise.all([
|
||||
commands[0].listMessages({ abuseId }),
|
||||
commands[0].listMessages({ token: userToken, abuseId })
|
||||
])
|
||||
|
||||
for (const body of results) {
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const abuseMessages: AbuseMessage[] = body.data
|
||||
expect(abuseMessages[0].message).to.equal('message 2')
|
||||
expect(abuseMessages[1].message).to.equal('message 4')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
489
packages/tests/src/api/moderation/automatic-tags.ts
Normal file
489
packages/tests/src/api/moderation/automatic-tags.ts
Normal file
@@ -0,0 +1,489 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { VideoPrivacy } from '@peertube/peertube-models'
|
||||
import {
|
||||
cleanupTests, createMultipleServers,
|
||||
doubleFollow,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultAccountAvatar,
|
||||
setDefaultVideoChannel,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test automatic tags', function () {
|
||||
let servers: PeerTubeServer[]
|
||||
let videoUUID: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await createMultipleServers(2)
|
||||
await setAccessTokensToServers(servers)
|
||||
await setDefaultVideoChannel(servers)
|
||||
await setDefaultAccountAvatar(servers)
|
||||
|
||||
await servers[1].config.enableLive({ allowReplay: false })
|
||||
|
||||
await doubleFollow(servers[0], servers[1]);
|
||||
|
||||
({ uuid: videoUUID } = await servers[0].videos.quickUpload({ name: 'video' }))
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
describe('Automatic tags on comments', function () {
|
||||
|
||||
describe('Built in external link auto tag', function () {
|
||||
|
||||
it('Should not assign external-link automatic tag with no URL inside the comment', async function () {
|
||||
const tests = [
|
||||
'my super comment',
|
||||
'toto.azfazfe',
|
||||
'Hello. Hi friends'
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: toTest })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listForAdmin()
|
||||
|
||||
for (const comment of data) {
|
||||
expect(comment.automaticTags, `"${comment.text}" has an automatic tag`).to.have.lengthOf(0)
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].comments.deleteAllComments({ videoUUID })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not assign external-link automatic tag if the URL is an internal link', async function () {
|
||||
const tests = [
|
||||
`Hi ${servers[0].url}`
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: toTest })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
// Server 1
|
||||
{
|
||||
const { data } = await servers[0].comments.listForAdmin()
|
||||
|
||||
for (const comment of data) {
|
||||
expect(comment.automaticTags, `"${comment.text}" has an automatic tag`).to.have.lengthOf(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Server 2
|
||||
{
|
||||
const { data } = await servers[1].comments.listForAdmin()
|
||||
|
||||
for (const comment of data) {
|
||||
expect(comment.automaticTags, `"${comment.text}" hasn't an automatic tag`).to.have.lengthOf(1)
|
||||
expect(comment.automaticTags[0]).to.equal('external-link')
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].comments.deleteAllComments({ videoUUID })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should assign external-link automatic tag', async function () {
|
||||
const tests = [
|
||||
'example.com',
|
||||
'Hi example.com'
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: toTest })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listForAdmin()
|
||||
|
||||
for (const comment of data) {
|
||||
expect(comment.automaticTags).to.have.lengthOf(1)
|
||||
expect(comment.automaticTags[0]).to.equal('external-link')
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].comments.deleteAllComments({ videoUUID })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
})
|
||||
|
||||
describe('With watched words', function () {
|
||||
let accountListId: number
|
||||
|
||||
it('Should create watched words list and automatically assign an automatic tag', async function () {
|
||||
// Account list
|
||||
{
|
||||
await servers[0].watchedWordsLists.createList({ listName: 'list 1', words: [ 'word 1', 'word 2' ], accountName: 'root' })
|
||||
|
||||
const { watchedWordsList } = await servers[0].watchedWordsLists.createList({
|
||||
listName: 'list 2',
|
||||
words: [ 'nemo' ],
|
||||
accountName: 'root'
|
||||
})
|
||||
accountListId = watchedWordsList.id
|
||||
}
|
||||
|
||||
// Server list
|
||||
{
|
||||
await servers[0].watchedWordsLists.createList({ listName: 'server 2', words: [ 'word 2' ] })
|
||||
}
|
||||
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'hi captain' })
|
||||
await servers[0].comments.addReplyToLastThread({ text: 'hi captain nemo' })
|
||||
await servers[1].comments.createThread({ videoId: videoUUID, text: 'hi captain nemo word 2 example.com' })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
// Server comments list must not include account personal watched words
|
||||
{
|
||||
const { data } = await servers[0].comments.listForAdmin()
|
||||
const c = (text: string) => data.find(c => c.text === text)
|
||||
|
||||
expect(c('hi captain').automaticTags).to.have.lengthOf(0)
|
||||
expect(c('hi captain nemo').automaticTags).to.have.lengthOf(0)
|
||||
expect(c('hi captain nemo word 2 example.com').automaticTags).to.have.members([ 'server 2', 'external-link' ])
|
||||
}
|
||||
|
||||
{
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos()
|
||||
const c = (text: string) => data.find(c => c.text === text)
|
||||
|
||||
expect(c('hi captain').automaticTags).to.have.lengthOf(0)
|
||||
expect(c('hi captain nemo').automaticTags).to.have.members([ 'list 2' ])
|
||||
expect(c('hi captain nemo word 2 example.com').automaticTags).to.have.members([ 'list 1', 'list 2', 'external-link' ])
|
||||
}
|
||||
})
|
||||
|
||||
it('Should update watched words list and assign auto tag with new words', async function () {
|
||||
// No tags
|
||||
{
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'my nautilus' })
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos()
|
||||
expect(data.find(c => c.text === 'my nautilus').automaticTags).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
await servers[0].watchedWordsLists.updateList({
|
||||
accountName: 'root',
|
||||
listId: accountListId,
|
||||
words: [ 'nautilus' ],
|
||||
listName: 'list 3'
|
||||
})
|
||||
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'captain nemo' })
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'my nautilus 2' })
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'word 1' })
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos()
|
||||
// Previous comment still have the same automatic tags
|
||||
expect(data.find(c => c.text === 'my nautilus').automaticTags).to.have.lengthOf(0)
|
||||
|
||||
expect(data.find(c => c.text === 'captain nemo').automaticTags).to.have.lengthOf(0)
|
||||
expect(data.find(c => c.text === 'my nautilus 2').automaticTags).to.have.members([ 'list 3' ])
|
||||
expect(data.find(c => c.text === 'word 1').automaticTags).to.have.members([ 'list 1' ])
|
||||
}
|
||||
})
|
||||
|
||||
it('Should delete watched words list and so not assign auto tags anymore', async function () {
|
||||
await servers[0].watchedWordsLists.deleteList({ accountName: 'root', listId: accountListId })
|
||||
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'my nautilus 3' })
|
||||
await servers[0].comments.createThread({ videoId: videoUUID, text: 'word 2' })
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos()
|
||||
expect(data.find(c => c.text === 'my nautilus 3').automaticTags).to.have.lengthOf(0)
|
||||
expect(data.find(c => c.text === 'word 2').automaticTags).to.have.members([ 'list 1' ])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Searching comments with specific tags', function () {
|
||||
|
||||
it('Should search in "comments on my videos" comments with specific automatic tags', async function () {
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listCommentsOnMyVideos({ autoTagOneOf: [ 'unknown' ] })
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
for (const autoTagOneOf of [ [ 'list 1' ], [ 'list 1', 'unknown' ] ]) {
|
||||
const { total, data } = await servers[0].comments.listCommentsOnMyVideos({ autoTagOneOf })
|
||||
|
||||
expect(total).to.equal(3)
|
||||
|
||||
expect(data.map(c => c.text)).to.have.members([
|
||||
'hi captain nemo word 2 example.com',
|
||||
'word 1',
|
||||
'word 2'
|
||||
])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should search in admin comments with specific automatic tags', async function () {
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listForAdmin({ autoTagOneOf: [ 'list 1' ] })
|
||||
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listForAdmin({ autoTagOneOf: [ 'external-link' ] })
|
||||
|
||||
expect(total).to.equal(1)
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].text).to.equal('hi captain nemo word 2 example.com')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('Automatic tags on videos', function () {
|
||||
|
||||
before(async function () {
|
||||
await servers[0].videos.removeAll()
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
describe('Built in external link auto tag', function () {
|
||||
|
||||
it('Should not assign external-link automatic tag with no URL inside the video', async function () {
|
||||
const tests = [
|
||||
'my super video',
|
||||
'toto.azfazfe',
|
||||
'Hello. Hi friends'
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].videos.upload({ attributes: { name: toTest, description: toTest } })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.videos.listAllForAdmin()
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.automaticTags, `"${video.name}" has an automatic tag`).to.have.lengthOf(0)
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].videos.removeAll()
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not assign external-link automatic tag if the URL is an internal link', async function () {
|
||||
const tests = [
|
||||
`Hi ${servers[0].url}`
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].videos.upload({ attributes: { name: toTest, description: toTest } })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
// Server 1
|
||||
{
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.automaticTags, `"${video.name}" has an automatic tag`).to.have.lengthOf(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Server 2
|
||||
{
|
||||
const { data } = await servers[1].videos.listAllForAdmin()
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.automaticTags, `"${video.name}" hasn't an automatic tag`).to.have.lengthOf(1)
|
||||
expect(video.automaticTags[0]).to.equal('external-link')
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].videos.removeAll()
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should assign external-link automatic tag', async function () {
|
||||
const tests = [
|
||||
'example.com',
|
||||
'Hi example.com'
|
||||
]
|
||||
|
||||
for (const toTest of tests) {
|
||||
await servers[0].videos.upload({ attributes: { name: toTest, description: toTest } })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.videos.listAllForAdmin()
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.automaticTags).to.have.lengthOf(1)
|
||||
expect(video.automaticTags[0]).to.equal('external-link')
|
||||
}
|
||||
}
|
||||
|
||||
await servers[0].videos.removeAll()
|
||||
await waitJobs(servers)
|
||||
})
|
||||
})
|
||||
|
||||
describe('With watched words', function () {
|
||||
let serverListId: number
|
||||
let liveUUID: string
|
||||
|
||||
it('Should create watched words list and automatically assign an automatic tag', async function () {
|
||||
// Server list
|
||||
{
|
||||
await servers[0].watchedWordsLists.createList({
|
||||
listName: 'donald list',
|
||||
words: [ 'riri', 'fifi', 'loulou' ]
|
||||
})
|
||||
|
||||
const { watchedWordsList } = await servers[0].watchedWordsLists.createList({
|
||||
listName: 'mickey list',
|
||||
words: [ 'dingo', 'pluto' ]
|
||||
})
|
||||
serverListId = watchedWordsList.id
|
||||
}
|
||||
|
||||
// Account list
|
||||
{
|
||||
await servers[0].watchedWordsLists.createList({ listName: 'picsou list', words: [ 'goldie' ], accountName: 'root' })
|
||||
}
|
||||
|
||||
await servers[0].videos.upload({ attributes: { name: 'my dear goldie', description: 'hi riri and fifi' } })
|
||||
await servers[0].videoImports.importVideo({
|
||||
attributes: {
|
||||
targetUrl: FIXTURE_URLS.goodVideo,
|
||||
channelId: servers[0].store.channel.id,
|
||||
name: 'import video',
|
||||
description: 'pluto dog'
|
||||
}
|
||||
})
|
||||
const { uuid } = await servers[1].live.create({
|
||||
fields: {
|
||||
channelId: servers[0].store.channel.id,
|
||||
privacy: VideoPrivacy.PUBLIC,
|
||||
name: 'live loulou',
|
||||
description: 'dingo and minnie'
|
||||
}
|
||||
})
|
||||
liveUUID = uuid
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
// Server videos list must not include account personal watched words
|
||||
{
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
const v = (name: string) => data.find(c => c.name === name)
|
||||
|
||||
expect(v('my dear goldie').automaticTags).to.have.members([ 'donald list' ])
|
||||
expect(v('import video').automaticTags).to.have.members([ 'mickey list' ])
|
||||
expect(v('live loulou').automaticTags).to.have.members([ 'donald list', 'mickey list' ])
|
||||
}
|
||||
|
||||
{
|
||||
const { data } = await servers[0].videos.listMyVideos()
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.automaticTags).to.not.exist
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should update watched words list and assign auto tag on update', async function () {
|
||||
const { uuid } = await servers[0].videos.quickUpload({ name: 'hi minnie' })
|
||||
|
||||
{
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
expect(data.find(v => v.name === 'hi minnie').automaticTags).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
await servers[0].watchedWordsLists.updateList({
|
||||
listId: serverListId,
|
||||
words: [ 'Minnie' ],
|
||||
listName: 'mickey list v2'
|
||||
})
|
||||
|
||||
await servers[0].videos.update({ id: uuid, attributes: { name: 'hi minnie v2' } })
|
||||
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
expect(data.find(v => v.name === 'hi minnie v2').automaticTags).to.have.members([ 'mickey list v2' ])
|
||||
}
|
||||
})
|
||||
|
||||
it('Should not update remote video if name/description has not changed', async function () {
|
||||
await servers[1].videos.update({
|
||||
id: liveUUID,
|
||||
attributes: {
|
||||
channelId: servers[0].store.channel.id,
|
||||
tags: [ 'super tag' ]
|
||||
}
|
||||
})
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
expect(data.find(v => v.name === 'live loulou').automaticTags).to.have.members([ 'donald list', 'mickey list' ])
|
||||
})
|
||||
|
||||
it('Should update remote video if name/description has changed', async function () {
|
||||
await servers[1].videos.update({
|
||||
id: liveUUID,
|
||||
attributes: { name: 'live loulou v2' }
|
||||
})
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].videos.listAllForAdmin()
|
||||
expect(data.find(v => v.name === 'live loulou v2').automaticTags).to.have.members([ 'donald list', 'mickey list v2' ])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Searching videos with specific tags', function () {
|
||||
|
||||
it('Should search in admin videos with specific automatic tags', async function () {
|
||||
{
|
||||
const { total, data } = await servers[0].videos.listAllForAdmin({ autoTagOneOf: [ 'picsou list' ] })
|
||||
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const { total, data } = await servers[0].videos.listAllForAdmin({ autoTagOneOf: [ 'mickey list v2' ] })
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
expect(data.map(d => d.name)).to.have.members([ 'hi minnie v2', 'live loulou v2' ])
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
231
packages/tests/src/api/moderation/blocklist-notification.ts
Normal file
231
packages/tests/src/api/moderation/blocklist-notification.ts
Normal file
@@ -0,0 +1,231 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { expect } from 'chai'
|
||||
import { UserNotificationType, UserNotificationType_Type } from '@peertube/peertube-models'
|
||||
import {
|
||||
cleanupTests,
|
||||
createMultipleServers,
|
||||
doubleFollow,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
|
||||
async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType_Type[]) {
|
||||
const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true })
|
||||
expect(data).to.have.lengthOf(expected.length)
|
||||
|
||||
for (const type of expected) {
|
||||
expect(data.find(n => n.type === type)).to.exist
|
||||
}
|
||||
}
|
||||
|
||||
describe('Test blocklist notifications', function () {
|
||||
let servers: PeerTubeServer[]
|
||||
let videoUUID: string
|
||||
|
||||
let userToken1: string
|
||||
let userToken2: string
|
||||
let remoteUserToken: string
|
||||
|
||||
async function resetState () {
|
||||
try {
|
||||
await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host })
|
||||
await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host })
|
||||
} catch {}
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
await servers[0].notifications.markAsReadAll({ token: userToken1 })
|
||||
await servers[0].notifications.markAsReadAll({ token: userToken2 })
|
||||
|
||||
{
|
||||
const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } })
|
||||
videoUUID = uuid
|
||||
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
{
|
||||
await servers[1].comments.createThread({
|
||||
token: remoteUserToken,
|
||||
videoId: videoUUID,
|
||||
text: '@user2@' + servers[0].host + ' hello'
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host })
|
||||
await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host })
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
servers = await createMultipleServers(2)
|
||||
await setAccessTokensToServers(servers)
|
||||
|
||||
{
|
||||
const user = { username: 'user1', password: 'password' }
|
||||
await servers[0].users.create({
|
||||
username: user.username,
|
||||
password: user.password,
|
||||
videoQuota: -1,
|
||||
videoQuotaDaily: -1
|
||||
})
|
||||
|
||||
userToken1 = await servers[0].login.getAccessToken(user)
|
||||
await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
|
||||
}
|
||||
|
||||
{
|
||||
const user = { username: 'user2', password: 'password' }
|
||||
await servers[0].users.create({ username: user.username, password: user.password })
|
||||
|
||||
userToken2 = await servers[0].login.getAccessToken(user)
|
||||
}
|
||||
|
||||
{
|
||||
const user = { username: 'user3', password: 'password' }
|
||||
await servers[1].users.create({ username: user.username, password: user.password })
|
||||
|
||||
remoteUserToken = await servers[1].login.getAccessToken(user)
|
||||
}
|
||||
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
})
|
||||
|
||||
describe('User blocks another user', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await resetState()
|
||||
})
|
||||
|
||||
it('Should have appropriate notifications', async function () {
|
||||
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken1, notifs)
|
||||
})
|
||||
|
||||
it('Should block an account', async function () {
|
||||
await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not have notifications from this account', async function () {
|
||||
await checkNotifications(servers[0], userToken1, [])
|
||||
})
|
||||
|
||||
it('Should have notifications of this account on user 2', async function () {
|
||||
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
||||
|
||||
await checkNotifications(servers[0], userToken2, notifs)
|
||||
|
||||
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host })
|
||||
})
|
||||
})
|
||||
|
||||
describe('User blocks another server', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await resetState()
|
||||
})
|
||||
|
||||
it('Should have appropriate notifications', async function () {
|
||||
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken1, notifs)
|
||||
})
|
||||
|
||||
it('Should block an account', async function () {
|
||||
await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not have notifications from this account', async function () {
|
||||
await checkNotifications(servers[0], userToken1, [])
|
||||
})
|
||||
|
||||
it('Should have notifications of this account on user 2', async function () {
|
||||
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
||||
|
||||
await checkNotifications(servers[0], userToken2, notifs)
|
||||
|
||||
await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host })
|
||||
})
|
||||
})
|
||||
|
||||
describe('Server blocks a user', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await resetState()
|
||||
})
|
||||
|
||||
it('Should have appropriate notifications', async function () {
|
||||
{
|
||||
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken1, notifs)
|
||||
}
|
||||
|
||||
{
|
||||
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken2, notifs)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should block an account', async function () {
|
||||
await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not have notifications from this account', async function () {
|
||||
await checkNotifications(servers[0], userToken1, [])
|
||||
await checkNotifications(servers[0], userToken2, [])
|
||||
|
||||
await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host })
|
||||
})
|
||||
})
|
||||
|
||||
describe('Server blocks a server', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await resetState()
|
||||
})
|
||||
|
||||
it('Should have appropriate notifications', async function () {
|
||||
{
|
||||
const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken1, notifs)
|
||||
}
|
||||
|
||||
{
|
||||
const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ]
|
||||
await checkNotifications(servers[0], userToken2, notifs)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should block an account', async function () {
|
||||
await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not have notifications from this account', async function () {
|
||||
await checkNotifications(servers[0], userToken1, [])
|
||||
await checkNotifications(servers[0], userToken2, [])
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
907
packages/tests/src/api/moderation/blocklist.ts
Normal file
907
packages/tests/src/api/moderation/blocklist.ts
Normal file
@@ -0,0 +1,907 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { expect } from 'chai'
|
||||
import { UserNotificationType } from '@peertube/peertube-models'
|
||||
import {
|
||||
BlocklistCommand,
|
||||
cleanupTests,
|
||||
CommentsCommand,
|
||||
createMultipleServers,
|
||||
doubleFollow,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultAccountAvatar,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
|
||||
async function checkAllVideos (server: PeerTubeServer, token: string) {
|
||||
{
|
||||
const { data } = await server.videos.listWithToken({ token })
|
||||
expect(data).to.have.lengthOf(5)
|
||||
}
|
||||
|
||||
{
|
||||
const { data } = await server.videos.list()
|
||||
expect(data).to.have.lengthOf(5)
|
||||
}
|
||||
}
|
||||
|
||||
async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
|
||||
const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
|
||||
|
||||
const threads = data.filter(t => t.isDeleted === false)
|
||||
expect(threads).to.have.lengthOf(2)
|
||||
|
||||
for (const thread of threads) {
|
||||
const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
|
||||
expect(tree.children).to.have.lengthOf(1)
|
||||
}
|
||||
}
|
||||
|
||||
async function checkCommentNotification (
|
||||
mainServer: PeerTubeServer,
|
||||
comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
|
||||
check: 'presence' | 'absence'
|
||||
) {
|
||||
const command = comment.server.comments
|
||||
|
||||
const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
|
||||
|
||||
await waitJobs([ mainServer, comment.server ])
|
||||
|
||||
const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
|
||||
const commentNotifications = data.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 command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
|
||||
|
||||
await waitJobs([ mainServer, comment.server ])
|
||||
}
|
||||
|
||||
describe('Test blocklist', function () {
|
||||
let servers: PeerTubeServer[]
|
||||
let videoUUID1: string
|
||||
let videoUUID2: string
|
||||
let videoUUID3: string
|
||||
let userToken1: string
|
||||
let userModeratorToken: string
|
||||
let userToken2: string
|
||||
|
||||
let command: BlocklistCommand
|
||||
let commentsCommand: CommentsCommand[]
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await createMultipleServers(3)
|
||||
await setAccessTokensToServers(servers)
|
||||
await setDefaultAccountAvatar(servers)
|
||||
|
||||
command = servers[0].blocklist
|
||||
commentsCommand = servers.map(s => s.comments)
|
||||
|
||||
{
|
||||
const user = { username: 'user1', password: 'password' }
|
||||
await servers[0].users.create({ username: user.username, password: user.password })
|
||||
|
||||
userToken1 = await servers[0].login.getAccessToken(user)
|
||||
await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
|
||||
}
|
||||
|
||||
{
|
||||
const user = { username: 'moderator', password: 'password' }
|
||||
await servers[0].users.create({ username: user.username, password: user.password })
|
||||
|
||||
userModeratorToken = await servers[0].login.getAccessToken(user)
|
||||
}
|
||||
|
||||
{
|
||||
const user = { username: 'user2', password: 'password' }
|
||||
await servers[1].users.create({ username: user.username, password: user.password })
|
||||
|
||||
userToken2 = await servers[1].login.getAccessToken(user)
|
||||
await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
|
||||
}
|
||||
|
||||
{
|
||||
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
|
||||
videoUUID1 = uuid
|
||||
}
|
||||
|
||||
{
|
||||
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
|
||||
videoUUID2 = uuid
|
||||
}
|
||||
|
||||
{
|
||||
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
|
||||
videoUUID3 = uuid
|
||||
}
|
||||
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
await doubleFollow(servers[0], servers[2])
|
||||
|
||||
{
|
||||
const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' })
|
||||
const reply = await commentsCommand[0].addReply({
|
||||
token: userToken1,
|
||||
videoId: videoUUID1,
|
||||
toCommentId: created.id,
|
||||
text: 'comment user 1'
|
||||
})
|
||||
await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' })
|
||||
}
|
||||
|
||||
{
|
||||
const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' })
|
||||
await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: '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], servers[0].accessToken)
|
||||
})
|
||||
|
||||
it('Should list the comments', function () {
|
||||
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||
})
|
||||
|
||||
it('Should block a remote account', async function () {
|
||||
await command.addToMyBlocklist({ account: 'user2@' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
const { data } = await servers[0].videos.listWithToken()
|
||||
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 2')
|
||||
expect(v).to.be.undefined
|
||||
})
|
||||
|
||||
it('Should block a local account', async function () {
|
||||
await command.addToMyBlocklist({ account: 'user1' })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
const { data } = await servers[0].videos.listWithToken()
|
||||
|
||||
expect(data).to.have.lengthOf(3)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 1')
|
||||
expect(v).to.be.undefined
|
||||
})
|
||||
|
||||
it('Should hide its comments', async function () {
|
||||
const { data } = await commentsCommand[0].listThreads({
|
||||
token: servers[0].accessToken,
|
||||
videoId: videoUUID1,
|
||||
start: 0,
|
||||
count: 25,
|
||||
sort: '-createdAt'
|
||||
})
|
||||
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].totalReplies).to.equal(1)
|
||||
|
||||
const t = data.find(t => t.text === 'comment user 1')
|
||||
expect(t).to.be.undefined
|
||||
|
||||
for (const thread of data) {
|
||||
const tree = await commentsCommand[0].getThread({
|
||||
videoId: videoUUID1,
|
||||
threadId: thread.id,
|
||||
token: servers[0].accessToken
|
||||
})
|
||||
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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'absence')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list all the videos with another user', async function () {
|
||||
return checkAllVideos(servers[0], userToken1)
|
||||
})
|
||||
|
||||
it('Should list blocked accounts', async function () {
|
||||
{
|
||||
const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
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')
|
||||
expect(block.blockedAccount.name).to.equal('user2')
|
||||
expect(block.blockedAccount.host).to.equal('' + servers[1].host)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
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')
|
||||
expect(block.blockedAccount.name).to.equal('user1')
|
||||
expect(block.blockedAccount.host).to.equal('' + servers[0].host)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should search blocked accounts', async function () {
|
||||
const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
expect(body.data[0].blockedAccount.name).to.equal('user2')
|
||||
})
|
||||
|
||||
it('Should get blocked status', async function () {
|
||||
const remoteHandle = 'user2@' + servers[1].host
|
||||
const localHandle = 'user1@' + servers[0].host
|
||||
const unknownHandle = 'user5@' + servers[0].host
|
||||
|
||||
{
|
||||
const status = await command.getStatus({ accounts: [ remoteHandle ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(1)
|
||||
expect(status.accounts[remoteHandle].blockedByUser).to.be.false
|
||||
expect(status.accounts[remoteHandle].blockedByServer).to.be.false
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(1)
|
||||
expect(status.accounts[remoteHandle].blockedByUser).to.be.true
|
||||
expect(status.accounts[remoteHandle].blockedByServer).to.be.false
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(3)
|
||||
|
||||
for (const handle of [ localHandle, remoteHandle ]) {
|
||||
expect(status.accounts[handle].blockedByUser).to.be.true
|
||||
expect(status.accounts[handle].blockedByServer).to.be.false
|
||||
}
|
||||
|
||||
expect(status.accounts[unknownHandle].blockedByUser).to.be.false
|
||||
expect(status.accounts[unknownHandle].blockedByServer).to.be.false
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should not allow a remote blocked user to comment my videos', async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
{
|
||||
await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
|
||||
await waitJobs(servers)
|
||||
|
||||
await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
|
||||
await waitJobs(servers)
|
||||
|
||||
const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
|
||||
const message = 'reply by user 2'
|
||||
const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message })
|
||||
await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' })
|
||||
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
// Server 2 has all the comments
|
||||
{
|
||||
const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||
|
||||
expect(data).to.have.lengthOf(2)
|
||||
expect(data[0].text).to.equal('uploader')
|
||||
expect(data[1].text).to.equal('comment user 2')
|
||||
|
||||
const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||
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 { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].text).to.equal('uploader')
|
||||
|
||||
const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||
|
||||
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 command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should display its videos', async function () {
|
||||
const { data } = await servers[0].videos.listWithToken()
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
const v = data.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 { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
||||
|
||||
// Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
|
||||
if (server.serverNumber === 3) {
|
||||
expect(data).to.have.lengthOf(1)
|
||||
continue
|
||||
}
|
||||
|
||||
expect(data).to.have.lengthOf(2)
|
||||
expect(data[0].text).to.equal('uploader')
|
||||
expect(data[1].text).to.equal('comment user 2')
|
||||
|
||||
const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
||||
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 command.removeFromMyBlocklist({ account: 'user1' })
|
||||
})
|
||||
|
||||
it('Should display its comments', function () {
|
||||
return checkAllComments(servers[0], 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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'presence')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('When managing server blocklist', function () {
|
||||
it('Should list all videos', function () {
|
||||
return checkAllVideos(servers[0], servers[0].accessToken)
|
||||
})
|
||||
|
||||
it('Should list the comments', function () {
|
||||
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||
})
|
||||
|
||||
it('Should block a remote server', async function () {
|
||||
await command.addToMyBlocklist({ server: '' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
const { data } = await servers[0].videos.listWithToken()
|
||||
|
||||
expect(data).to.have.lengthOf(3)
|
||||
|
||||
const v1 = data.find(v => v.name === 'video user 2')
|
||||
const v2 = data.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], userToken1)
|
||||
})
|
||||
|
||||
it('Should hide its comments', async function () {
|
||||
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||
|
||||
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
||||
})
|
||||
|
||||
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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'absence')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list blocked servers', async function () {
|
||||
const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
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('' + servers[1].host)
|
||||
})
|
||||
|
||||
it('Should search blocked servers', async function () {
|
||||
const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
|
||||
})
|
||||
|
||||
it('Should get blocklist status', async function () {
|
||||
const blockedServer = servers[1].host
|
||||
const notBlockedServer = 'example.com'
|
||||
|
||||
{
|
||||
const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(0)
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(2)
|
||||
expect(status.hosts[blockedServer].blockedByUser).to.be.false
|
||||
expect(status.hosts[blockedServer].blockedByServer).to.be.false
|
||||
|
||||
expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
|
||||
expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
|
||||
}
|
||||
|
||||
{
|
||||
const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(0)
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(2)
|
||||
expect(status.hosts[blockedServer].blockedByUser).to.be.true
|
||||
expect(status.hosts[blockedServer].blockedByServer).to.be.false
|
||||
|
||||
expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
|
||||
expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
|
||||
}
|
||||
})
|
||||
|
||||
it('Should unblock the remote server', async function () {
|
||||
await command.removeFromMyBlocklist({ server: '' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should display its videos', function () {
|
||||
return checkAllVideos(servers[0], servers[0].accessToken)
|
||||
})
|
||||
|
||||
it('Should display its comments', function () {
|
||||
return checkAllComments(servers[0], 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@' + servers[0].host
|
||||
}
|
||||
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], token)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list the comments', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
await checkAllComments(servers[0], token, videoUUID1)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should block a remote account', async function () {
|
||||
await command.addToServerBlocklist({ account: 'user2@' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
const { data } = await servers[0].videos.listWithToken({ token })
|
||||
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 2')
|
||||
expect(v).to.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should block a local account', async function () {
|
||||
await command.addToServerBlocklist({ account: 'user1' })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
const { data } = await servers[0].videos.listWithToken({ token })
|
||||
|
||||
expect(data).to.have.lengthOf(3)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 1')
|
||||
expect(v).to.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should display owned videos of blocked account to this account', async function () {
|
||||
const { data } = await servers[0].videos.listMyVideos({ token: userToken1 })
|
||||
|
||||
expect(data).to.have.lengthOf(1)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 1')
|
||||
expect(v).not.to.be.undefined
|
||||
})
|
||||
|
||||
it('Should hide its comments', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
|
||||
const threads = data.filter(t => t.isDeleted === false)
|
||||
|
||||
expect(threads).to.have.lengthOf(1)
|
||||
expect(threads[0].totalReplies).to.equal(1)
|
||||
|
||||
const t = threads.find(t => t.text === 'comment user 1')
|
||||
expect(t).to.be.undefined
|
||||
|
||||
for (const thread of threads) {
|
||||
const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
|
||||
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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'absence')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list blocked accounts', async function () {
|
||||
{
|
||||
const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
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')
|
||||
expect(block.blockedAccount.name).to.equal('user2')
|
||||
expect(block.blockedAccount.host).to.equal('' + servers[1].host)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
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')
|
||||
expect(block.blockedAccount.name).to.equal('user1')
|
||||
expect(block.blockedAccount.host).to.equal('' + servers[0].host)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should search blocked accounts', async function () {
|
||||
const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
expect(body.data[0].blockedAccount.name).to.equal('user2')
|
||||
})
|
||||
|
||||
it('Should get blocked status', async function () {
|
||||
const remoteHandle = 'user2@' + servers[1].host
|
||||
const localHandle = 'user1@' + servers[0].host
|
||||
const unknownHandle = 'user5@' + servers[0].host
|
||||
|
||||
for (const token of [ undefined, servers[0].accessToken ]) {
|
||||
const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(3)
|
||||
|
||||
for (const handle of [ localHandle, remoteHandle ]) {
|
||||
expect(status.accounts[handle].blockedByUser).to.be.false
|
||||
expect(status.accounts[handle].blockedByServer).to.be.true
|
||||
}
|
||||
|
||||
expect(status.accounts[unknownHandle].blockedByUser).to.be.false
|
||||
expect(status.accounts[unknownHandle].blockedByServer).to.be.false
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should unblock the remote account', async function () {
|
||||
await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should display its videos', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
const { data } = await servers[0].videos.listWithToken({ token })
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
const v = data.find(v => v.name === 'video user 2')
|
||||
expect(v).not.to.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should unblock the local account', async function () {
|
||||
await command.removeFromServerBlocklist({ account: 'user1' })
|
||||
})
|
||||
|
||||
it('Should display its comments', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
await checkAllComments(servers[0], 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@' + servers[0].host
|
||||
}
|
||||
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], token)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list the comments', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
await checkAllComments(servers[0], token, videoUUID1)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should block a remote server', async function () {
|
||||
await command.addToServerBlocklist({ server: '' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should hide its videos', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
const requests = [
|
||||
servers[0].videos.list(),
|
||||
servers[0].videos.listWithToken({ token })
|
||||
]
|
||||
|
||||
for (const req of requests) {
|
||||
const { data } = await req
|
||||
expect(data).to.have.lengthOf(3)
|
||||
|
||||
const v1 = data.find(v => v.name === 'video user 2')
|
||||
const v2 = data.find(v => v.name === 'video server 2')
|
||||
|
||||
expect(v1).to.be.undefined
|
||||
expect(v2).to.be.undefined
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should hide its comments', async function () {
|
||||
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
||||
|
||||
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
||||
})
|
||||
|
||||
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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'absence')
|
||||
}
|
||||
|
||||
{
|
||||
const now = new Date()
|
||||
await servers[1].follows.unfollow({ target: servers[0] })
|
||||
await waitJobs(servers)
|
||||
await servers[1].follows.follow({ hosts: [ servers[0].host ] })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
|
||||
const commentNotifications = data.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 body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
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('' + servers[1].host)
|
||||
})
|
||||
|
||||
it('Should search blocked servers', async function () {
|
||||
const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
|
||||
})
|
||||
|
||||
it('Should get blocklist status', async function () {
|
||||
const blockedServer = servers[1].host
|
||||
const notBlockedServer = 'example.com'
|
||||
|
||||
for (const token of [ undefined, servers[0].accessToken ]) {
|
||||
const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] })
|
||||
expect(Object.keys(status.accounts)).to.have.lengthOf(0)
|
||||
|
||||
expect(Object.keys(status.hosts)).to.have.lengthOf(2)
|
||||
expect(status.hosts[blockedServer].blockedByUser).to.be.false
|
||||
expect(status.hosts[blockedServer].blockedByServer).to.be.true
|
||||
|
||||
expect(status.hosts[notBlockedServer].blockedByUser).to.be.false
|
||||
expect(status.hosts[notBlockedServer].blockedByServer).to.be.false
|
||||
}
|
||||
})
|
||||
|
||||
it('Should unblock the remote server', async function () {
|
||||
await command.removeFromServerBlocklist({ server: '' + servers[1].host })
|
||||
})
|
||||
|
||||
it('Should list all videos', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
await checkAllVideos(servers[0], token)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list the comments', async function () {
|
||||
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
||||
await checkAllComments(servers[0], 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@' + servers[0].host
|
||||
}
|
||||
await checkCommentNotification(servers[0], comment, 'presence')
|
||||
}
|
||||
|
||||
{
|
||||
const now = new Date()
|
||||
await servers[1].follows.unfollow({ target: servers[0] })
|
||||
await waitJobs(servers)
|
||||
await servers[1].follows.follow({ hosts: [ servers[0].host ] })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
|
||||
const commentNotifications = data.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)
|
||||
})
|
||||
})
|
||||
617
packages/tests/src/api/moderation/comment-approval.ts
Normal file
617
packages/tests/src/api/moderation/comment-approval.ts
Normal file
@@ -0,0 +1,617 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import {
|
||||
ActivityApproveReply,
|
||||
ActivityPubOrderedCollection,
|
||||
HttpStatusCode,
|
||||
UserRole,
|
||||
VideoCommentObject,
|
||||
VideoCommentPolicy,
|
||||
VideoCommentPolicyType,
|
||||
VideoPrivacy
|
||||
} from '@peertube/peertube-models'
|
||||
import {
|
||||
PeerTubeServer,
|
||||
cleanupTests,
|
||||
createMultipleServers,
|
||||
doubleFollow,
|
||||
makeActivityPubGetRequest,
|
||||
makeActivityPubRawRequest,
|
||||
setAccessTokensToServers,
|
||||
setDefaultAccountAvatar,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
import { expectStartWith } from '@tests/shared/checks.js'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test comments approval', function () {
|
||||
let servers: PeerTubeServer[]
|
||||
let userToken: string
|
||||
let anotherUserToken: string
|
||||
let moderatorToken: string
|
||||
|
||||
async function createVideo (commentsPolicy: VideoCommentPolicyType) {
|
||||
const { uuid } = await servers[0].videos.upload({
|
||||
token: userToken,
|
||||
attributes: {
|
||||
name: 'review policy: ' + commentsPolicy,
|
||||
privacy: VideoPrivacy.PUBLIC,
|
||||
commentsPolicy
|
||||
}
|
||||
})
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
return uuid
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
servers = await createMultipleServers(3)
|
||||
await setAccessTokensToServers(servers)
|
||||
await setDefaultAccountAvatar(servers)
|
||||
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
await doubleFollow(servers[0], servers[2])
|
||||
await doubleFollow(servers[1], servers[2])
|
||||
|
||||
userToken = await servers[0].users.generateUserAndToken('user1')
|
||||
anotherUserToken = await servers[0].users.generateUserAndToken('user2')
|
||||
moderatorToken = await servers[0].users.generateUserAndToken('moderator', UserRole.MODERATOR)
|
||||
})
|
||||
|
||||
describe('On video with comments requiring approval', function () {
|
||||
let videoId: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
videoId = await createVideo(VideoCommentPolicy.REQUIRES_APPROVAL)
|
||||
})
|
||||
|
||||
it('Should create a local and remote comment that require approval', async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
await servers[0].comments.createThread({ text: 'local', videoId, token: anotherUserToken })
|
||||
await servers[1].comments.createThread({ text: 'remote', videoId })
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
for (const c of data) {
|
||||
expect(c.heldForReview).to.be.true
|
||||
}
|
||||
})
|
||||
|
||||
it('Should display comments depending on the user', async function () {
|
||||
// Owner see the comments
|
||||
{
|
||||
const { data } = await servers[0].comments.listThreads({ videoId, token: userToken })
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
for (const c of data) {
|
||||
expect(c.heldForReview).to.be.true
|
||||
}
|
||||
}
|
||||
|
||||
// Anonymous doesn't see the comments
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listThreads({ videoId })
|
||||
expect(data).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
// Owner of the comment can see it
|
||||
{
|
||||
const { data } = await servers[1].comments.listThreads({ videoId, token: servers[1].accessToken })
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].heldForReview).to.be.true
|
||||
expect(data[0].text).to.equal('remote')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should create a local and remote reply and require approval', async function () {
|
||||
await servers[0].comments.addReplyToLastThread({ text: 'local reply', token: anotherUserToken })
|
||||
await servers[1].comments.addReplyToLastThread({ text: 'remote reply' })
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
for (const c of data) {
|
||||
expect(c.heldForReview).to.be.true
|
||||
}
|
||||
})
|
||||
|
||||
it('Should approve a thread comment', async function () {
|
||||
{
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const commentId = data.find(c => c.text === 'remote').id
|
||||
await servers[0].comments.approve({ commentId, videoId, token: userToken })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
// Owner and moderators
|
||||
for (const token of [ userToken, moderatorToken ]) {
|
||||
const { data: threads } = await servers[0].comments.listThreads({ videoId, token })
|
||||
expect(threads).to.have.lengthOf(2)
|
||||
|
||||
for (const c of threads) {
|
||||
if (c.text === 'remote') expect(c.heldForReview).to.be.false
|
||||
else expect(c.heldForReview).to.be.true
|
||||
|
||||
const thread = await servers[0].comments.getThread({ videoId, threadId: c.id, token })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.heldForReview).to.equal(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Anonymous
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listThreads({ videoId })
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].heldForReview).to.be.false
|
||||
expect(data[0].text).to.equal('remote')
|
||||
|
||||
const thread = await server.comments.getThread({ videoId, threadId: data[0].id })
|
||||
expect(thread.children).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
// Owner of the comment can see it
|
||||
{
|
||||
const { data } = await servers[1].comments.listThreads({ videoId, token: servers[1].accessToken })
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].heldForReview).to.be.false
|
||||
expect(data[0].text).to.equal('remote')
|
||||
|
||||
const thread = await servers[1].comments.getThread({ videoId, threadId: data[0].id, token: servers[1].accessToken })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.heldForReview).to.equal(true)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should approve a reply comment', async function () {
|
||||
{
|
||||
const commentId = await servers[0].comments.findCommentId({ videoId, text: 'remote reply' })
|
||||
await servers[0].comments.approve({ commentId, videoId, token: userToken })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Owner
|
||||
{
|
||||
const { data } = await servers[0].comments.listThreads({ videoId, token: userToken })
|
||||
expect(data.filter(c => c.heldForReview)).to.have.lengthOf(1)
|
||||
|
||||
const thread = await servers[0].comments.getThreadOf({ videoId, text: 'remote', token: userToken })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.text).to.equal('remote reply')
|
||||
expect(thread.children[0].comment.heldForReview).to.be.false
|
||||
}
|
||||
|
||||
// Other users
|
||||
for (const server of servers) {
|
||||
const thread = await server.comments.getThreadOf({ videoId, text: 'remote' })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.text).to.equal('remote reply')
|
||||
expect(thread.children[0].comment.heldForReview).to.be.false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list and filter on comments awaiting approval', async function () {
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listCommentsOnMyVideos({ videoId, token: userToken })
|
||||
expect(total).to.equal(4)
|
||||
expect(data).to.have.lengthOf(4)
|
||||
}
|
||||
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listCommentsOnMyVideos({ videoId, token: userToken, isHeldForReview: true })
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
expect(data.filter(c => c.heldForReview)).to.have.lengthOf(2)
|
||||
}
|
||||
|
||||
{
|
||||
const { total, data } = await servers[0].comments.listCommentsOnMyVideos({ videoId, token: userToken, isHeldForReview: false })
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
expect(data.filter(c => !c.heldForReview)).to.have.lengthOf(2)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should approve a reply of a non approved reply', async function () {
|
||||
const threadId = await servers[0].comments.findCommentId({ videoId, text: 'local' })
|
||||
|
||||
const { id: replyId } = await servers[0].comments.addReply({
|
||||
videoId,
|
||||
toCommentId: await servers[0].comments.findCommentId({ videoId, text: 'local reply' }),
|
||||
text: 'local reply 2',
|
||||
token: anotherUserToken
|
||||
})
|
||||
|
||||
await servers[0].comments.approve({ commentId: replyId, videoId, token: userToken })
|
||||
await servers[0].comments.approve({ commentId: threadId, videoId, token: userToken })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Owner
|
||||
{
|
||||
const { data } = await servers[0].comments.listThreads({ videoId, token: userToken })
|
||||
expect(data.filter(c => c.heldForReview)).to.have.lengthOf(0)
|
||||
|
||||
const thread = await servers[0].comments.getThreadOf({ videoId, text: 'local', token: userToken })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.text).to.equal('local reply')
|
||||
expect(thread.children[0].comment.heldForReview).to.be.true
|
||||
|
||||
expect(thread.children[0].children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].children[0].comment.text).to.equal('local reply 2')
|
||||
expect(thread.children[0].children[0].comment.heldForReview).to.be.false
|
||||
}
|
||||
|
||||
// Other users
|
||||
for (const server of servers) {
|
||||
const thread = await server.comments.getThreadOf({ videoId, text: 'local' })
|
||||
expect(thread.children).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should have appropriate ActivityPub representation', async function () {
|
||||
const localNonApprovedId = await servers[0].comments.findCommentId({ text: 'local reply', videoId })
|
||||
const localApprovedId = await servers[0].comments.findCommentId({ text: 'local', videoId })
|
||||
const remoteApprovedId = await servers[0].comments.findCommentId({ text: 'remote', videoId })
|
||||
|
||||
{
|
||||
for (const page of [ 1, 2 ]) {
|
||||
const res = await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${videoId}/comments?page=${page}`)
|
||||
const { totalItems, orderedItems } = res.body as ActivityPubOrderedCollection<string>
|
||||
|
||||
expect(totalItems).to.equal(4)
|
||||
expect(orderedItems.some(url => url === `${servers[0].url}/videos/watch/${videoId}/comments/${localNonApprovedId}`)).to.be.false
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
await makeActivityPubGetRequest(
|
||||
servers[0].url,
|
||||
`/videos/watch/${videoId}/comments/${localNonApprovedId}`,
|
||||
HttpStatusCode.NOT_FOUND_404
|
||||
)
|
||||
|
||||
await makeActivityPubGetRequest(
|
||||
servers[0].url,
|
||||
`/videos/watch/${videoId}/comments/${localNonApprovedId}/approve-reply`,
|
||||
HttpStatusCode.NOT_FOUND_404
|
||||
)
|
||||
}
|
||||
|
||||
const toTest = [ { server: servers[0], commentId: localApprovedId }, { server: servers[1], commentId: remoteApprovedId } ]
|
||||
for (const { server, commentId } of toTest) {
|
||||
const res = await makeActivityPubGetRequest(server.url, `/videos/watch/${videoId}/comments/${commentId}`)
|
||||
const { replyApproval } = res.body as VideoCommentObject
|
||||
|
||||
expectStartWith(replyApproval, `${servers[0].url}/videos/watch/${videoId}/comments/`)
|
||||
const res2 = await makeActivityPubRawRequest(replyApproval, HttpStatusCode.OK_200)
|
||||
|
||||
const object = res2.body as ActivityApproveReply
|
||||
expect(object.type).to.equal('ApproveReply')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should remove an approved/non-approved comments', async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
{
|
||||
const commentId = await servers[1].comments.findCommentId({ videoId, text: 'local' })
|
||||
await servers[1].comments.addReply({ videoId, toCommentId: commentId, text: 'remote reply on local' })
|
||||
await waitJobs(servers)
|
||||
}
|
||||
|
||||
for (const text of [ 'remote', 'local reply', 'remote reply on local' ]) {
|
||||
const commentId = await servers[0].comments.findCommentId({ videoId, text })
|
||||
await servers[0].comments.delete({ videoId, commentId })
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
// Owner
|
||||
{
|
||||
const { data } = await servers[0].comments.listThreads({ videoId, token: userToken, sort: '-createdAt' })
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
{
|
||||
const remote = data[0]
|
||||
expect(remote.isDeleted).to.be.true
|
||||
|
||||
const thread = await servers[0].comments.getThread({ videoId, token: userToken, threadId: remote.id })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.text).to.equal('remote reply')
|
||||
}
|
||||
|
||||
{
|
||||
const local = data[1]
|
||||
expect(local.isDeleted).to.be.false
|
||||
|
||||
const thread = await servers[0].comments.getThread({ videoId, token: userToken, threadId: local.id })
|
||||
expect(thread.children).to.have.lengthOf(2)
|
||||
|
||||
{
|
||||
const localReply = thread.children[0]
|
||||
expect(localReply.comment.deletedAt).to.exist
|
||||
expect(localReply.comment.heldForReview).to.be.true
|
||||
expect(localReply.children).to.have.lengthOf(1)
|
||||
|
||||
expect(localReply.children).to.have.lengthOf(1)
|
||||
expect(localReply.children[0].comment.text).to.equal('local reply 2')
|
||||
expect(localReply.children[0].comment.heldForReview).to.be.false
|
||||
expect(localReply.children[0].children).to.have.lengthOf(0)
|
||||
}
|
||||
|
||||
{
|
||||
expect(thread.children[1].comment.deletedAt).to.exist
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Other users
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listThreads({ videoId, sort: '-createdAt' })
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
{
|
||||
const remote = data[0]
|
||||
expect(remote.isDeleted).to.be.true
|
||||
|
||||
const thread = await server.comments.getThread({ videoId, threadId: remote.id })
|
||||
expect(thread.children).to.have.lengthOf(1)
|
||||
expect(thread.children[0].comment.text).to.equal('remote reply')
|
||||
}
|
||||
|
||||
{
|
||||
const local = data[1]
|
||||
expect(local.isDeleted).to.be.false
|
||||
|
||||
const thread = await server.comments.getThread({ videoId, threadId: local.id })
|
||||
// Anonymous users cannot see the thread because the delete comment was held for review
|
||||
expect(thread.children).to.have.lengthOf(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('Should not require review for video uploader, admins and moderators', async function () {
|
||||
for (const token of [ userToken, moderatorToken, servers[0].accessToken ]) {
|
||||
await servers[0].comments.createThread({ videoId, text: 'right', token })
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.comments.listThreads({ videoId, sort: '-createdAt' })
|
||||
expect(data.filter(c => c.text === 'right')).to.have.lengthOf(3)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('On video with comments with some tags requiring approval', function () {
|
||||
let videoId: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(30000)
|
||||
|
||||
videoId = await createVideo(VideoCommentPolicy.ENABLED)
|
||||
})
|
||||
|
||||
it('Should only have built-in auto tag policies and no policies set', async function () {
|
||||
const { review } = await servers[0].autoTags.getCommentPolicies({ accountName: 'user1', token: userToken })
|
||||
expect(review).to.have.lengthOf(0)
|
||||
|
||||
const { available } = await servers[0].autoTags.getAccountAvailable({ accountName: 'user1', token: userToken })
|
||||
expect(available.map(a => a.name)).to.deep.equal([ 'external-link' ])
|
||||
})
|
||||
|
||||
it('Should add watched words and so available tag policies', async function () {
|
||||
await servers[0].watchedWordsLists.createList({
|
||||
token: userToken,
|
||||
listName: 'forbidden-list',
|
||||
words: [ 'forbidden' ],
|
||||
accountName: 'user1'
|
||||
})
|
||||
|
||||
await servers[0].watchedWordsLists.createList({
|
||||
token: userToken,
|
||||
listName: 'allowed-list',
|
||||
words: [ 'allowed' ],
|
||||
accountName: 'user1'
|
||||
})
|
||||
|
||||
const { review } = await servers[0].autoTags.getCommentPolicies({ accountName: 'user1', token: userToken })
|
||||
expect(review).to.have.lengthOf(0)
|
||||
|
||||
const { available } = await servers[0].autoTags.getAccountAvailable({ accountName: 'user1', token: userToken })
|
||||
expect(available.map(a => a.name)).to.have.deep.members([ 'external-link', 'forbidden-list', 'allowed-list' ])
|
||||
})
|
||||
|
||||
it('Should update policies', async function () {
|
||||
await servers[0].autoTags.updateCommentPolicies({
|
||||
accountName: 'user1',
|
||||
review: [ 'external-link', 'forbidden-list' ],
|
||||
token: userToken
|
||||
})
|
||||
|
||||
const { review } = await servers[0].autoTags.getCommentPolicies({ accountName: 'user1', token: userToken })
|
||||
expect(review).to.have.deep.members([ 'external-link', 'forbidden-list' ])
|
||||
})
|
||||
|
||||
it('Should publish a comment without approval', async function () {
|
||||
const threadText = '1 - framasoft and allowed'
|
||||
const replyText = '1 - frama and allowed'
|
||||
|
||||
await servers[0].comments.createThread({ token: anotherUserToken, videoId, text: threadText })
|
||||
await waitJobs(servers)
|
||||
|
||||
const commentId = await servers[1].comments.findCommentId({ videoId, text: threadText })
|
||||
await servers[1].comments.addReply({ text: replyText, videoId, toCommentId: commentId })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const t = data.find(c => c.text === threadText)
|
||||
const r = data.find(c => c.text === replyText)
|
||||
|
||||
expect(t.automaticTags).to.have.members([ 'allowed-list' ])
|
||||
expect(t.heldForReview).to.be.false
|
||||
|
||||
expect(r.automaticTags).to.have.members([ 'allowed-list' ])
|
||||
expect(r.heldForReview).to.be.false
|
||||
})
|
||||
|
||||
it('Should publish a comment with approval', async function () {
|
||||
const threadText = '2 - framasoft.org and allowed'
|
||||
const replyText = '2 - https://framasoft.org and forbidden'
|
||||
|
||||
await servers[1].comments.createThread({ videoId, text: threadText })
|
||||
await waitJobs(servers)
|
||||
|
||||
const commentId = await servers[0].comments.findCommentId({ videoId, text: threadText })
|
||||
await servers[0].comments.addReply({ token: anotherUserToken, text: replyText, videoId, toCommentId: commentId })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const t = data.find(c => c.text === threadText)
|
||||
const r = data.find(c => c.text === replyText)
|
||||
|
||||
expect(t.automaticTags).to.have.members([ 'external-link', 'allowed-list' ])
|
||||
expect(t.heldForReview).to.be.true
|
||||
|
||||
expect(r.automaticTags).to.have.members([ 'external-link', 'forbidden-list' ])
|
||||
expect(r.heldForReview).to.be.true
|
||||
})
|
||||
|
||||
it('Should update policies and not update previously tags set', async function () {
|
||||
await servers[0].autoTags.updateCommentPolicies({ accountName: 'user1', review: [ 'forbidden-list' ], token: userToken })
|
||||
|
||||
const { review } = await servers[0].autoTags.getCommentPolicies({ accountName: 'user1', token: userToken })
|
||||
expect(review).to.have.deep.members([ 'forbidden-list' ])
|
||||
|
||||
const { available } = await servers[0].autoTags.getAccountAvailable({ accountName: 'user1', token: userToken })
|
||||
expect(available.map(a => a.name)).to.have.deep.members([ 'external-link', 'forbidden-list', 'allowed-list' ])
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ videoId, token: userToken })
|
||||
expect(data.filter(c => c.heldForReview)).to.have.lengthOf(2)
|
||||
})
|
||||
|
||||
it('Should publish a comment with and without approval base on the new policies', async function () {
|
||||
const threadText = '3 - framasoft.org and allowed'
|
||||
const replyText = '3 - forbidden'
|
||||
|
||||
await servers[0].comments.createThread({ token: anotherUserToken, videoId, text: threadText })
|
||||
await servers[0].comments.addReplyToLastThread({ token: anotherUserToken, text: replyText })
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const t = data.find(c => c.text === threadText)
|
||||
const r = data.find(c => c.text === replyText)
|
||||
|
||||
expect(t.automaticTags).to.have.members([ 'external-link', 'allowed-list' ])
|
||||
expect(t.heldForReview).to.be.false
|
||||
|
||||
expect(r.automaticTags).to.have.members([ 'forbidden-list' ])
|
||||
expect(r.heldForReview).to.be.true
|
||||
})
|
||||
|
||||
it('Should not require approval for a moderator but it should have the tag set', async function () {
|
||||
await servers[0].comments.createThread({ token: moderatorToken, videoId, text: 'forbidden' })
|
||||
await waitJobs(servers)
|
||||
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const t = data.find(c => c.text === 'forbidden')
|
||||
|
||||
expect(t.automaticTags).to.have.members([ 'forbidden-list' ])
|
||||
expect(t.heldForReview).to.be.false
|
||||
})
|
||||
|
||||
it('Should not have threads waiting for approval before approbation for anonymous users on server 1 and 3', async function () {
|
||||
for (const server of [ servers[0], servers[2] ]) {
|
||||
const { data } = await server.comments.listThreads({ videoId })
|
||||
expect(data).to.have.lengthOf(3)
|
||||
|
||||
expect(data.some(c => c.text === '2 - framasoft.org and allowed')).to.be.false
|
||||
}
|
||||
})
|
||||
|
||||
it('Should see threads waiting for approval before approbation for anonymous users on server 2', async function () {
|
||||
const { data } = await servers[1].comments.listThreads({ videoId })
|
||||
expect(data).to.have.lengthOf(4)
|
||||
|
||||
expect(data.some(c => c.text === '2 - framasoft.org and allowed')).to.be.true
|
||||
expect(data.some(c => c.text === '2 - https://framasoft.org and forbidden')).to.be.false
|
||||
})
|
||||
})
|
||||
|
||||
describe('Comment count with moderation', function () {
|
||||
let videoId: string
|
||||
|
||||
before(async function () {
|
||||
videoId = await createVideo(VideoCommentPolicy.REQUIRES_APPROVAL)
|
||||
})
|
||||
|
||||
it('Should not increment comment count when comment is held for review', async function () {
|
||||
await servers[0].comments.createThread({ token: anotherUserToken, videoId, text: 'held comment' })
|
||||
await waitJobs(servers)
|
||||
|
||||
const video = await servers[0].videos.get({ id: videoId })
|
||||
expect(video.comments).to.equal(0)
|
||||
})
|
||||
|
||||
it('Should increment comment count after approving comment', async function () {
|
||||
// Create a new comment that will be held for review
|
||||
await servers[0].comments.createThread({ token: anotherUserToken, videoId, text: 'test comment' })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Get the held comment
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const heldComment = data.find(c => c.text === 'test comment')
|
||||
expect(heldComment.heldForReview).to.be.true
|
||||
|
||||
// Verify initial count is 0
|
||||
let video = await servers[0].videos.get({ id: videoId })
|
||||
expect(video.comments).to.equal(0)
|
||||
|
||||
// Approve the comment
|
||||
await servers[0].comments.approve({ token: userToken, videoId, commentId: heldComment.id })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Verify count incremented after approval
|
||||
video = await servers[0].videos.get({ id: videoId })
|
||||
expect(video.comments).to.equal(1)
|
||||
})
|
||||
|
||||
it('Should not increment comment count when deleting held comment', async function () {
|
||||
// Get initial comment count
|
||||
let video = await servers[0].videos.get({ id: videoId })
|
||||
const initialCount = video.comments
|
||||
|
||||
// Create a new comment that will be held for review
|
||||
await servers[0].comments.createThread({ token: anotherUserToken, videoId, text: 'to be deleted' })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Get the held comment
|
||||
const { data } = await servers[0].comments.listCommentsOnMyVideos({ token: userToken })
|
||||
const heldComment = data.find(c => c.text === 'to be deleted')
|
||||
expect(heldComment.heldForReview).to.be.true
|
||||
|
||||
// Delete the held comment
|
||||
await servers[0].comments.delete({ token: userToken, videoId, commentId: heldComment.id })
|
||||
await waitJobs(servers)
|
||||
|
||||
// Verify count remains unchanged after deleting held comment
|
||||
video = await servers[0].videos.get({ id: videoId })
|
||||
expect(video.comments).to.equal(initialCount)
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
6
packages/tests/src/api/moderation/index.ts
Normal file
6
packages/tests/src/api/moderation/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from './abuses.js'
|
||||
export * from './automatic-tags.js'
|
||||
export * from './blocklist-notification.js'
|
||||
export * from './blocklist.js'
|
||||
export * from './video-blacklist.js'
|
||||
export * from './watched-words.js'
|
||||
448
packages/tests/src/api/moderation/video-blacklist.ts
Normal file
448
packages/tests/src/api/moderation/video-blacklist.ts
Normal file
@@ -0,0 +1,448 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { sortObjectComparator } from '@peertube/peertube-core-utils'
|
||||
import { HttpStatusCode, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType, VideoPrivacy } from '@peertube/peertube-models'
|
||||
import {
|
||||
BlacklistCommand,
|
||||
cleanupTests,
|
||||
createMultipleServers,
|
||||
doubleFollow, makeActivityPubGetRequest,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultChannelAvatar,
|
||||
waitJobs
|
||||
} from '@peertube/peertube-server-commands'
|
||||
import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test video blacklist', function () {
|
||||
let servers: PeerTubeServer[] = []
|
||||
let videoId: number
|
||||
let command: BlacklistCommand
|
||||
|
||||
async function blacklistVideosOnServer (server: PeerTubeServer) {
|
||||
const { data } = await server.videos.list()
|
||||
|
||||
for (const video of data) {
|
||||
await server.blacklist.add({ videoId: video.id, reason: 'super reason' })
|
||||
}
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
// Run servers
|
||||
servers = await createMultipleServers(2)
|
||||
|
||||
// Get the access tokens
|
||||
await setAccessTokensToServers(servers)
|
||||
|
||||
// Server 1 and server 2 follow each other
|
||||
await doubleFollow(servers[0], servers[1])
|
||||
await setDefaultChannelAvatar(servers[0])
|
||||
|
||||
// Upload 2 videos on server 2
|
||||
await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
|
||||
await servers[1].videos.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
|
||||
|
||||
// Wait videos propagation, server 2 has transcoding enabled
|
||||
await waitJobs(servers)
|
||||
|
||||
command = servers[0].blacklist
|
||||
|
||||
// Blacklist the two videos on server 1
|
||||
await blacklistVideosOnServer(servers[0])
|
||||
})
|
||||
|
||||
describe('When listing/searching videos', function () {
|
||||
|
||||
it('Should not have the video blacklisted in videos list/search on server 1', async function () {
|
||||
{
|
||||
const { total, data } = await servers[0].videos.list()
|
||||
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.be.an('array')
|
||||
expect(data.length).to.equal(0)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await servers[0].search.searchVideos({ search: 'video' })
|
||||
|
||||
expect(body.total).to.equal(0)
|
||||
expect(body.data).to.be.an('array')
|
||||
expect(body.data.length).to.equal(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should have the blacklisted video in videos list/search on server 2', async function () {
|
||||
{
|
||||
const { total, data } = await servers[1].videos.list()
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.be.an('array')
|
||||
expect(data.length).to.equal(2)
|
||||
}
|
||||
|
||||
{
|
||||
const body = await servers[1].search.searchVideos({ search: 'video' })
|
||||
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data).to.be.an('array')
|
||||
expect(body.data.length).to.equal(2)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('When listing manually blacklisted videos', function () {
|
||||
|
||||
it('Should display all the blacklisted videos', async function () {
|
||||
const body = await command.list()
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(2)
|
||||
|
||||
for (const blacklistedVideo of blacklistedVideos) {
|
||||
expect(blacklistedVideo.reason).to.equal('super reason')
|
||||
videoId = blacklistedVideo.video.id
|
||||
}
|
||||
})
|
||||
|
||||
it('Should display all the blacklisted videos when applying manual type filter', async function () {
|
||||
const body = await command.list({ type: VideoBlacklistType.MANUAL })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(2)
|
||||
})
|
||||
|
||||
it('Should display nothing when applying automatic type filter', async function () {
|
||||
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(0)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('Should get the correct sort when sorting by descending id', async function () {
|
||||
const body = await command.list({ sort: '-id' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(2)
|
||||
|
||||
const result = [ ...body.data ].sort(sortObjectComparator('id', 'desc'))
|
||||
expect(blacklistedVideos).to.deep.equal(result)
|
||||
})
|
||||
|
||||
it('Should get the correct sort when sorting by descending video name', async function () {
|
||||
const body = await command.list({ sort: '-name' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(2)
|
||||
|
||||
const result = [ ...body.data ].sort(sortObjectComparator('name', 'desc'))
|
||||
expect(blacklistedVideos).to.deep.equal(result)
|
||||
})
|
||||
|
||||
it('Should get the correct sort when sorting by ascending creation date', async function () {
|
||||
const body = await command.list({ sort: 'createdAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
expect(blacklistedVideos).to.be.an('array')
|
||||
expect(blacklistedVideos.length).to.equal(2)
|
||||
|
||||
const result = [ ...body.data ].sort(sortObjectComparator('createdAt', 'asc'))
|
||||
expect(blacklistedVideos).to.deep.equal(result)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When updating blacklisted videos', function () {
|
||||
|
||||
it('Should change the reason', async function () {
|
||||
await command.update({ videoId, reason: 'my super reason updated' })
|
||||
|
||||
const body = await command.list({ sort: '-name' })
|
||||
const video = body.data.find(b => b.video.id === videoId)
|
||||
|
||||
expect(video.reason).to.equal('my super reason updated')
|
||||
})
|
||||
})
|
||||
|
||||
describe('When listing my videos', function () {
|
||||
it('Should display blacklisted videos', async function () {
|
||||
await blacklistVideosOnServer(servers[1])
|
||||
|
||||
const { total, data } = await servers[1].videos.listMyVideos()
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
for (const video of data) {
|
||||
expect(video.blacklisted).to.be.true
|
||||
expect(video.blacklistedReason).to.equal('super reason')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('When removing a blacklisted video', function () {
|
||||
let videoToRemove: VideoBlacklist
|
||||
let blacklist = []
|
||||
|
||||
it('Should not have any video in videos list on server 1', async function () {
|
||||
const { total, data } = await servers[0].videos.list()
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.be.an('array')
|
||||
expect(data.length).to.equal(0)
|
||||
})
|
||||
|
||||
it('Should remove a video from the blacklist on server 1', async function () {
|
||||
// Get one video in the blacklist
|
||||
const body = await command.list({ sort: '-name' })
|
||||
videoToRemove = body.data[0]
|
||||
blacklist = body.data.slice(1)
|
||||
|
||||
// Remove it
|
||||
await command.remove({ videoId: videoToRemove.video.id })
|
||||
})
|
||||
|
||||
it('Should have the ex-blacklisted video in videos list on server 1', async function () {
|
||||
const { total, data } = await servers[0].videos.list()
|
||||
expect(total).to.equal(1)
|
||||
|
||||
expect(data).to.be.an('array')
|
||||
expect(data.length).to.equal(1)
|
||||
|
||||
expect(data[0].name).to.equal(videoToRemove.video.name)
|
||||
expect(data[0].id).to.equal(videoToRemove.video.id)
|
||||
})
|
||||
|
||||
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
|
||||
const body = await command.list({ sort: '-name' })
|
||||
expect(body.total).to.equal(1)
|
||||
|
||||
const videos = body.data
|
||||
expect(videos).to.be.an('array')
|
||||
expect(videos.length).to.equal(1)
|
||||
expect(videos).to.deep.equal(blacklist)
|
||||
})
|
||||
})
|
||||
|
||||
describe('When blacklisting local videos', function () {
|
||||
let video3UUID: string
|
||||
let video4UUID: string
|
||||
|
||||
before(async function () {
|
||||
{
|
||||
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } })
|
||||
video3UUID = uuid
|
||||
}
|
||||
{
|
||||
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } })
|
||||
video4UUID = uuid
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should blacklist video 3 and keep it federated', async function () {
|
||||
await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
{
|
||||
const { data } = await servers[0].videos.list()
|
||||
expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
|
||||
}
|
||||
|
||||
{
|
||||
const { data } = await servers[1].videos.list()
|
||||
expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should unfederate the video', async function () {
|
||||
await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.videos.list()
|
||||
expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should have the video unfederated even after an Update AP message', async function () {
|
||||
await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.videos.list()
|
||||
expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
it('Should have the correct video blacklist unfederate attribute', async function () {
|
||||
const body = await command.list({ sort: 'createdAt' })
|
||||
|
||||
const blacklistedVideos = body.data
|
||||
const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
|
||||
const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
|
||||
|
||||
expect(video3Blacklisted.unfederated).to.be.false
|
||||
expect(video4Blacklisted.unfederated).to.be.true
|
||||
})
|
||||
|
||||
it('Should not have AP comments/announces/likes/dislikes', async function () {
|
||||
await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${video3UUID}/comments`, HttpStatusCode.UNAUTHORIZED_401)
|
||||
await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${video3UUID}/announces`, HttpStatusCode.UNAUTHORIZED_401)
|
||||
await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${video3UUID}/likes`, HttpStatusCode.UNAUTHORIZED_401)
|
||||
await makeActivityPubGetRequest(servers[0].url, `/videos/watch/${video3UUID}/dislikes`, HttpStatusCode.UNAUTHORIZED_401)
|
||||
})
|
||||
|
||||
it('Should remove the video from blacklist and refederate the video', async function () {
|
||||
await command.remove({ videoId: video4UUID })
|
||||
|
||||
await waitJobs(servers)
|
||||
|
||||
for (const server of servers) {
|
||||
const { data } = await server.videos.list()
|
||||
expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('When auto blacklist videos', function () {
|
||||
let userWithoutFlag: string
|
||||
let userWithFlag: string
|
||||
let channelOfUserWithoutFlag: number
|
||||
|
||||
async function checkBlacklist (videoUUID: string, password?: string) {
|
||||
await servers[0].videos.get({ id: videoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
||||
|
||||
if (password) {
|
||||
await servers[0].videos.getWithPassword({ id: videoUUID, password, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
||||
}
|
||||
}
|
||||
|
||||
before(async function () {
|
||||
await servers[0].config.enableAutoBlacklist()
|
||||
|
||||
{
|
||||
const user = { username: 'user_without_flag', password: 'password' }
|
||||
await servers[0].users.create({
|
||||
username: user.username,
|
||||
adminFlags: UserAdminFlag.NONE,
|
||||
password: user.password,
|
||||
role: UserRole.USER
|
||||
})
|
||||
|
||||
userWithoutFlag = await servers[0].login.getAccessToken(user)
|
||||
|
||||
const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag })
|
||||
channelOfUserWithoutFlag = videoChannels[0].id
|
||||
}
|
||||
|
||||
{
|
||||
const user = { username: 'user_with_flag', password: 'password' }
|
||||
await servers[0].users.create({
|
||||
username: user.username,
|
||||
adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
|
||||
password: user.password,
|
||||
role: UserRole.USER
|
||||
})
|
||||
|
||||
userWithFlag = await servers[0].login.getAccessToken(user)
|
||||
}
|
||||
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should auto blacklist a public video on upload', async function () {
|
||||
const video = await servers[0].videos.quickUpload({ token: userWithoutFlag, name: 'blacklisted 1' })
|
||||
|
||||
const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(1)
|
||||
expect(body.data[0].video.name).to.equal('blacklisted 1')
|
||||
|
||||
await checkBlacklist(video.uuid)
|
||||
})
|
||||
|
||||
it('Should auto blacklist an unlisted video on upload', async function () {
|
||||
const video = await servers[0].videos.quickUpload({ token: userWithoutFlag, name: 'blacklisted 2', privacy: VideoPrivacy.UNLISTED })
|
||||
|
||||
const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(2)
|
||||
expect(body.data[0].video.name).to.equal('blacklisted 2')
|
||||
|
||||
await checkBlacklist(video.uuid)
|
||||
})
|
||||
|
||||
it('Should auto blacklist a password protected video on upload', async function () {
|
||||
const video = await servers[0].videos.upload({
|
||||
token: userWithoutFlag,
|
||||
attributes: {
|
||||
name: 'blacklisted 3',
|
||||
privacy: VideoPrivacy.PASSWORD_PROTECTED,
|
||||
videoPasswords: [ 'toto' ]
|
||||
}
|
||||
})
|
||||
|
||||
const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(3)
|
||||
expect(body.data[0].video.name).to.equal('blacklisted 3')
|
||||
|
||||
await checkBlacklist(video.uuid, 'toto')
|
||||
})
|
||||
|
||||
it('Should auto blacklist a video on URL import', async function () {
|
||||
const attributes = {
|
||||
targetUrl: FIXTURE_URLS.goodVideo,
|
||||
name: 'URL import',
|
||||
channelId: channelOfUserWithoutFlag
|
||||
}
|
||||
const { video } = await servers[0].videoImports.importVideo({ token: userWithoutFlag, attributes })
|
||||
|
||||
const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(4)
|
||||
expect(body.data[0].video.name).to.equal('URL import')
|
||||
|
||||
await checkBlacklist(video.uuid)
|
||||
})
|
||||
|
||||
it('Should auto blacklist a video on torrent import', async function () {
|
||||
const attributes = {
|
||||
magnetUri: FIXTURE_URLS.magnet,
|
||||
name: 'Torrent import',
|
||||
channelId: channelOfUserWithoutFlag
|
||||
}
|
||||
const { video } = await servers[0].videoImports.importVideo({ token: userWithoutFlag, attributes })
|
||||
|
||||
const body = await command.list({ sort: '-createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(5)
|
||||
expect(body.data[0].video.name).to.equal('Torrent import')
|
||||
|
||||
await checkBlacklist(video.uuid)
|
||||
})
|
||||
|
||||
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
|
||||
await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
|
||||
|
||||
const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
|
||||
expect(body.total).to.equal(5)
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
})
|
||||
189
packages/tests/src/api/moderation/watched-words.ts
Normal file
189
packages/tests/src/api/moderation/watched-words.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import {
|
||||
cleanupTests,
|
||||
createSingleServer,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
setDefaultAccountAvatar
|
||||
} from '@peertube/peertube-server-commands'
|
||||
import { expect } from 'chai'
|
||||
|
||||
describe('Test watched words', function () {
|
||||
let server: PeerTubeServer
|
||||
let userToken: string
|
||||
|
||||
before(async function () {
|
||||
this.timeout(120000)
|
||||
|
||||
server = await createSingleServer(1)
|
||||
await setAccessTokensToServers([ server ])
|
||||
await setDefaultAccountAvatar([ server ])
|
||||
|
||||
userToken = await server.users.generateUserAndToken('user1')
|
||||
})
|
||||
|
||||
function runTests (mode: 'server' | 'account') {
|
||||
let listId: number
|
||||
let accountName: string
|
||||
let token: string
|
||||
|
||||
before(() => {
|
||||
accountName = mode === 'server'
|
||||
? undefined
|
||||
: 'user1'
|
||||
|
||||
token = mode === 'server'
|
||||
? server.accessToken
|
||||
: userToken
|
||||
})
|
||||
|
||||
it('Should list empty watched words', async function () {
|
||||
const { data, total } = await server.watchedWordsLists.listWordsLists({ token, accountName })
|
||||
|
||||
expect(total).to.equal(0)
|
||||
expect(data).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it('Should add watched words lists', async function () {
|
||||
{
|
||||
const { watchedWordsList } = await server.watchedWordsLists.createList({
|
||||
token,
|
||||
listName: 'list user one',
|
||||
words: [ 'word1' ],
|
||||
accountName
|
||||
})
|
||||
|
||||
listId = watchedWordsList.id
|
||||
}
|
||||
|
||||
{
|
||||
await server.watchedWordsLists.createList({
|
||||
token,
|
||||
listName: 'list user two',
|
||||
words: [ 'word2', 'word3' ],
|
||||
accountName
|
||||
})
|
||||
}
|
||||
|
||||
if (mode === 'account') {
|
||||
await server.watchedWordsLists.createList({
|
||||
listName: 'list one',
|
||||
words: [ 'word4', 'word5' ],
|
||||
accountName: 'root'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('Should list watched words', async function () {
|
||||
if (mode === 'account') {
|
||||
const { data, total } = await server.watchedWordsLists.listWordsLists({ accountName: 'root' })
|
||||
|
||||
expect(total).to.equal(1)
|
||||
|
||||
expect(data).to.have.lengthOf(1)
|
||||
expect(data[0].id).to.exist
|
||||
expect(data[0].createdAt).to.exist
|
||||
expect(data[0].updatedAt).to.exist
|
||||
expect(data[0].listName).to.equal('list one')
|
||||
expect(data[0].words).to.deep.equal([ 'word4', 'word5' ])
|
||||
}
|
||||
|
||||
// With sort, start, count
|
||||
{
|
||||
const { data, total } = await server.watchedWordsLists.listWordsLists({
|
||||
token,
|
||||
accountName,
|
||||
sort: 'createdAt'
|
||||
})
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
expect(data[0].listName).to.equal('list user one')
|
||||
expect(data[0].words).to.deep.equal([ 'word1' ])
|
||||
|
||||
expect(data[1].listName).to.equal('list user two')
|
||||
expect(data[1].words).to.deep.equal([ 'word2', 'word3' ])
|
||||
}
|
||||
|
||||
{
|
||||
const { data, total } = await server.watchedWordsLists.listWordsLists({
|
||||
token,
|
||||
accountName,
|
||||
sort: '-listName'
|
||||
})
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(2)
|
||||
|
||||
expect(data[0].listName).to.equal('list user two')
|
||||
expect(data[1].listName).to.equal('list user one')
|
||||
}
|
||||
|
||||
{
|
||||
const { data, total } = await server.watchedWordsLists.listWordsLists({
|
||||
accountName,
|
||||
token,
|
||||
sort: '-listName',
|
||||
start: 1,
|
||||
count: 1
|
||||
})
|
||||
|
||||
expect(total).to.equal(2)
|
||||
expect(data).to.have.lengthOf(1)
|
||||
|
||||
expect(data[0].listName).to.equal('list user one')
|
||||
}
|
||||
})
|
||||
|
||||
it('Should update watched words lists', async function () {
|
||||
await server.watchedWordsLists.updateList({
|
||||
listId,
|
||||
token,
|
||||
accountName,
|
||||
words: [ 'updated-word1', 'updated-word2' ]
|
||||
})
|
||||
|
||||
await server.watchedWordsLists.updateList({
|
||||
listId,
|
||||
token,
|
||||
accountName,
|
||||
listName: 'updated-list'
|
||||
})
|
||||
|
||||
const { data } = await server.watchedWordsLists.listWordsLists({ token, accountName })
|
||||
const list = data.find(l => l.id === listId)
|
||||
|
||||
expect(list.listName).to.equal('updated-list')
|
||||
expect(list.words).to.deep.equal([ 'updated-word1', 'updated-word2' ])
|
||||
})
|
||||
|
||||
it('Should delete watched words lists', async function () {
|
||||
await server.watchedWordsLists.deleteList({
|
||||
listId,
|
||||
token,
|
||||
accountName
|
||||
})
|
||||
|
||||
const { total, data } = await server.watchedWordsLists.listWordsLists({ token, accountName })
|
||||
expect(total).to.equal(1)
|
||||
expect(data).to.have.lengthOf(1)
|
||||
|
||||
const list = data.find(l => l.id === listId)
|
||||
expect(list).to.not.exist
|
||||
})
|
||||
}
|
||||
|
||||
describe('Managing account watched words', function () {
|
||||
runTests('account')
|
||||
})
|
||||
|
||||
describe('Managing instance watched words', function () {
|
||||
runTests('server')
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests([ server ])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user