diff options
author | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
commit | c380e3928517eb5311b38cf257816642617d7a33 (patch) | |
tree | 2ea9b70ebca16b5d109bcce98fe7f944dad89319 /packages/tests/src/external-plugins | |
parent | a8ca6190fb462bf6eb5685cfc1d8ae444164a487 (diff) | |
parent | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (diff) | |
download | PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.gz PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.zst PeerTube-c380e3928517eb5311b38cf257816642617d7a33.zip |
Merge branch 'feature/esm-and-nx' into develop
Diffstat (limited to 'packages/tests/src/external-plugins')
-rw-r--r-- | packages/tests/src/external-plugins/akismet.ts | 160 | ||||
-rw-r--r-- | packages/tests/src/external-plugins/auth-ldap.ts | 117 | ||||
-rw-r--r-- | packages/tests/src/external-plugins/auto-block-videos.ts | 167 | ||||
-rw-r--r-- | packages/tests/src/external-plugins/auto-mute.ts | 216 | ||||
-rw-r--r-- | packages/tests/src/external-plugins/index.ts | 4 |
5 files changed, 664 insertions, 0 deletions
diff --git a/packages/tests/src/external-plugins/akismet.ts b/packages/tests/src/external-plugins/akismet.ts new file mode 100644 index 000000000..c6d3b7752 --- /dev/null +++ b/packages/tests/src/external-plugins/akismet.ts | |||
@@ -0,0 +1,160 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | waitJobs | ||
12 | } from '@peertube/peertube-server-commands' | ||
13 | |||
14 | describe('Official plugin Akismet', function () { | ||
15 | let servers: PeerTubeServer[] | ||
16 | let videoUUID: string | ||
17 | |||
18 | before(async function () { | ||
19 | this.timeout(30000) | ||
20 | |||
21 | servers = await createMultipleServers(2) | ||
22 | await setAccessTokensToServers(servers) | ||
23 | |||
24 | await servers[0].plugins.install({ | ||
25 | npmName: 'peertube-plugin-akismet' | ||
26 | }) | ||
27 | |||
28 | if (!process.env.AKISMET_KEY) throw new Error('Missing AKISMET_KEY from env') | ||
29 | |||
30 | await servers[0].plugins.updateSettings({ | ||
31 | npmName: 'peertube-plugin-akismet', | ||
32 | settings: { | ||
33 | 'akismet-api-key': process.env.AKISMET_KEY | ||
34 | } | ||
35 | }) | ||
36 | |||
37 | await doubleFollow(servers[0], servers[1]) | ||
38 | }) | ||
39 | |||
40 | describe('Local threads/replies', function () { | ||
41 | |||
42 | before(async function () { | ||
43 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) | ||
44 | videoUUID = uuid | ||
45 | }) | ||
46 | |||
47 | it('Should not detect a thread as spam', async function () { | ||
48 | await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' }) | ||
49 | }) | ||
50 | |||
51 | it('Should not detect a reply as spam', async function () { | ||
52 | await servers[0].comments.addReplyToLastThread({ text: 'reply' }) | ||
53 | }) | ||
54 | |||
55 | it('Should detect a thread as spam', async function () { | ||
56 | await servers[0].comments.createThread({ | ||
57 | videoId: videoUUID, | ||
58 | text: 'akismet-guaranteed-spam', | ||
59 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
60 | }) | ||
61 | }) | ||
62 | |||
63 | it('Should detect a thread as spam', async function () { | ||
64 | await servers[0].comments.createThread({ videoId: videoUUID, text: 'comment' }) | ||
65 | await servers[0].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
66 | }) | ||
67 | }) | ||
68 | |||
69 | describe('Remote threads/replies', function () { | ||
70 | |||
71 | before(async function () { | ||
72 | this.timeout(60000) | ||
73 | |||
74 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video 1' }) | ||
75 | videoUUID = uuid | ||
76 | |||
77 | await waitJobs(servers) | ||
78 | }) | ||
79 | |||
80 | it('Should not detect a thread as spam', async function () { | ||
81 | this.timeout(30000) | ||
82 | |||
83 | await servers[1].comments.createThread({ videoId: videoUUID, text: 'remote comment 1' }) | ||
84 | await waitJobs(servers) | ||
85 | |||
86 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) | ||
87 | expect(data).to.have.lengthOf(1) | ||
88 | }) | ||
89 | |||
90 | it('Should not detect a reply as spam', async function () { | ||
91 | this.timeout(30000) | ||
92 | |||
93 | await servers[1].comments.addReplyToLastThread({ text: 'I agree with you' }) | ||
94 | await waitJobs(servers) | ||
95 | |||
96 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) | ||
97 | expect(data).to.have.lengthOf(1) | ||
98 | |||
99 | const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: data[0].id }) | ||
100 | expect(tree.children).to.have.lengthOf(1) | ||
101 | }) | ||
102 | |||
103 | it('Should detect a thread as spam', async function () { | ||
104 | this.timeout(30000) | ||
105 | |||
106 | await servers[1].comments.createThread({ videoId: videoUUID, text: 'akismet-guaranteed-spam' }) | ||
107 | await waitJobs(servers) | ||
108 | |||
109 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) | ||
110 | expect(data).to.have.lengthOf(1) | ||
111 | }) | ||
112 | |||
113 | it('Should detect a thread as spam', async function () { | ||
114 | this.timeout(30000) | ||
115 | |||
116 | await servers[1].comments.addReplyToLastThread({ text: 'akismet-guaranteed-spam' }) | ||
117 | await waitJobs(servers) | ||
118 | |||
119 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID }) | ||
120 | expect(data).to.have.lengthOf(1) | ||
121 | |||
122 | const thread = data[0] | ||
123 | const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId: thread.id }) | ||
124 | expect(tree.children).to.have.lengthOf(1) | ||
125 | }) | ||
126 | }) | ||
127 | |||
128 | describe('Signup', function () { | ||
129 | |||
130 | before(async function () { | ||
131 | await servers[0].config.updateExistingSubConfig({ | ||
132 | newConfig: { | ||
133 | signup: { | ||
134 | enabled: true | ||
135 | } | ||
136 | } | ||
137 | }) | ||
138 | }) | ||
139 | |||
140 | it('Should allow signup', async function () { | ||
141 | await servers[0].registrations.register({ | ||
142 | username: 'user1', | ||
143 | displayName: 'user 1' | ||
144 | }) | ||
145 | }) | ||
146 | |||
147 | it('Should detect a signup as SPAM', async function () { | ||
148 | await servers[0].registrations.register({ | ||
149 | username: 'user2', | ||
150 | displayName: 'user 2', | ||
151 | email: 'akismet-guaranteed-spam@example.com', | ||
152 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
153 | }) | ||
154 | }) | ||
155 | }) | ||
156 | |||
157 | after(async function () { | ||
158 | await cleanupTests(servers) | ||
159 | }) | ||
160 | }) | ||
diff --git a/packages/tests/src/external-plugins/auth-ldap.ts b/packages/tests/src/external-plugins/auth-ldap.ts new file mode 100644 index 000000000..ad058110c --- /dev/null +++ b/packages/tests/src/external-plugins/auth-ldap.ts | |||
@@ -0,0 +1,117 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@peertube/peertube-server-commands' | ||
5 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
6 | |||
7 | describe('Official plugin auth-ldap', function () { | ||
8 | let server: PeerTubeServer | ||
9 | let accessToken: string | ||
10 | let userId: number | ||
11 | |||
12 | before(async function () { | ||
13 | this.timeout(30000) | ||
14 | |||
15 | server = await createSingleServer(1) | ||
16 | await setAccessTokensToServers([ server ]) | ||
17 | |||
18 | await server.plugins.install({ npmName: 'peertube-plugin-auth-ldap' }) | ||
19 | }) | ||
20 | |||
21 | it('Should not login with without LDAP settings', async function () { | ||
22 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
23 | }) | ||
24 | |||
25 | it('Should not login with bad LDAP settings', async function () { | ||
26 | await server.plugins.updateSettings({ | ||
27 | npmName: 'peertube-plugin-auth-ldap', | ||
28 | settings: { | ||
29 | 'bind-credentials': 'GoodNewsEveryone', | ||
30 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | ||
31 | 'insecure-tls': false, | ||
32 | 'mail-property': 'mail', | ||
33 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | ||
34 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | ||
35 | 'url': 'ldap://127.0.0.1:390', | ||
36 | 'username-property': 'uid' | ||
37 | } | ||
38 | }) | ||
39 | |||
40 | await server.login.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
41 | }) | ||
42 | |||
43 | it('Should not login with good LDAP settings but wrong username/password', async function () { | ||
44 | await server.plugins.updateSettings({ | ||
45 | npmName: 'peertube-plugin-auth-ldap', | ||
46 | settings: { | ||
47 | 'bind-credentials': 'GoodNewsEveryone', | ||
48 | 'bind-dn': 'cn=admin,dc=planetexpress,dc=com', | ||
49 | 'insecure-tls': false, | ||
50 | 'mail-property': 'mail', | ||
51 | 'search-base': 'ou=people,dc=planetexpress,dc=com', | ||
52 | 'search-filter': '(|(mail={{username}})(uid={{username}}))', | ||
53 | 'url': 'ldap://127.0.0.1:10389', | ||
54 | 'username-property': 'uid' | ||
55 | } | ||
56 | }) | ||
57 | |||
58 | await server.login.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
59 | await server.login.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
60 | }) | ||
61 | |||
62 | it('Should login with the appropriate username/password', async function () { | ||
63 | accessToken = await server.login.getAccessToken({ username: 'fry', password: 'fry' }) | ||
64 | }) | ||
65 | |||
66 | it('Should login with the appropriate email/password', async function () { | ||
67 | accessToken = await server.login.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' }) | ||
68 | }) | ||
69 | |||
70 | it('Should login get my profile', async function () { | ||
71 | const body = await server.users.getMyInfo({ token: accessToken }) | ||
72 | expect(body.username).to.equal('fry') | ||
73 | expect(body.email).to.equal('fry@planetexpress.com') | ||
74 | |||
75 | userId = body.id | ||
76 | }) | ||
77 | |||
78 | it('Should upload a video', async function () { | ||
79 | await server.videos.upload({ token: accessToken, attributes: { name: 'my super video' } }) | ||
80 | }) | ||
81 | |||
82 | it('Should not be able to login if the user is banned', async function () { | ||
83 | await server.users.banUser({ userId }) | ||
84 | |||
85 | await server.login.login({ | ||
86 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
87 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
88 | }) | ||
89 | }) | ||
90 | |||
91 | it('Should be able to login if the user is unbanned', async function () { | ||
92 | await server.users.unbanUser({ userId }) | ||
93 | |||
94 | await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } }) | ||
95 | }) | ||
96 | |||
97 | it('Should not be able to ask password reset', async function () { | ||
98 | await server.users.askResetPassword({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
99 | }) | ||
100 | |||
101 | it('Should not be able to ask email verification', async function () { | ||
102 | await server.users.askSendVerifyEmail({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 }) | ||
103 | }) | ||
104 | |||
105 | it('Should not login if the plugin is uninstalled', async function () { | ||
106 | await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) | ||
107 | |||
108 | await server.login.login({ | ||
109 | user: { username: 'fry@planetexpress.com', password: 'fry' }, | ||
110 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
111 | }) | ||
112 | }) | ||
113 | |||
114 | after(async function () { | ||
115 | await cleanupTests([ server ]) | ||
116 | }) | ||
117 | }) | ||
diff --git a/packages/tests/src/external-plugins/auto-block-videos.ts b/packages/tests/src/external-plugins/auto-block-videos.ts new file mode 100644 index 000000000..6146c827c --- /dev/null +++ b/packages/tests/src/external-plugins/auto-block-videos.ts | |||
@@ -0,0 +1,167 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { wait } from '@peertube/peertube-core-utils' | ||
5 | import { Video } from '@peertube/peertube-models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | killallServers, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers | ||
13 | } from '@peertube/peertube-server-commands' | ||
14 | import { MockBlocklist } from '../shared/mock-servers/index.js' | ||
15 | |||
16 | async function check (server: PeerTubeServer, videoUUID: string, exists = true) { | ||
17 | const { data } = await server.videos.list() | ||
18 | |||
19 | const video = data.find(v => v.uuid === videoUUID) | ||
20 | |||
21 | if (exists) expect(video).to.not.be.undefined | ||
22 | else expect(video).to.be.undefined | ||
23 | } | ||
24 | |||
25 | describe('Official plugin auto-block videos', function () { | ||
26 | let servers: PeerTubeServer[] | ||
27 | let blocklistServer: MockBlocklist | ||
28 | let server1Videos: Video[] = [] | ||
29 | let server2Videos: Video[] = [] | ||
30 | let port: number | ||
31 | |||
32 | before(async function () { | ||
33 | this.timeout(120000) | ||
34 | |||
35 | servers = await createMultipleServers(2) | ||
36 | await setAccessTokensToServers(servers) | ||
37 | |||
38 | for (const server of servers) { | ||
39 | await server.plugins.install({ npmName: 'peertube-plugin-auto-block-videos' }) | ||
40 | } | ||
41 | |||
42 | blocklistServer = new MockBlocklist() | ||
43 | port = await blocklistServer.initialize() | ||
44 | |||
45 | await servers[0].videos.quickUpload({ name: 'video server 1' }) | ||
46 | await servers[1].videos.quickUpload({ name: 'video server 2' }) | ||
47 | await servers[1].videos.quickUpload({ name: 'video 2 server 2' }) | ||
48 | await servers[1].videos.quickUpload({ name: 'video 3 server 2' }) | ||
49 | |||
50 | { | ||
51 | const { data } = await servers[0].videos.list() | ||
52 | server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) | ||
53 | } | ||
54 | |||
55 | { | ||
56 | const { data } = await servers[1].videos.list() | ||
57 | server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) | ||
58 | } | ||
59 | |||
60 | await doubleFollow(servers[0], servers[1]) | ||
61 | }) | ||
62 | |||
63 | it('Should update plugin settings', async function () { | ||
64 | await servers[0].plugins.updateSettings({ | ||
65 | npmName: 'peertube-plugin-auto-block-videos', | ||
66 | settings: { | ||
67 | 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`, | ||
68 | 'check-seconds-interval': 1 | ||
69 | } | ||
70 | }) | ||
71 | }) | ||
72 | |||
73 | it('Should auto block a video', async function () { | ||
74 | await check(servers[0], server2Videos[0].uuid, true) | ||
75 | |||
76 | blocklistServer.replace({ | ||
77 | data: [ | ||
78 | { | ||
79 | value: server2Videos[0].url | ||
80 | } | ||
81 | ] | ||
82 | }) | ||
83 | |||
84 | await wait(2000) | ||
85 | |||
86 | await check(servers[0], server2Videos[0].uuid, false) | ||
87 | }) | ||
88 | |||
89 | it('Should have video in blacklists', async function () { | ||
90 | const body = await servers[0].blacklist.list() | ||
91 | |||
92 | const videoBlacklists = body.data | ||
93 | expect(videoBlacklists).to.have.lengthOf(1) | ||
94 | expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin') | ||
95 | expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name) | ||
96 | }) | ||
97 | |||
98 | it('Should not block a local video', async function () { | ||
99 | await check(servers[0], server1Videos[0].uuid, true) | ||
100 | |||
101 | blocklistServer.replace({ | ||
102 | data: [ | ||
103 | { | ||
104 | value: server1Videos[0].url | ||
105 | } | ||
106 | ] | ||
107 | }) | ||
108 | |||
109 | await wait(2000) | ||
110 | |||
111 | await check(servers[0], server1Videos[0].uuid, true) | ||
112 | }) | ||
113 | |||
114 | it('Should remove a video block', async function () { | ||
115 | await check(servers[0], server2Videos[0].uuid, false) | ||
116 | |||
117 | blocklistServer.replace({ | ||
118 | data: [ | ||
119 | { | ||
120 | value: server2Videos[0].url, | ||
121 | action: 'remove' | ||
122 | } | ||
123 | ] | ||
124 | }) | ||
125 | |||
126 | await wait(2000) | ||
127 | |||
128 | await check(servers[0], server2Videos[0].uuid, true) | ||
129 | }) | ||
130 | |||
131 | it('Should auto block a video, manually unblock it and do not reblock it automatically', async function () { | ||
132 | this.timeout(20000) | ||
133 | |||
134 | const video = server2Videos[1] | ||
135 | |||
136 | await check(servers[0], video.uuid, true) | ||
137 | |||
138 | blocklistServer.replace({ | ||
139 | data: [ | ||
140 | { | ||
141 | value: video.url, | ||
142 | updatedAt: new Date().toISOString() | ||
143 | } | ||
144 | ] | ||
145 | }) | ||
146 | |||
147 | await wait(2000) | ||
148 | |||
149 | await check(servers[0], video.uuid, false) | ||
150 | |||
151 | await servers[0].blacklist.remove({ videoId: video.uuid }) | ||
152 | |||
153 | await check(servers[0], video.uuid, true) | ||
154 | |||
155 | await killallServers([ servers[0] ]) | ||
156 | await servers[0].run() | ||
157 | await wait(2000) | ||
158 | |||
159 | await check(servers[0], video.uuid, true) | ||
160 | }) | ||
161 | |||
162 | after(async function () { | ||
163 | await blocklistServer.terminate() | ||
164 | |||
165 | await cleanupTests(servers) | ||
166 | }) | ||
167 | }) | ||
diff --git a/packages/tests/src/external-plugins/auto-mute.ts b/packages/tests/src/external-plugins/auto-mute.ts new file mode 100644 index 000000000..b4050e236 --- /dev/null +++ b/packages/tests/src/external-plugins/auto-mute.ts | |||
@@ -0,0 +1,216 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { wait } from '@peertube/peertube-core-utils' | ||
5 | import { HttpStatusCode } from '@peertube/peertube-models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | killallServers, | ||
11 | makeGetRequest, | ||
12 | PeerTubeServer, | ||
13 | setAccessTokensToServers | ||
14 | } from '@peertube/peertube-server-commands' | ||
15 | import { MockBlocklist } from '../shared/mock-servers/index.js' | ||
16 | |||
17 | describe('Official plugin auto-mute', function () { | ||
18 | const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' | ||
19 | let servers: PeerTubeServer[] | ||
20 | let blocklistServer: MockBlocklist | ||
21 | let port: number | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(120000) | ||
25 | |||
26 | servers = await createMultipleServers(2) | ||
27 | await setAccessTokensToServers(servers) | ||
28 | |||
29 | for (const server of servers) { | ||
30 | await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' }) | ||
31 | } | ||
32 | |||
33 | blocklistServer = new MockBlocklist() | ||
34 | port = await blocklistServer.initialize() | ||
35 | |||
36 | await servers[0].videos.quickUpload({ name: 'video server 1' }) | ||
37 | await servers[1].videos.quickUpload({ name: 'video server 2' }) | ||
38 | |||
39 | await doubleFollow(servers[0], servers[1]) | ||
40 | }) | ||
41 | |||
42 | it('Should update plugin settings', async function () { | ||
43 | await servers[0].plugins.updateSettings({ | ||
44 | npmName: 'peertube-plugin-auto-mute', | ||
45 | settings: { | ||
46 | 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`, | ||
47 | 'check-seconds-interval': 1 | ||
48 | } | ||
49 | }) | ||
50 | }) | ||
51 | |||
52 | it('Should add a server blocklist', async function () { | ||
53 | blocklistServer.replace({ | ||
54 | data: [ | ||
55 | { | ||
56 | value: servers[1].host | ||
57 | } | ||
58 | ] | ||
59 | }) | ||
60 | |||
61 | await wait(2000) | ||
62 | |||
63 | const { total } = await servers[0].videos.list() | ||
64 | expect(total).to.equal(1) | ||
65 | }) | ||
66 | |||
67 | it('Should remove a server blocklist', async function () { | ||
68 | blocklistServer.replace({ | ||
69 | data: [ | ||
70 | { | ||
71 | value: servers[1].host, | ||
72 | action: 'remove' | ||
73 | } | ||
74 | ] | ||
75 | }) | ||
76 | |||
77 | await wait(2000) | ||
78 | |||
79 | const { total } = await servers[0].videos.list() | ||
80 | expect(total).to.equal(2) | ||
81 | }) | ||
82 | |||
83 | it('Should add an account blocklist', async function () { | ||
84 | blocklistServer.replace({ | ||
85 | data: [ | ||
86 | { | ||
87 | value: 'root@' + servers[1].host | ||
88 | } | ||
89 | ] | ||
90 | }) | ||
91 | |||
92 | await wait(2000) | ||
93 | |||
94 | const { total } = await servers[0].videos.list() | ||
95 | expect(total).to.equal(1) | ||
96 | }) | ||
97 | |||
98 | it('Should remove an account blocklist', async function () { | ||
99 | blocklistServer.replace({ | ||
100 | data: [ | ||
101 | { | ||
102 | value: 'root@' + servers[1].host, | ||
103 | action: 'remove' | ||
104 | } | ||
105 | ] | ||
106 | }) | ||
107 | |||
108 | await wait(2000) | ||
109 | |||
110 | const { total } = await servers[0].videos.list() | ||
111 | expect(total).to.equal(2) | ||
112 | }) | ||
113 | |||
114 | it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { | ||
115 | this.timeout(20000) | ||
116 | |||
117 | const account = 'root@' + servers[1].host | ||
118 | |||
119 | blocklistServer.replace({ | ||
120 | data: [ | ||
121 | { | ||
122 | value: account, | ||
123 | updatedAt: new Date().toISOString() | ||
124 | } | ||
125 | ] | ||
126 | }) | ||
127 | |||
128 | await wait(2000) | ||
129 | |||
130 | { | ||
131 | const { total } = await servers[0].videos.list() | ||
132 | expect(total).to.equal(1) | ||
133 | } | ||
134 | |||
135 | await servers[0].blocklist.removeFromServerBlocklist({ account }) | ||
136 | |||
137 | { | ||
138 | const { total } = await servers[0].videos.list() | ||
139 | expect(total).to.equal(2) | ||
140 | } | ||
141 | |||
142 | await killallServers([ servers[0] ]) | ||
143 | await servers[0].run() | ||
144 | await wait(2000) | ||
145 | |||
146 | { | ||
147 | const { total } = await servers[0].videos.list() | ||
148 | expect(total).to.equal(2) | ||
149 | } | ||
150 | }) | ||
151 | |||
152 | it('Should not expose the auto mute list', async function () { | ||
153 | await makeGetRequest({ | ||
154 | url: servers[0].url, | ||
155 | path: '/plugins/auto-mute/router/api/v1/mute-list', | ||
156 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
157 | }) | ||
158 | }) | ||
159 | |||
160 | it('Should enable auto mute list', async function () { | ||
161 | await servers[0].plugins.updateSettings({ | ||
162 | npmName: 'peertube-plugin-auto-mute', | ||
163 | settings: { | ||
164 | 'blocklist-urls': '', | ||
165 | 'check-seconds-interval': 1, | ||
166 | 'expose-mute-list': true | ||
167 | } | ||
168 | }) | ||
169 | |||
170 | await makeGetRequest({ | ||
171 | url: servers[0].url, | ||
172 | path: '/plugins/auto-mute/router/api/v1/mute-list', | ||
173 | expectedStatus: HttpStatusCode.OK_200 | ||
174 | }) | ||
175 | }) | ||
176 | |||
177 | it('Should mute an account on server 1, and server 2 auto mutes it', async function () { | ||
178 | this.timeout(20000) | ||
179 | |||
180 | await servers[1].plugins.updateSettings({ | ||
181 | npmName: 'peertube-plugin-auto-mute', | ||
182 | settings: { | ||
183 | 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath, | ||
184 | 'check-seconds-interval': 1, | ||
185 | 'expose-mute-list': false | ||
186 | } | ||
187 | }) | ||
188 | |||
189 | await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host }) | ||
190 | await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host }) | ||
191 | |||
192 | const res = await makeGetRequest({ | ||
193 | url: servers[0].url, | ||
194 | path: '/plugins/auto-mute/router/api/v1/mute-list', | ||
195 | expectedStatus: HttpStatusCode.OK_200 | ||
196 | }) | ||
197 | |||
198 | const data = res.body.data | ||
199 | expect(data).to.have.lengthOf(1) | ||
200 | expect(data[0].updatedAt).to.exist | ||
201 | expect(data[0].value).to.equal('root@' + servers[1].host) | ||
202 | |||
203 | await wait(2000) | ||
204 | |||
205 | for (const server of servers) { | ||
206 | const { total } = await server.videos.list() | ||
207 | expect(total).to.equal(1) | ||
208 | } | ||
209 | }) | ||
210 | |||
211 | after(async function () { | ||
212 | await blocklistServer.terminate() | ||
213 | |||
214 | await cleanupTests(servers) | ||
215 | }) | ||
216 | }) | ||
diff --git a/packages/tests/src/external-plugins/index.ts b/packages/tests/src/external-plugins/index.ts new file mode 100644 index 000000000..815bbf1da --- /dev/null +++ b/packages/tests/src/external-plugins/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | import './akismet' | ||
2 | import './auth-ldap' | ||
3 | import './auto-block-videos' | ||
4 | import './auto-mute' | ||