diff options
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/account-blocklist.ts | 294 | ||||
-rw-r--r-- | server/tests/api/users/blocklist.ts | 500 | ||||
-rw-r--r-- | server/tests/api/users/index.ts | 1 |
3 files changed, 501 insertions, 294 deletions
diff --git a/server/tests/api/users/account-blocklist.ts b/server/tests/api/users/account-blocklist.ts deleted file mode 100644 index 026971331..000000000 --- a/server/tests/api/users/account-blocklist.ts +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' | ||
6 | import { | ||
7 | createUser, | ||
8 | doubleFollow, | ||
9 | flushAndRunMultipleServers, | ||
10 | flushTests, | ||
11 | killallServers, | ||
12 | ServerInfo, | ||
13 | uploadVideo, | ||
14 | userLogin | ||
15 | } from '../../utils/index' | ||
16 | import { setAccessTokensToServers } from '../../utils/users/login' | ||
17 | import { getVideosListWithToken } from '../../utils/videos/videos' | ||
18 | import { | ||
19 | addVideoCommentReply, | ||
20 | addVideoCommentThread, | ||
21 | getVideoCommentThreads, | ||
22 | getVideoThreadComments | ||
23 | } from '../../utils/videos/video-comments' | ||
24 | import { waitJobs } from '../../utils/server/jobs' | ||
25 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
26 | import { | ||
27 | addAccountToAccountBlocklist, | ||
28 | addServerToAccountBlocklist, | ||
29 | getAccountBlocklistByAccount, getServerBlocklistByAccount, | ||
30 | removeAccountFromAccountBlocklist, | ||
31 | removeServerFromAccountBlocklist | ||
32 | } from '../../utils/users/blocklist' | ||
33 | |||
34 | const expect = chai.expect | ||
35 | |||
36 | async function checkAllVideos (url: string, token: string) { | ||
37 | const res = await getVideosListWithToken(url, token) | ||
38 | |||
39 | expect(res.body.data).to.have.lengthOf(4) | ||
40 | } | ||
41 | |||
42 | async function checkAllComments (url: string, token: string, videoUUID: string) { | ||
43 | const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 5, '-createdAt', token) | ||
44 | |||
45 | const threads: VideoComment[] = resThreads.body.data | ||
46 | expect(threads).to.have.lengthOf(2) | ||
47 | |||
48 | for (const thread of threads) { | ||
49 | const res = await getVideoThreadComments(url, videoUUID, thread.id, token) | ||
50 | |||
51 | const tree: VideoCommentThreadTree = res.body | ||
52 | expect(tree.children).to.have.lengthOf(1) | ||
53 | } | ||
54 | } | ||
55 | |||
56 | describe('Test accounts blocklist', function () { | ||
57 | let servers: ServerInfo[] | ||
58 | let videoUUID1: string | ||
59 | let videoUUID2: string | ||
60 | let userToken1: string | ||
61 | let userToken2: string | ||
62 | |||
63 | before(async function () { | ||
64 | this.timeout(60000) | ||
65 | |||
66 | await flushTests() | ||
67 | |||
68 | servers = await flushAndRunMultipleServers(2) | ||
69 | await setAccessTokensToServers(servers) | ||
70 | |||
71 | { | ||
72 | const user = { username: 'user1', password: 'password' } | ||
73 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
74 | |||
75 | userToken1 = await userLogin(servers[0], user) | ||
76 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) | ||
77 | } | ||
78 | |||
79 | { | ||
80 | const user = { username: 'user2', password: 'password' } | ||
81 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | ||
82 | |||
83 | userToken2 = await userLogin(servers[1], user) | ||
84 | await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) | ||
85 | } | ||
86 | |||
87 | { | ||
88 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) | ||
89 | videoUUID1 = res.body.video.uuid | ||
90 | } | ||
91 | |||
92 | { | ||
93 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) | ||
94 | videoUUID2 = res.body.video.uuid | ||
95 | } | ||
96 | |||
97 | await doubleFollow(servers[0], servers[1]) | ||
98 | |||
99 | { | ||
100 | const resComment = await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, 'comment root 1') | ||
101 | const resReply = await addVideoCommentReply(servers[ 0 ].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') | ||
102 | await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') | ||
103 | } | ||
104 | |||
105 | { | ||
106 | const resComment = await addVideoCommentThread(servers[ 0 ].url, userToken1, videoUUID1, 'comment user 1') | ||
107 | await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') | ||
108 | } | ||
109 | |||
110 | await waitJobs(servers) | ||
111 | }) | ||
112 | |||
113 | describe('When managing account blocklist', function () { | ||
114 | it('Should list all videos', function () { | ||
115 | return checkAllVideos(servers[0].url, servers[0].accessToken) | ||
116 | }) | ||
117 | |||
118 | it('Should list the comments', function () { | ||
119 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) | ||
120 | }) | ||
121 | |||
122 | it('Should block a remote account', async function () { | ||
123 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:9002') | ||
124 | }) | ||
125 | |||
126 | it('Should hide its videos', async function () { | ||
127 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | ||
128 | |||
129 | const videos: Video[] = res.body.data | ||
130 | expect(videos).to.have.lengthOf(3) | ||
131 | |||
132 | const v = videos.find(v => v.name === 'video user 2') | ||
133 | expect(v).to.be.undefined | ||
134 | }) | ||
135 | |||
136 | it('Should block a local account', async function () { | ||
137 | await addAccountToAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') | ||
138 | }) | ||
139 | |||
140 | it('Should hide its videos', async function () { | ||
141 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | ||
142 | |||
143 | const videos: Video[] = res.body.data | ||
144 | expect(videos).to.have.lengthOf(2) | ||
145 | |||
146 | const v = videos.find(v => v.name === 'video user 1') | ||
147 | expect(v).to.be.undefined | ||
148 | }) | ||
149 | |||
150 | it('Should hide its comments', async function () { | ||
151 | const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', servers[0].accessToken) | ||
152 | |||
153 | const threads: VideoComment[] = resThreads.body.data | ||
154 | expect(threads).to.have.lengthOf(1) | ||
155 | expect(threads[0].totalReplies).to.equal(0) | ||
156 | |||
157 | const t = threads.find(t => t.text === 'comment user 1') | ||
158 | expect(t).to.be.undefined | ||
159 | |||
160 | for (const thread of threads) { | ||
161 | const res = await getVideoThreadComments(servers[0].url, videoUUID1, thread.id, servers[0].accessToken) | ||
162 | |||
163 | const tree: VideoCommentThreadTree = res.body | ||
164 | expect(tree.children).to.have.lengthOf(0) | ||
165 | } | ||
166 | }) | ||
167 | |||
168 | it('Should list all the videos with another user', async function () { | ||
169 | return checkAllVideos(servers[0].url, userToken1) | ||
170 | }) | ||
171 | |||
172 | it('Should list all the comments with another user', async function () { | ||
173 | return checkAllComments(servers[0].url, userToken1, videoUUID1) | ||
174 | }) | ||
175 | |||
176 | it('Should list blocked accounts', async function () { | ||
177 | { | ||
178 | const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
179 | const blocks: AccountBlock[] = res.body.data | ||
180 | |||
181 | expect(res.body.total).to.equal(2) | ||
182 | |||
183 | const block = blocks[0] | ||
184 | expect(block.byAccount.displayName).to.equal('root') | ||
185 | expect(block.byAccount.name).to.equal('root') | ||
186 | expect(block.blockedAccount.displayName).to.equal('user2') | ||
187 | expect(block.blockedAccount.name).to.equal('user2') | ||
188 | expect(block.blockedAccount.host).to.equal('localhost:9002') | ||
189 | } | ||
190 | |||
191 | { | ||
192 | const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 1, 2, 'createdAt') | ||
193 | const blocks: AccountBlock[] = res.body.data | ||
194 | |||
195 | expect(res.body.total).to.equal(2) | ||
196 | |||
197 | const block = blocks[0] | ||
198 | expect(block.byAccount.displayName).to.equal('root') | ||
199 | expect(block.byAccount.name).to.equal('root') | ||
200 | expect(block.blockedAccount.displayName).to.equal('user1') | ||
201 | expect(block.blockedAccount.name).to.equal('user1') | ||
202 | expect(block.blockedAccount.host).to.equal('localhost:9001') | ||
203 | } | ||
204 | }) | ||
205 | |||
206 | it('Should unblock the remote account', async function () { | ||
207 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user2@localhost:9002') | ||
208 | }) | ||
209 | |||
210 | it('Should display its videos', async function () { | ||
211 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | ||
212 | |||
213 | const videos: Video[] = res.body.data | ||
214 | expect(videos).to.have.lengthOf(3) | ||
215 | |||
216 | const v = videos.find(v => v.name === 'video user 2') | ||
217 | expect(v).not.to.be.undefined | ||
218 | }) | ||
219 | |||
220 | it('Should unblock the local account', async function () { | ||
221 | await removeAccountFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'user1') | ||
222 | }) | ||
223 | |||
224 | it('Should display its comments', function () { | ||
225 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) | ||
226 | }) | ||
227 | }) | ||
228 | |||
229 | describe('When managing server blocklist', function () { | ||
230 | it('Should list all videos', function () { | ||
231 | return checkAllVideos(servers[0].url, servers[0].accessToken) | ||
232 | }) | ||
233 | |||
234 | it('Should list the comments', function () { | ||
235 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) | ||
236 | }) | ||
237 | |||
238 | it('Should block a remote server', async function () { | ||
239 | await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:9002') | ||
240 | }) | ||
241 | |||
242 | it('Should hide its videos', async function () { | ||
243 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | ||
244 | |||
245 | const videos: Video[] = res.body.data | ||
246 | expect(videos).to.have.lengthOf(2) | ||
247 | |||
248 | const v1 = videos.find(v => v.name === 'video user 2') | ||
249 | const v2 = videos.find(v => v.name === 'video server 2') | ||
250 | |||
251 | expect(v1).to.be.undefined | ||
252 | expect(v2).to.be.undefined | ||
253 | }) | ||
254 | |||
255 | it('Should list all the videos with another user', async function () { | ||
256 | return checkAllVideos(servers[0].url, userToken1) | ||
257 | }) | ||
258 | |||
259 | it('Should hide its comments') | ||
260 | |||
261 | it('Should list blocked servers', async function () { | ||
262 | const res = await getServerBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
263 | const blocks: ServerBlock[] = res.body.data | ||
264 | |||
265 | expect(res.body.total).to.equal(1) | ||
266 | |||
267 | const block = blocks[0] | ||
268 | expect(block.byAccount.displayName).to.equal('root') | ||
269 | expect(block.byAccount.name).to.equal('root') | ||
270 | expect(block.blockedServer.host).to.equal('localhost:9002') | ||
271 | }) | ||
272 | |||
273 | it('Should unblock the remote server', async function () { | ||
274 | await removeServerFromAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:9002') | ||
275 | }) | ||
276 | |||
277 | it('Should display its videos', function () { | ||
278 | return checkAllVideos(servers[0].url, servers[0].accessToken) | ||
279 | }) | ||
280 | |||
281 | it('Should display its comments', function () { | ||
282 | return checkAllComments(servers[0].url, servers[0].accessToken, videoUUID1) | ||
283 | }) | ||
284 | }) | ||
285 | |||
286 | after(async function () { | ||
287 | killallServers(servers) | ||
288 | |||
289 | // Keep the logs if the test failed | ||
290 | if (this[ 'ok' ]) { | ||
291 | await flushTests() | ||
292 | } | ||
293 | }) | ||
294 | }) | ||
diff --git a/server/tests/api/users/blocklist.ts b/server/tests/api/users/blocklist.ts new file mode 100644 index 000000000..99fe04b8c --- /dev/null +++ b/server/tests/api/users/blocklist.ts | |||
@@ -0,0 +1,500 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { AccountBlock, ServerBlock, Video } from '../../../../shared/index' | ||
6 | import { | ||
7 | createUser, | ||
8 | doubleFollow, | ||
9 | flushAndRunMultipleServers, | ||
10 | flushTests, | ||
11 | killallServers, | ||
12 | ServerInfo, | ||
13 | uploadVideo, | ||
14 | userLogin | ||
15 | } from '../../utils/index' | ||
16 | import { setAccessTokensToServers } from '../../utils/users/login' | ||
17 | import { getVideosListWithToken } from '../../utils/videos/videos' | ||
18 | import { | ||
19 | addVideoCommentReply, | ||
20 | addVideoCommentThread, | ||
21 | getVideoCommentThreads, | ||
22 | getVideoThreadComments | ||
23 | } from '../../utils/videos/video-comments' | ||
24 | import { waitJobs } from '../../utils/server/jobs' | ||
25 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
26 | import { | ||
27 | addAccountToAccountBlocklist, | ||
28 | addAccountToServerBlocklist, | ||
29 | addServerToAccountBlocklist, | ||
30 | addServerToServerBlocklist, | ||
31 | getAccountBlocklistByAccount, | ||
32 | getAccountBlocklistByServer, | ||
33 | getServerBlocklistByAccount, | ||
34 | getServerBlocklistByServer, | ||
35 | removeAccountFromAccountBlocklist, | ||
36 | removeAccountFromServerBlocklist, | ||
37 | removeServerFromAccountBlocklist, | ||
38 | removeServerFromServerBlocklist | ||
39 | } from '../../utils/users/blocklist' | ||
40 | |||
41 | const expect = chai.expect | ||
42 | |||
43 | async function checkAllVideos (url: string, token: string) { | ||
44 | const res = await getVideosListWithToken(url, token) | ||
45 | |||
46 | expect(res.body.data).to.have.lengthOf(4) | ||
47 | } | ||
48 | |||
49 | async function checkAllComments (url: string, token: string, videoUUID: string) { | ||
50 | const resThreads = await getVideoCommentThreads(url, videoUUID, 0, 5, '-createdAt', token) | ||
51 | |||
52 | const threads: VideoComment[] = resThreads.body.data | ||
53 | expect(threads).to.have.lengthOf(2) | ||
54 | |||
55 | for (const thread of threads) { | ||
56 | const res = await getVideoThreadComments(url, videoUUID, thread.id, token) | ||
57 | |||
58 | const tree: VideoCommentThreadTree = res.body | ||
59 | expect(tree.children).to.have.lengthOf(1) | ||
60 | } | ||
61 | } | ||
62 | |||
63 | describe('Test blocklist', function () { | ||
64 | let servers: ServerInfo[] | ||
65 | let videoUUID1: string | ||
66 | let videoUUID2: string | ||
67 | let userToken1: string | ||
68 | let userModeratorToken: string | ||
69 | let userToken2: string | ||
70 | |||
71 | before(async function () { | ||
72 | this.timeout(60000) | ||
73 | |||
74 | await flushTests() | ||
75 | |||
76 | servers = await flushAndRunMultipleServers(2) | ||
77 | await setAccessTokensToServers(servers) | ||
78 | |||
79 | { | ||
80 | const user = { username: 'user1', password: 'password' } | ||
81 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
82 | |||
83 | userToken1 = await userLogin(servers[0], user) | ||
84 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) | ||
85 | } | ||
86 | |||
87 | { | ||
88 | const user = { username: 'moderator', password: 'password' } | ||
89 | await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) | ||
90 | |||
91 | userModeratorToken = await userLogin(servers[0], user) | ||
92 | } | ||
93 | |||
94 | { | ||
95 | const user = { username: 'user2', password: 'password' } | ||
96 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | ||
97 | |||
98 | userToken2 = await userLogin(servers[1], user) | ||
99 | await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) | ||
100 | } | ||
101 | |||
102 | { | ||
103 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) | ||
104 | videoUUID1 = res.body.video.uuid | ||
105 | } | ||
106 | |||
107 | { | ||
108 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) | ||
109 | videoUUID2 = res.body.video.uuid | ||
110 | } | ||
111 | |||
112 | await doubleFollow(servers[0], servers[1]) | ||
113 | |||
114 | { | ||
115 | const resComment = await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, 'comment root 1') | ||
116 | const resReply = await addVideoCommentReply(servers[ 0 ].url, userToken1, videoUUID1, resComment.body.comment.id, 'comment user 1') | ||
117 | await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resReply.body.comment.id, 'comment root 1') | ||
118 | } | ||
119 | |||
120 | { | ||
121 | const resComment = await addVideoCommentThread(servers[ 0 ].url, userToken1, videoUUID1, 'comment user 1') | ||
122 | await addVideoCommentReply(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1, resComment.body.comment.id, 'comment root 1') | ||
123 | } | ||
124 | |||
125 | await waitJobs(servers) | ||
126 | }) | ||
127 | |||
128 | describe('User blocklist', function () { | ||
129 | |||
130 | describe('When managing account blocklist', function () { | ||
131 | it('Should list all videos', function () { | ||
132 | return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
133 | }) | ||
134 | |||
135 | it('Should list the comments', function () { | ||
136 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
137 | }) | ||
138 | |||
139 | it('Should block a remote account', async function () { | ||
140 | await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') | ||
141 | }) | ||
142 | |||
143 | it('Should hide its videos', async function () { | ||
144 | const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
145 | |||
146 | const videos: Video[] = res.body.data | ||
147 | expect(videos).to.have.lengthOf(3) | ||
148 | |||
149 | const v = videos.find(v => v.name === 'video user 2') | ||
150 | expect(v).to.be.undefined | ||
151 | }) | ||
152 | |||
153 | it('Should block a local account', async function () { | ||
154 | await addAccountToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1') | ||
155 | }) | ||
156 | |||
157 | it('Should hide its videos', async function () { | ||
158 | const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
159 | |||
160 | const videos: Video[] = res.body.data | ||
161 | expect(videos).to.have.lengthOf(2) | ||
162 | |||
163 | const v = videos.find(v => v.name === 'video user 1') | ||
164 | expect(v).to.be.undefined | ||
165 | }) | ||
166 | |||
167 | it('Should hide its comments', async function () { | ||
168 | const resThreads = await getVideoCommentThreads(servers[ 0 ].url, videoUUID1, 0, 5, '-createdAt', servers[ 0 ].accessToken) | ||
169 | |||
170 | const threads: VideoComment[] = resThreads.body.data | ||
171 | expect(threads).to.have.lengthOf(1) | ||
172 | expect(threads[ 0 ].totalReplies).to.equal(0) | ||
173 | |||
174 | const t = threads.find(t => t.text === 'comment user 1') | ||
175 | expect(t).to.be.undefined | ||
176 | |||
177 | for (const thread of threads) { | ||
178 | const res = await getVideoThreadComments(servers[ 0 ].url, videoUUID1, thread.id, servers[ 0 ].accessToken) | ||
179 | |||
180 | const tree: VideoCommentThreadTree = res.body | ||
181 | expect(tree.children).to.have.lengthOf(0) | ||
182 | } | ||
183 | }) | ||
184 | |||
185 | it('Should list all the videos with another user', async function () { | ||
186 | return checkAllVideos(servers[ 0 ].url, userToken1) | ||
187 | }) | ||
188 | |||
189 | it('Should list all the comments with another user', async function () { | ||
190 | return checkAllComments(servers[ 0 ].url, userToken1, videoUUID1) | ||
191 | }) | ||
192 | |||
193 | it('Should list blocked accounts', async function () { | ||
194 | { | ||
195 | const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
196 | const blocks: AccountBlock[] = res.body.data | ||
197 | |||
198 | expect(res.body.total).to.equal(2) | ||
199 | |||
200 | const block = blocks[ 0 ] | ||
201 | expect(block.byAccount.displayName).to.equal('root') | ||
202 | expect(block.byAccount.name).to.equal('root') | ||
203 | expect(block.blockedAccount.displayName).to.equal('user2') | ||
204 | expect(block.blockedAccount.name).to.equal('user2') | ||
205 | expect(block.blockedAccount.host).to.equal('localhost:9002') | ||
206 | } | ||
207 | |||
208 | { | ||
209 | const res = await getAccountBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 1, 2, 'createdAt') | ||
210 | const blocks: AccountBlock[] = res.body.data | ||
211 | |||
212 | expect(res.body.total).to.equal(2) | ||
213 | |||
214 | const block = blocks[ 0 ] | ||
215 | expect(block.byAccount.displayName).to.equal('root') | ||
216 | expect(block.byAccount.name).to.equal('root') | ||
217 | expect(block.blockedAccount.displayName).to.equal('user1') | ||
218 | expect(block.blockedAccount.name).to.equal('user1') | ||
219 | expect(block.blockedAccount.host).to.equal('localhost:9001') | ||
220 | } | ||
221 | }) | ||
222 | |||
223 | it('Should unblock the remote account', async function () { | ||
224 | await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') | ||
225 | }) | ||
226 | |||
227 | it('Should display its videos', async function () { | ||
228 | const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
229 | |||
230 | const videos: Video[] = res.body.data | ||
231 | expect(videos).to.have.lengthOf(3) | ||
232 | |||
233 | const v = videos.find(v => v.name === 'video user 2') | ||
234 | expect(v).not.to.be.undefined | ||
235 | }) | ||
236 | |||
237 | it('Should unblock the local account', async function () { | ||
238 | await removeAccountFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1') | ||
239 | }) | ||
240 | |||
241 | it('Should display its comments', function () { | ||
242 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
243 | }) | ||
244 | }) | ||
245 | |||
246 | describe('When managing server blocklist', function () { | ||
247 | it('Should list all videos', function () { | ||
248 | return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
249 | }) | ||
250 | |||
251 | it('Should list the comments', function () { | ||
252 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
253 | }) | ||
254 | |||
255 | it('Should block a remote server', async function () { | ||
256 | await addServerToAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') | ||
257 | }) | ||
258 | |||
259 | it('Should hide its videos', async function () { | ||
260 | const res = await getVideosListWithToken(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
261 | |||
262 | const videos: Video[] = res.body.data | ||
263 | expect(videos).to.have.lengthOf(2) | ||
264 | |||
265 | const v1 = videos.find(v => v.name === 'video user 2') | ||
266 | const v2 = videos.find(v => v.name === 'video server 2') | ||
267 | |||
268 | expect(v1).to.be.undefined | ||
269 | expect(v2).to.be.undefined | ||
270 | }) | ||
271 | |||
272 | it('Should list all the videos with another user', async function () { | ||
273 | return checkAllVideos(servers[ 0 ].url, userToken1) | ||
274 | }) | ||
275 | |||
276 | it('Should hide its comments') | ||
277 | |||
278 | it('Should list blocked servers', async function () { | ||
279 | const res = await getServerBlocklistByAccount(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
280 | const blocks: ServerBlock[] = res.body.data | ||
281 | |||
282 | expect(res.body.total).to.equal(1) | ||
283 | |||
284 | const block = blocks[ 0 ] | ||
285 | expect(block.byAccount.displayName).to.equal('root') | ||
286 | expect(block.byAccount.name).to.equal('root') | ||
287 | expect(block.blockedServer.host).to.equal('localhost:9002') | ||
288 | }) | ||
289 | |||
290 | it('Should unblock the remote server', async function () { | ||
291 | await removeServerFromAccountBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') | ||
292 | }) | ||
293 | |||
294 | it('Should display its videos', function () { | ||
295 | return checkAllVideos(servers[ 0 ].url, servers[ 0 ].accessToken) | ||
296 | }) | ||
297 | |||
298 | it('Should display its comments', function () { | ||
299 | return checkAllComments(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID1) | ||
300 | }) | ||
301 | }) | ||
302 | }) | ||
303 | |||
304 | describe('Server blocklist', function () { | ||
305 | |||
306 | describe('When managing account blocklist', function () { | ||
307 | it('Should list all videos', async function () { | ||
308 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
309 | await checkAllVideos(servers[ 0 ].url, token) | ||
310 | } | ||
311 | }) | ||
312 | |||
313 | it('Should list the comments', async function () { | ||
314 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
315 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | ||
316 | } | ||
317 | }) | ||
318 | |||
319 | it('Should block a remote account', async function () { | ||
320 | await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') | ||
321 | }) | ||
322 | |||
323 | it('Should hide its videos', async function () { | ||
324 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
325 | const res = await getVideosListWithToken(servers[ 0 ].url, token) | ||
326 | |||
327 | const videos: Video[] = res.body.data | ||
328 | expect(videos).to.have.lengthOf(3) | ||
329 | |||
330 | const v = videos.find(v => v.name === 'video user 2') | ||
331 | expect(v).to.be.undefined | ||
332 | } | ||
333 | }) | ||
334 | |||
335 | it('Should block a local account', async function () { | ||
336 | await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1') | ||
337 | }) | ||
338 | |||
339 | it('Should hide its videos', async function () { | ||
340 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
341 | const res = await getVideosListWithToken(servers[ 0 ].url, token) | ||
342 | |||
343 | const videos: Video[] = res.body.data | ||
344 | expect(videos).to.have.lengthOf(2) | ||
345 | |||
346 | const v = videos.find(v => v.name === 'video user 1') | ||
347 | expect(v).to.be.undefined | ||
348 | } | ||
349 | }) | ||
350 | |||
351 | it('Should hide its comments', async function () { | ||
352 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
353 | const resThreads = await getVideoCommentThreads(servers[ 0 ].url, videoUUID1, 0, 5, '-createdAt', token) | ||
354 | |||
355 | const threads: VideoComment[] = resThreads.body.data | ||
356 | expect(threads).to.have.lengthOf(1) | ||
357 | expect(threads[ 0 ].totalReplies).to.equal(0) | ||
358 | |||
359 | const t = threads.find(t => t.text === 'comment user 1') | ||
360 | expect(t).to.be.undefined | ||
361 | |||
362 | for (const thread of threads) { | ||
363 | const res = await getVideoThreadComments(servers[ 0 ].url, videoUUID1, thread.id, token) | ||
364 | |||
365 | const tree: VideoCommentThreadTree = res.body | ||
366 | expect(tree.children).to.have.lengthOf(0) | ||
367 | } | ||
368 | } | ||
369 | }) | ||
370 | |||
371 | it('Should list blocked accounts', async function () { | ||
372 | { | ||
373 | const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
374 | const blocks: AccountBlock[] = res.body.data | ||
375 | |||
376 | expect(res.body.total).to.equal(2) | ||
377 | |||
378 | const block = blocks[ 0 ] | ||
379 | expect(block.byAccount.displayName).to.equal('peertube') | ||
380 | expect(block.byAccount.name).to.equal('peertube') | ||
381 | expect(block.blockedAccount.displayName).to.equal('user2') | ||
382 | expect(block.blockedAccount.name).to.equal('user2') | ||
383 | expect(block.blockedAccount.host).to.equal('localhost:9002') | ||
384 | } | ||
385 | |||
386 | { | ||
387 | const res = await getAccountBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 1, 2, 'createdAt') | ||
388 | const blocks: AccountBlock[] = res.body.data | ||
389 | |||
390 | expect(res.body.total).to.equal(2) | ||
391 | |||
392 | const block = blocks[ 0 ] | ||
393 | expect(block.byAccount.displayName).to.equal('peertube') | ||
394 | expect(block.byAccount.name).to.equal('peertube') | ||
395 | expect(block.blockedAccount.displayName).to.equal('user1') | ||
396 | expect(block.blockedAccount.name).to.equal('user1') | ||
397 | expect(block.blockedAccount.host).to.equal('localhost:9001') | ||
398 | } | ||
399 | }) | ||
400 | |||
401 | it('Should unblock the remote account', async function () { | ||
402 | await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user2@localhost:9002') | ||
403 | }) | ||
404 | |||
405 | it('Should display its videos', async function () { | ||
406 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
407 | const res = await getVideosListWithToken(servers[ 0 ].url, token) | ||
408 | |||
409 | const videos: Video[] = res.body.data | ||
410 | expect(videos).to.have.lengthOf(3) | ||
411 | |||
412 | const v = videos.find(v => v.name === 'video user 2') | ||
413 | expect(v).not.to.be.undefined | ||
414 | } | ||
415 | }) | ||
416 | |||
417 | it('Should unblock the local account', async function () { | ||
418 | await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'user1') | ||
419 | }) | ||
420 | |||
421 | it('Should display its comments', async function () { | ||
422 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
423 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | ||
424 | } | ||
425 | }) | ||
426 | }) | ||
427 | |||
428 | describe('When managing server blocklist', function () { | ||
429 | it('Should list all videos', async function () { | ||
430 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
431 | await checkAllVideos(servers[ 0 ].url, token) | ||
432 | } | ||
433 | }) | ||
434 | |||
435 | it('Should list the comments', async function () { | ||
436 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
437 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | ||
438 | } | ||
439 | }) | ||
440 | |||
441 | it('Should block a remote server', async function () { | ||
442 | await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') | ||
443 | }) | ||
444 | |||
445 | it('Should hide its videos', async function () { | ||
446 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
447 | const res = await getVideosListWithToken(servers[ 0 ].url, token) | ||
448 | |||
449 | const videos: Video[] = res.body.data | ||
450 | expect(videos).to.have.lengthOf(2) | ||
451 | |||
452 | const v1 = videos.find(v => v.name === 'video user 2') | ||
453 | const v2 = videos.find(v => v.name === 'video server 2') | ||
454 | |||
455 | expect(v1).to.be.undefined | ||
456 | expect(v2).to.be.undefined | ||
457 | } | ||
458 | }) | ||
459 | |||
460 | it('Should hide its comments') | ||
461 | |||
462 | it('Should list blocked servers', async function () { | ||
463 | const res = await getServerBlocklistByServer(servers[ 0 ].url, servers[ 0 ].accessToken, 0, 1, 'createdAt') | ||
464 | const blocks: ServerBlock[] = res.body.data | ||
465 | |||
466 | expect(res.body.total).to.equal(1) | ||
467 | |||
468 | const block = blocks[ 0 ] | ||
469 | expect(block.byAccount.displayName).to.equal('peertube') | ||
470 | expect(block.byAccount.name).to.equal('peertube') | ||
471 | expect(block.blockedServer.host).to.equal('localhost:9002') | ||
472 | }) | ||
473 | |||
474 | it('Should unblock the remote server', async function () { | ||
475 | await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, 'localhost:9002') | ||
476 | }) | ||
477 | |||
478 | it('Should list all videos', async function () { | ||
479 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
480 | await checkAllVideos(servers[ 0 ].url, token) | ||
481 | } | ||
482 | }) | ||
483 | |||
484 | it('Should list the comments', async function () { | ||
485 | for (const token of [ userModeratorToken, servers[ 0 ].accessToken ]) { | ||
486 | await checkAllComments(servers[ 0 ].url, token, videoUUID1) | ||
487 | } | ||
488 | }) | ||
489 | }) | ||
490 | }) | ||
491 | |||
492 | after(async function () { | ||
493 | killallServers(servers) | ||
494 | |||
495 | // Keep the logs if the test failed | ||
496 | if (this[ 'ok' ]) { | ||
497 | await flushTests() | ||
498 | } | ||
499 | }) | ||
500 | }) | ||
diff --git a/server/tests/api/users/index.ts b/server/tests/api/users/index.ts index 21d75da3e..0a1b8b0b2 100644 --- a/server/tests/api/users/index.ts +++ b/server/tests/api/users/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import './blocklist' | ||
1 | import './user-subscriptions' | 2 | import './user-subscriptions' |
2 | import './users' | 3 | import './users' |
3 | import './users-verification' | 4 | import './users-verification' |