]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/blocklist.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / blocklist.ts
index 9a4a3b3b9233777f22e331f12e4e509bbbab84d6..b3fd8ecac8cfcf0894e32ff2a24a36bd88886c62 100644 (file)
@@ -6,9 +6,9 @@ import {
   BlocklistCommand,
   cleanupTests,
   CommentsCommand,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
   waitJobs
 } from '@shared/extra-utils'
@@ -16,7 +16,7 @@ import { UserNotificationType } from '@shared/models'
 
 const expect = chai.expect
 
-async function checkAllVideos (server: ServerInfo, token: string) {
+async function checkAllVideos (server: PeerTubeServer, token: string) {
   {
     const { data } = await server.videos.listWithToken({ token })
     expect(data).to.have.lengthOf(5)
@@ -28,7 +28,7 @@ async function checkAllVideos (server: ServerInfo, token: string) {
   }
 }
 
-async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) {
+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)
@@ -41,8 +41,8 @@ async function checkAllComments (server: ServerInfo, token: string, videoUUID: s
 }
 
 async function checkCommentNotification (
-  mainServer: ServerInfo,
-  comment: { server: ServerInfo, token: string, videoUUID: string, text: string },
+  mainServer: PeerTubeServer,
+  comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string },
   check: 'presence' | 'absence'
 ) {
   const command = comment.server.comments
@@ -63,7 +63,7 @@ async function checkCommentNotification (
 }
 
 describe('Test blocklist', function () {
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let videoUUID1: string
   let videoUUID2: string
   let videoUUID3: string
@@ -77,7 +77,7 @@ describe('Test blocklist', function () {
   before(async function () {
     this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(3)
+    servers = await createMultipleServers(3)
     await setAccessTokensToServers(servers)
 
     command = servers[0].blocklist
@@ -254,6 +254,45 @@ describe('Test blocklist', function () {
         }
       })
 
+      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)
 
@@ -434,6 +473,35 @@ describe('Test blocklist', function () {
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      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 })
       })
@@ -575,6 +643,27 @@ describe('Test blocklist', function () {
         }
       })
 
+      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 })
       })
@@ -620,6 +709,7 @@ describe('Test blocklist', function () {
     })
 
     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)
@@ -690,7 +780,7 @@ describe('Test blocklist', function () {
           const now = new Date()
           await servers[1].follows.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await servers[1].follows.follow({ targets: [ servers[0].host ] })
+          await servers[1].follows.follow({ hosts: [ servers[0].host ] })
 
           await waitJobs(servers)
 
@@ -713,6 +803,23 @@ describe('Test blocklist', function () {
         expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
       })
 
+      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 })
       })
@@ -751,7 +858,7 @@ describe('Test blocklist', function () {
           const now = new Date()
           await servers[1].follows.unfollow({ target: servers[0] })
           await waitJobs(servers)
-          await servers[1].follows.follow({ targets: [ servers[0].host ] })
+          await servers[1].follows.follow({ hosts: [ servers[0].host ] })
 
           await waitJobs(servers)