2020-01-31 10:56:52 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import 'mocha'
|
2020-01-31 10:56:52 -05:00
|
|
|
import { AccountBlock, ServerBlock, Video } from '../../../../shared/index'
|
2018-10-15 07:03:04 -04:00
|
|
|
import {
|
2019-04-24 09:10:37 -04:00
|
|
|
cleanupTests,
|
2020-01-31 10:56:52 -05:00
|
|
|
createUser,
|
|
|
|
deleteVideoComment,
|
2018-10-15 07:03:04 -04:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
ServerInfo,
|
|
|
|
uploadVideo,
|
|
|
|
userLogin
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/index'
|
|
|
|
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
|
2020-01-31 10:56:52 -05:00
|
|
|
import { getVideosList, getVideosListWithToken } from '../../../../shared/extra-utils/videos/videos'
|
2018-10-15 07:03:04 -04:00
|
|
|
import {
|
|
|
|
addVideoCommentReply,
|
|
|
|
addVideoCommentThread,
|
|
|
|
getVideoCommentThreads,
|
|
|
|
getVideoThreadComments
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/videos/video-comments'
|
|
|
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
2018-10-15 07:03:04 -04:00
|
|
|
import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
|
|
|
|
import {
|
|
|
|
addAccountToAccountBlocklist,
|
|
|
|
addAccountToServerBlocklist,
|
|
|
|
addServerToAccountBlocklist,
|
|
|
|
addServerToServerBlocklist,
|
|
|
|
getAccountBlocklistByAccount,
|
|
|
|
getAccountBlocklistByServer,
|
|
|
|
getServerBlocklistByAccount,
|
|
|
|
getServerBlocklistByServer,
|
|
|
|
removeAccountFromAccountBlocklist,
|
|
|
|
removeAccountFromServerBlocklist,
|
|
|
|
removeServerFromAccountBlocklist,
|
|
|
|
removeServerFromServerBlocklist
|
2019-04-15 09:26:15 -04:00
|
|
|
} from '../../../../shared/extra-utils/users/blocklist'
|
2020-01-03 07:36:34 -05:00
|
|
|
import { getUserNotifications } from '../../../../shared/extra-utils/users/user-notifications'
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
async function checkAllVideos (url: string, token: string) {
|
2018-10-15 10:43:14 -04:00
|
|
|
{
|
|
|
|
const res = await getVideosListWithToken(url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2018-10-15 10:43:14 -04:00
|
|
|
expect(res.body.data).to.have.lengthOf(4)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosList(url)
|
|
|
|
|
|
|
|
expect(res.body.data).to.have.lengthOf(4)
|
|
|
|
}
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function checkAllComments (url: string, token: string, videoUUID: string) {
|
2019-12-19 04:35:47 -05:00
|
|
|
const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 25, '-createdAt', token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
const allThreads: VideoComment[] = resThreads.body.data
|
|
|
|
const threads = allThreads.filter(t => t.isDeleted === false)
|
2018-10-15 07:03:04 -04:00
|
|
|
expect(threads).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
for (const thread of threads) {
|
|
|
|
const res = await getVideoThreadComments(url, videoUUID, thread.id, token)
|
|
|
|
|
|
|
|
const tree: VideoCommentThreadTree = res.body
|
|
|
|
expect(tree.children).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
async function checkCommentNotification (
|
|
|
|
mainServer: ServerInfo,
|
|
|
|
comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
|
|
|
|
check: 'presence' | 'absence'
|
|
|
|
) {
|
|
|
|
const resComment = await addVideoCommentThread(comment.server.url, comment.token, comment.videoUUID, comment.text)
|
|
|
|
const threadId = resComment.body.comment.id
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await waitJobs([ mainServer, comment.server ])
|
2019-12-19 04:35:47 -05:00
|
|
|
|
|
|
|
const res = await getUserNotifications(mainServer.url, mainServer.accessToken, 0, 30)
|
|
|
|
const commentNotifications = res.body.data
|
|
|
|
.filter(n => n.comment && n.comment.id === threadId)
|
|
|
|
|
|
|
|
if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1)
|
|
|
|
else expect(commentNotifications).to.have.lengthOf(0)
|
|
|
|
|
|
|
|
await deleteVideoComment(comment.server.url, comment.token, comment.videoUUID, threadId)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await waitJobs([ mainServer, comment.server ])
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
2018-10-15 07:03:04 -04:00
|
|
|
describe('Test blocklist', function () {
|
|
|
|
let servers: ServerInfo[]
|
|
|
|
let videoUUID1: string
|
|
|
|
let videoUUID2: string
|
|
|
|
let userToken1: string
|
|
|
|
let userModeratorToken: string
|
|
|
|
let userToken2: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user1', password: 'password' }
|
2020-01-31 10:56:52 -05:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
userToken1 = await userLogin(servers[0], user)
|
|
|
|
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'moderator', password: 'password' }
|
2020-01-31 10:56:52 -05:00
|
|
|
await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
userModeratorToken = await userLogin(servers[0], user)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const user = { username: 'user2', password: 'password' }
|
2020-01-31 10:56:52 -05:00
|
|
|
await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
userToken2 = await userLogin(servers[1], user)
|
|
|
|
await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' })
|
|
|
|
videoUUID1 = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' })
|
|
|
|
videoUUID2 = res.body.video.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID1, 'comment root 1')
|
|
|
|
const resReply = await addVideoCommentReply(servers[0].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1')
|
|
|
|
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1')
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const resComment = await addVideoCommentThread(servers[0].url, userToken1, videoUUID1, 'comment user 1')
|
|
|
|
await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1')
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('User blocklist', function () {
|
|
|
|
|
|
|
|
describe('When managing account blocklist', function () {
|
|
|
|
it('Should list all videos', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(3)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 2')
|
|
|
|
expect(v).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a local account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 1')
|
|
|
|
expect(v).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its comments', async function () {
|
2020-05-19 04:48:50 -04:00
|
|
|
const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const threads: VideoComment[] = resThreads.body.data
|
|
|
|
expect(threads).to.have.lengthOf(1)
|
2020-01-31 10:56:52 -05:00
|
|
|
expect(threads[0].totalReplies).to.equal(0)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const t = threads.find(t => t.text === 'comment user 1')
|
|
|
|
expect(t).to.be.undefined
|
|
|
|
|
|
|
|
for (const thread of threads) {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const tree: VideoCommentThreadTree = res.body
|
|
|
|
expect(tree.children).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
it('Should not have notifications from blocked accounts', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[0],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken1,
|
|
|
|
videoUUID: videoUUID2,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 07:03:04 -04:00
|
|
|
it('Should list all the videos with another user', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllVideos(servers[0].url, userToken1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all the comments with another user', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllComments(servers[0].url, userToken1, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list blocked accounts', async function () {
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: AccountBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04: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')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getAccountBlocklistByAccount(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: AccountBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04: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')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the remote account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(3)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 2')
|
|
|
|
expect(v).not.to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the local account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1')
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
2019-12-19 04:35:47 -05:00
|
|
|
|
|
|
|
it('Should have a notification from a non blocked account', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[0],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken1,
|
|
|
|
videoUUID: videoUUID2,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When managing server blocklist', function () {
|
|
|
|
it('Should list all videos', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote server', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const v1 = videos.find(v => v.name === 'video user 2')
|
|
|
|
const v2 = videos.find(v => v.name === 'video server 2')
|
|
|
|
|
|
|
|
expect(v1).to.be.undefined
|
|
|
|
expect(v2).to.be.undefined
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all the videos with another user', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllVideos(servers[0].url, userToken1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
it('Should hide its comments', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
|
2019-12-19 04:35:47 -05:00
|
|
|
const threadId = resThreads.body.comment.id
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2019-12-19 04:35:47 -05:00
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
|
2019-12-19 04:35:47 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notifications from blocked server', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
it('Should list blocked servers', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getServerBlocklistByAccount(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: ServerBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04:00
|
|
|
expect(block.byAccount.displayName).to.equal('root')
|
|
|
|
expect(block.byAccount.name).to.equal('root')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the remote server', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllVideos(servers[0].url, servers[0].accessToken)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
2019-12-19 04:35:47 -05:00
|
|
|
|
|
|
|
it('Should have notification from unblocked server', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Server blocklist', function () {
|
|
|
|
|
|
|
|
describe('When managing account blocklist', function () {
|
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllVideos(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllComments(servers[0].url, token, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
const res = await getVideosListWithToken(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(3)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 2')
|
|
|
|
expect(v).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a local account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
const res = await getVideosListWithToken(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 1')
|
|
|
|
expect(v).to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its comments', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
2020-05-19 04:48:50 -04:00
|
|
|
const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
|
|
|
|
|
|
|
|
let threads: VideoComment[] = resThreads.body.data
|
|
|
|
threads = threads.filter(t => t.isDeleted === false)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
expect(threads).to.have.lengthOf(1)
|
2020-01-31 10:56:52 -05:00
|
|
|
expect(threads[0].totalReplies).to.equal(0)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const t = threads.find(t => t.text === 'comment user 1')
|
|
|
|
expect(t).to.be.undefined
|
|
|
|
|
|
|
|
for (const thread of threads) {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const tree: VideoCommentThreadTree = res.body
|
|
|
|
expect(tree.children).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
it('Should not have notification from blocked accounts by instance', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-10-15 07:03:04 -04:00
|
|
|
it('Should list blocked accounts', async function () {
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: AccountBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04: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')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedAccount.host).to.equal('localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getAccountBlocklistByServer(servers[0].url, servers[0].accessToken, 1, 2, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: AccountBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04: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')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedAccount.host).to.equal('localhost:' + servers[0].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the remote account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
const res = await getVideosListWithToken(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(3)
|
|
|
|
|
|
|
|
const v = videos.find(v => v.name === 'video user 2')
|
|
|
|
expect(v).not.to.be.undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the local account', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, 'user1')
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should display its comments', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllComments(servers[0].url, token, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
2019-12-19 04:35:47 -05:00
|
|
|
|
|
|
|
it('Should have notifications from unblocked accounts', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When managing server blocklist', function () {
|
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllVideos(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllComments(servers[0].url, token, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should block a remote server', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should hide its videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
const res1 = await getVideosList(servers[0].url)
|
|
|
|
const res2 = await getVideosListWithToken(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2018-10-15 10:43:14 -04:00
|
|
|
for (const res of [ res1, res2 ]) {
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2018-10-15 10:43:14 -04:00
|
|
|
const v1 = videos.find(v => v.name === 'video user 2')
|
|
|
|
const v2 = videos.find(v => v.name === 'video server 2')
|
2018-10-15 07:03:04 -04:00
|
|
|
|
2018-10-15 10:43:14 -04:00
|
|
|
expect(v1).to.be.undefined
|
|
|
|
expect(v2).to.be.undefined
|
|
|
|
}
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-19 04:35:47 -05:00
|
|
|
it('Should hide its comments', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const resThreads = await addVideoCommentThread(servers[1].url, userToken2, videoUUID1, 'hidden comment 2')
|
2019-12-19 04:35:47 -05:00
|
|
|
const threadId = resThreads.body.comment.id
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1)
|
2019-12-19 04:35:47 -05:00
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
await deleteVideoComment(servers[1].url, userToken2, videoUUID1, threadId)
|
2019-12-19 04:35:47 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have notification from blocked instances by instance', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'absence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
|
|
|
|
it('Should list blocked servers', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
const res = await getServerBlocklistByServer(servers[0].url, servers[0].accessToken, 0, 1, 'createdAt')
|
2018-10-15 07:03:04 -04:00
|
|
|
const blocks: ServerBlock[] = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
2020-01-31 10:56:52 -05:00
|
|
|
const block = blocks[0]
|
2018-10-15 07:03:04 -04:00
|
|
|
expect(block.byAccount.displayName).to.equal('peertube')
|
|
|
|
expect(block.byAccount.name).to.equal('peertube')
|
2019-04-25 11:14:49 -04:00
|
|
|
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should unblock the remote server', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all videos', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllVideos(servers[0].url, token)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list the comments', async function () {
|
2020-01-31 10:56:52 -05:00
|
|
|
for (const token of [ userModeratorToken, servers[0].accessToken ]) {
|
|
|
|
await checkAllComments(servers[0].url, token, videoUUID1)
|
2018-10-15 07:03:04 -04:00
|
|
|
}
|
|
|
|
})
|
2019-12-19 04:35:47 -05:00
|
|
|
|
|
|
|
it('Should have notification from unblocked instances', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
{
|
2020-01-31 10:56:52 -05:00
|
|
|
const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' }
|
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const comment = {
|
2020-01-31 10:56:52 -05:00
|
|
|
server: servers[1],
|
2019-12-19 04:35:47 -05:00
|
|
|
token: userToken2,
|
|
|
|
videoUUID: videoUUID1,
|
2020-01-31 10:56:52 -05:00
|
|
|
text: 'hello @root@localhost:' + servers[0].port
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
2020-01-31 10:56:52 -05:00
|
|
|
await checkCommentNotification(servers[0], comment, 'presence')
|
2019-12-19 04:35:47 -05:00
|
|
|
}
|
|
|
|
})
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 09:10:37 -04:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-10-15 07:03:04 -04:00
|
|
|
})
|
|
|
|
})
|