/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { UserNotificationType } from '@shared/models'
import {
BlocklistCommand,
cleanupTests,
doubleFollow,
PeerTubeServer,
setAccessTokensToServers,
+ setDefaultAccountAvatar,
waitJobs
-} from '@shared/extra-utils'
-import { UserNotificationType } from '@shared/models'
-
-const expect = chai.expect
+} from '@shared/server-commands'
async function checkAllVideos (server: PeerTubeServer, token: string) {
{
servers = await createMultipleServers(3)
await setAccessTokensToServers(servers)
+ await setDefaultAccountAvatar(servers)
command = servers[0].blocklist
commentsCommand = servers.map(s => s.comments)
}
})
+ 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)
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
})
+ 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: 'localhost:' + servers[1].port })
})
}
})
+ 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@localhost:' + servers[1].port })
})
})
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)
expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
})
+ 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: 'localhost:' + servers[1].port })
})