From 5b9c965d5aa747f29b081289f930ee215fdc23c8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Apr 2019 14:04:57 +0200 Subject: Add ability to forbid followers --- server/tests/api/check-params/config.ts | 5 ++ server/tests/api/check-params/follows.ts | 40 +++++++++++ server/tests/api/server/config.ts | 9 +++ server/tests/api/server/follows-moderation.ts | 96 ++++++++++++++++++++------- 4 files changed, 126 insertions(+), 24 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 0b333e2f4..d117f26e6 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -87,6 +87,11 @@ describe('Test config API validators', function () { enabled: false } } + }, + followers: { + instance: { + enabled: false + } } } diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 2ad1575a3..67fa43778 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -144,6 +144,46 @@ describe('Test server follows API validators', function () { }) }) + describe('When removing a follower', function () { + const path = '/api/v1/server/followers' + + it('Should fail with an invalid token', async function () { + await makeDeleteRequest({ + url: server.url, + path: path + '/toto@localhost:9002', + token: 'fake_token', + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makeDeleteRequest({ + url: server.url, + path: path + '/toto@localhost:9002', + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + + it('Should fail with an invalid follower', async function () { + await makeDeleteRequest({ + url: server.url, + path: path + '/toto', + token: server.accessToken, + statusCodeExpected: 400 + }) + }) + + it('Should fail with an unknown follower', async function () { + await makeDeleteRequest({ + url: server.url, + path: path + '/toto@localhost:9003', + token: server.accessToken, + statusCodeExpected: 404 + }) + }) + }) + describe('When removing following', function () { const path = '/api/v1/server/following' diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index b9f05e952..cb2700f29 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -63,6 +63,8 @@ function checkInitialConfig (data: CustomConfig) { expect(data.import.videos.http.enabled).to.be.true expect(data.import.videos.torrent.enabled).to.be.true expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false + + expect(data.followers.instance.enabled).to.be.true } function checkUpdatedConfig (data: CustomConfig) { @@ -105,6 +107,8 @@ function checkUpdatedConfig (data: CustomConfig) { expect(data.import.videos.http.enabled).to.be.false expect(data.import.videos.torrent.enabled).to.be.false expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true + + expect(data.followers.instance.enabled).to.be.false } describe('Test config', function () { @@ -234,6 +238,11 @@ describe('Test config', function () { enabled: true } } + }, + followers: { + instance: { + enabled: false + } } } await updateCustomConfig(server.url, server.accessToken, newCustomConfig) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index b1cbfb62c..a360706f2 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -2,7 +2,13 @@ import * as chai from 'chai' import 'mocha' -import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' +import { + flushAndRunMultipleServers, + killallServers, + ServerInfo, + setAccessTokensToServers, + updateCustomSubConfig +} from '../../../../shared/utils/index' import { follow, getFollowersListPaginationAndSort, @@ -14,6 +20,38 @@ import { ActorFollow } from '../../../../shared/models/actors' const expect = chai.expect +async function checkHasFollowers (servers: ServerInfo[]) { + { + const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') + expect(res.body.total).to.equal(1) + + const follow = res.body.data[0] as ActorFollow + expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') + expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') + } + + { + const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') + expect(res.body.total).to.equal(1) + + const follow = res.body.data[0] as ActorFollow + expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') + expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') + } +} + +async function checkNoFollowers (servers: ServerInfo[]) { + { + const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt') + expect(res.body.total).to.equal(0) + } + + { + const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt') + expect(res.body.total).to.equal(0) + } +} + describe('Test follows moderation', function () { let servers: ServerInfo[] = [] @@ -35,23 +73,7 @@ describe('Test follows moderation', function () { }) it('Should have correct follows', async function () { - { - const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') - expect(res.body.total).to.equal(1) - - const follow = res.body.data[0] as ActorFollow - expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') - expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') - } - - { - const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt') - expect(res.body.total).to.equal(1) - - const follow = res.body.data[0] as ActorFollow - expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') - expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') - } + await checkHasFollowers(servers) }) it('Should remove follower on server 2', async function () { @@ -61,15 +83,41 @@ describe('Test follows moderation', function () { }) it('Should not not have follows anymore', async function () { - { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt') - expect(res.body.total).to.equal(0) + await checkNoFollowers(servers) + }) + + it('Should disable followers on server 2', async function () { + const subConfig = { + followers: { + instance: { + enabled: false + } + } } - { - const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt') - expect(res.body.total).to.equal(0) + await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + + await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await waitJobs(servers) + + await checkNoFollowers(servers) + }) + + it('Should re enable followers on server 2', async function () { + const subConfig = { + followers: { + instance: { + enabled: true + } + } } + + await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + + await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) + await waitJobs(servers) + + await checkHasFollowers(servers) }) after(async function () { -- cgit v1.2.3