2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2022-08-17 15:44:32 +02:00
|
|
|
import { expect } from 'chai'
|
2022-02-28 08:34:43 +01:00
|
|
|
import { UserNotificationType } from '@shared/models'
|
2018-10-15 13:03:04 +02:00
|
|
|
import {
|
2021-07-07 16:02:46 +02:00
|
|
|
BlocklistCommand,
|
2019-04-24 15:10:37 +02:00
|
|
|
cleanupTests,
|
2021-07-09 14:15:11 +02:00
|
|
|
CommentsCommand,
|
2021-07-16 09:47:51 +02:00
|
|
|
createMultipleServers,
|
2021-07-16 14:27:30 +02:00
|
|
|
doubleFollow,
|
2021-07-16 09:47:51 +02:00
|
|
|
PeerTubeServer,
|
2021-05-11 11:27:40 +02:00
|
|
|
setAccessTokensToServers,
|
2022-02-28 08:34:43 +01:00
|
|
|
setDefaultAccountAvatar,
|
2021-05-11 11:27:40 +02:00
|
|
|
waitJobs
|
2021-12-17 09:29:23 +01:00
|
|
|
} from '@shared/server-commands'
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function checkAllVideos (server: PeerTubeServer, token: string) {
|
2018-10-15 16:43:14 +02:00
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.videos.listWithToken({ token })
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(5)
|
2018-10-15 16:43:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.videos.list()
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(5)
|
2018-10-15 16:43:14 +02:00
|
|
|
}
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
const threads = data.filter(t => t.isDeleted === false)
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(threads).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
for (const thread of threads) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token })
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(tree.children).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 10:35:47 +01:00
|
|
|
async function checkCommentNotification (
|
2021-07-16 09:47:51 +02:00
|
|
|
mainServer: PeerTubeServer,
|
|
|
|
comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
|
2019-12-19 10:35:47 +01:00
|
|
|
check: 'presence' | 'absence'
|
|
|
|
) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const command = comment.server.comments
|
2021-07-09 14:15:11 +02:00
|
|
|
|
|
|
|
const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text })
|
2019-12-19 10:35:47 +01:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
await waitJobs([ mainServer, comment.server ])
|
2019-12-19 10:35:47 +01:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await mainServer.notifications.list({ start: 0, count: 30 })
|
2021-07-09 16:23:01 +02:00
|
|
|
const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt)
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
|
|
|
|
else expect(commentNotifications).to.have.lengthOf(0)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId })
|
2019-12-19 10:35:47 +01:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
await waitJobs([ mainServer, comment.server ])
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
describe('Test blocklist', function () {
|
2021-07-16 09:47:51 +02:00
|
|
|
let servers: PeerTubeServer[]
|
2018-10-15 13:03:04 +02:00
|
|
|
let videoUUID1: string
|
|
|
|
let videoUUID2: string
|
2020-05-22 17:06:26 +02:00
|
|
|
let videoUUID3: string
|
2018-10-15 13:03:04 +02:00
|
|
|
let userToken1: string
|
|
|
|
let userModeratorToken: string
|
|
|
|
let userToken2: string
|
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
let command: BlocklistCommand
|
2021-07-09 14:15:11 +02:00
|
|
|
let commentsCommand: CommentsCommand[]
|
2021-07-07 16:02:46 +02:00
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
before(async function () {
|
2021-03-22 09:49:23 +01:00
|
|
|
this.timeout(120000)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:47:51 +02:00
|
|
|
servers = await createMultipleServers(3)
|
2018-10-15 13:03:04 +02:00
|
|
|
await setAccessTokensToServers(servers)
|
2022-02-28 08:34:43 +01:00
|
|
|
await setDefaultAccountAvatar(servers)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
command = servers[0].blocklist
|
|
|
|
commentsCommand = servers.map(s => s.comments)
|
2021-07-09 14:15:11 +02:00
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
{
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({ username: user.username, password: user.password })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
userToken1 = await servers[0].login.getAccessToken(user)
|
|
|
|
await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } })
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'moderator', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].users.create({ username: user.username, password: user.password })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
userModeratorToken = await servers[0].login.getAccessToken(user)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user2', password: 'password' }
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].users.create({ username: user.username, password: user.password })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
userToken2 = await servers[1].login.getAccessToken(user)
|
|
|
|
await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } })
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
|
2021-07-15 10:02:54 +02:00
|
|
|
videoUUID1 = uuid
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
|
2021-07-15 10:02:54 +02:00
|
|
|
videoUUID2 = uuid
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
2020-05-22 17:06:26 +02:00
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
|
2021-07-15 10:02:54 +02:00
|
|
|
videoUUID3 = uuid
|
2020-05-22 17:06:26 +02:00
|
|
|
}
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
2020-05-22 17:06:26 +02:00
|
|
|
await doubleFollow(servers[0], servers[2])
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
{
|
2021-07-09 14:15:11 +02:00
|
|
|
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' })
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-09 14:15:11 +02:00
|
|
|
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' })
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('User blocklist', function () {
|
|
|
|
|
|
|
|
describe('When managing account blocklist', function () {
|
|
|
|
it('Should list all videos', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote account', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.addToMyBlocklist({ account: 'user2@' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken()
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(4)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a local account', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
await command.addToMyBlocklist({ account: 'user1' })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken()
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(3)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 1')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its comments', async function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
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')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(t).to.be.undefined
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
for (const thread of data) {
|
|
|
|
const tree = await commentsCommand[0].getThread({
|
|
|
|
videoId: videoUUID1,
|
|
|
|
threadId: thread.id,
|
|
|
|
token: servers[0].accessToken
|
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(tree.children).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 10:35:47 +01:00
|
|
|
it('Should not have notifications from blocked accounts', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[0],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken1,
|
|
|
|
videoUUID: videoUUID2,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should list all the videos with another user', async function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllVideos(servers[0], userToken1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list blocked accounts', async function () {
|
|
|
|
{
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(2)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
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')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedAccount.host).to.equal('' + servers[1].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(2)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
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')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedAccount.host).to.equal('' + servers[0].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-06-17 16:06:58 +02:00
|
|
|
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')
|
|
|
|
})
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-22 17:06:26 +02:00
|
|
|
it('Should not allow a remote blocked user to comment my videos', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
{
|
2021-07-09 14:15:11 +02:00
|
|
|
await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' })
|
2020-05-22 17:06:26 +02:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' })
|
2020-05-22 17:06:26 +02:00
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' })
|
2020-05-22 17:06:26 +02:00
|
|
|
const message = 'reply by user 2'
|
2021-07-09 14:15:11 +02:00
|
|
|
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' })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Server 2 has all the comments
|
|
|
|
{
|
2021-07-09 14:15:11 +02:00
|
|
|
const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
expect(data).to.have.lengthOf(2)
|
|
|
|
expect(data[0].text).to.equal('uploader')
|
|
|
|
expect(data[1].text).to.equal('comment user 2')
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id })
|
2020-05-22 17:06:26 +02:00
|
|
|
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] ]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
expect(data[0].text).to.equal('uploader')
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0)
|
|
|
|
else expect(tree.children).to.have.lengthOf(1)
|
2020-05-22 17:06:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should unblock the remote account', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken()
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(4)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).not.to.be.undefined
|
|
|
|
})
|
|
|
|
|
2020-05-22 17:06:26 +02:00
|
|
|
it('Should display its comments on my video', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
// Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment
|
|
|
|
if (server.serverNumber === 3) {
|
2021-07-09 14:15:11 +02:00
|
|
|
expect(data).to.have.lengthOf(1)
|
2020-05-22 17:06:26 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
expect(data).to.have.lengthOf(2)
|
|
|
|
expect(data[0].text).to.equal('uploader')
|
|
|
|
expect(data[1].text).to.equal('comment user 2')
|
2020-05-22 17:06:26 +02:00
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id })
|
2020-05-22 17:06:26 +02:00
|
|
|
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')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should unblock the local account', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
await command.removeFromMyBlocklist({ account: 'user1' })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
it('Should have a notification from a non blocked account', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[0],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken1,
|
|
|
|
videoUUID: videoUUID2,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When managing server blocklist', function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should list all videos', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote server', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.addToMyBlocklist({ server: '' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken()
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(3)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v1 = data.find(v => v.name === 'video user 2')
|
|
|
|
const v2 = data.find(v => v.name === 'video server 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
expect(v1).to.be.undefined
|
|
|
|
expect(v2).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all the videos with another user', async function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllVideos(servers[0], userToken1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
2019-12-19 10:35:47 +01:00
|
|
|
it('Should hide its comments', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2019-12-19 10:35:47 +01:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
2019-12-19 10:35:47 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from blocked server', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
it('Should list blocked servers', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(1)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(block.byAccount.displayName).to.equal('root')
|
|
|
|
expect(block.byAccount.name).to.equal('root')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedServer.host).to.equal('' + servers[1].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
2022-06-17 16:06:58 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should unblock the remote server', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.removeFromMyBlocklist({ server: '' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllVideos(servers[0], servers[0].accessToken)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', function () {
|
2021-07-09 14:15:11 +02:00
|
|
|
return checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
it('Should have notification from unblocked server', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Server blocklist', function () {
|
|
|
|
|
|
|
|
describe('When managing account blocklist', function () {
|
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllVideos(servers[0], token)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], token, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote account', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.addToServerBlocklist({ account: 'user2@' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken({ token })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(4)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a local account', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
await command.addToServerBlocklist({ account: 'user1' })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken({ token })
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(3)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 1')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its comments', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token })
|
|
|
|
const threads = data.filter(t => t.isDeleted === false)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
expect(threads).to.have.lengthOf(1)
|
2021-06-08 16:19:09 +02:00
|
|
|
expect(threads[0].totalReplies).to.equal(1)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
const t = threads.find(t => t.text === 'comment user 1')
|
|
|
|
expect(t).to.be.undefined
|
|
|
|
|
|
|
|
for (const thread of threads) {
|
2021-07-09 14:15:11 +02:00
|
|
|
const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token })
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(tree.children).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 10:35:47 +01:00
|
|
|
it('Should not have notification from blocked accounts by instance', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should list blocked accounts', async function () {
|
|
|
|
{
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(2)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
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')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedAccount.host).to.equal('' + servers[1].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(2)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
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')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedAccount.host).to.equal('' + servers[0].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-06-17 16:06:58 +02:00
|
|
|
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')
|
|
|
|
})
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should unblock the remote account', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].videos.listWithToken({ token })
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(data).to.have.lengthOf(4)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v = data.find(v => v.name === 'video user 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(v).not.to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the local account', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
await command.removeFromServerBlocklist({ account: 'user1' })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], token, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
it('Should have notifications from unblocked accounts', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When managing server blocklist', function () {
|
2021-12-06 16:53:00 +01:00
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllVideos(servers[0], token)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], token, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote server', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.addToServerBlocklist({ server: '' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-15 10:02:54 +02:00
|
|
|
const requests = [
|
2021-07-16 09:04:35 +02:00
|
|
|
servers[0].videos.list(),
|
|
|
|
servers[0].videos.listWithToken({ token })
|
2021-07-15 10:02:54 +02:00
|
|
|
]
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
for (const req of requests) {
|
|
|
|
const { data } = await req
|
|
|
|
expect(data).to.have.lengthOf(3)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
const v1 = data.find(v => v.name === 'video user 2')
|
|
|
|
const v2 = data.find(v => v.name === 'video server 2')
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2018-10-15 16:43:14 +02:00
|
|
|
expect(v1).to.be.undefined
|
|
|
|
expect(v2).to.be.undefined
|
|
|
|
}
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 10:35:47 +01:00
|
|
|
it('Should hide its comments', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' })
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], servers[0].accessToken, videoUUID1)
|
2019-12-19 10:35:47 +01:00
|
|
|
|
2021-07-09 14:15:11 +02:00
|
|
|
await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id })
|
2019-12-19 10:35:47 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notification from blocked instances by instance', async function () {
|
2020-05-22 17:06:26 +02:00
|
|
|
this.timeout(50000)
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const now = new Date()
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].follows.unfollow({ target: servers[0] })
|
2020-05-22 17:06:26 +02:00
|
|
|
await waitJobs(servers)
|
2021-07-20 14:15:15 +02:00
|
|
|
await servers[1].follows.follow({ hosts: [ servers[0].host ] })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
|
2021-07-09 16:23:01 +02:00
|
|
|
const commentNotifications = data.filter(n => {
|
|
|
|
return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
|
|
|
|
})
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
expect(commentNotifications).to.have.lengthOf(0)
|
|
|
|
}
|
2019-12-19 10:35:47 +01:00
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
|
|
|
|
it('Should list blocked servers', async function () {
|
2021-07-07 16:02:46 +02:00
|
|
|
const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' })
|
|
|
|
expect(body.total).to.equal(1)
|
2018-10-15 13:03:04 +02:00
|
|
|
|
2021-07-07 16:02:46 +02:00
|
|
|
const block = body.data[0]
|
2018-10-15 13:03:04 +02:00
|
|
|
expect(block.byAccount.displayName).to.equal('peertube')
|
|
|
|
expect(block.byAccount.name).to.equal('peertube')
|
2022-12-09 11:14:47 +01:00
|
|
|
expect(block.blockedServer.host).to.equal('' + servers[1].host)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
2022-06-17 16:06:58 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-12-06 16:53:00 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 13:03:04 +02:00
|
|
|
it('Should unblock the remote server', async function () {
|
2022-12-09 11:14:47 +01:00
|
|
|
await command.removeFromServerBlocklist({ server: '' + servers[1].host })
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllVideos(servers[0], token)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 16:56:52 +01:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2021-07-09 14:15:11 +02:00
|
|
|
await checkAllComments(servers[0], token, videoUUID1)
|
2018-10-15 13:03:04 +02:00
|
|
|
}
|
|
|
|
})
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
it('Should have notification from unblocked instances', async function () {
|
2020-05-22 17:06:26 +02:00
|
|
|
this.timeout(50000)
|
2019-12-19 10:35:47 +01:00
|
|
|
|
|
|
|
{
|
2020-01-31 16:56:52 +01:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 16:56:52 +01:00
|
|
|
server: servers[1],
|
2019-12-19 10:35:47 +01:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2022-12-09 11:14:47 +01:00
|
|
|
text: 'hello @root@' + servers[0].host
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-01-31 16:56:52 +01:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 10:35:47 +01:00
|
|
|
}
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
const now = new Date()
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].follows.unfollow({ target: servers[0] })
|
2020-05-22 17:06:26 +02:00
|
|
|
await waitJobs(servers)
|
2021-07-20 14:15:15 +02:00
|
|
|
await servers[1].follows.follow({ hosts: [ servers[0].host ] })
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data } = await servers[0].notifications.list({ start: 0, count: 30 })
|
2021-07-09 16:23:01 +02:00
|
|
|
const commentNotifications = data.filter(n => {
|
|
|
|
return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString()
|
|
|
|
})
|
2020-05-22 17:06:26 +02:00
|
|
|
|
|
|
|
expect(commentNotifications).to.have.lengthOf(1)
|
|
|
|
}
|
2019-12-19 10:35:47 +01:00
|
|
|
})
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-10-15 13:03:04 +02:00
|
|
|
})
|
|
|
|
})
|