]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
86d13ec2 | 2 | |
afffe988 | 3 | import 'mocha' |
4f32032f C |
4 | import * as chai from 'chai' |
5 | import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' | |
6 | import { CustomConfig } from '@shared/models/server' | |
0e1dc3e7 | 7 | import { |
e1c55031 | 8 | addVideoCommentThread, |
a890d1e0 | 9 | blockUser, |
7c3b7976 | 10 | cleanupTests, |
a890d1e0 C |
11 | createUser, |
12 | deleteMe, | |
7c3b7976 | 13 | flushAndRunServer, |
c100a614 | 14 | getAccountRatings, |
edbc9325 | 15 | getAdminAbusesList, |
a890d1e0 | 16 | getBlacklistedVideosList, |
e1c55031 | 17 | getCustomConfig, |
a890d1e0 C |
18 | getMyUserInformation, |
19 | getMyUserVideoQuotaUsed, | |
20 | getMyUserVideoRating, | |
21 | getUserInformation, | |
22 | getUsersList, | |
23 | getUsersListPaginationAndSort, | |
1f20622f | 24 | getVideoChannel, |
a1587156 C |
25 | getVideosList, |
26 | installPlugin, | |
a890d1e0 C |
27 | login, |
28 | makePutBodyRequest, | |
29 | rateVideo, | |
1f20622f | 30 | registerUserWithChannel, |
a890d1e0 C |
31 | removeUser, |
32 | removeVideo, | |
4f32032f | 33 | reportAbuse, |
a890d1e0 C |
34 | ServerInfo, |
35 | testImage, | |
36 | unblockUser, | |
4f32032f | 37 | updateAbuse, |
e1c55031 | 38 | updateCustomSubConfig, |
a890d1e0 C |
39 | updateMyAvatar, |
40 | updateMyUser, | |
41 | updateUser, | |
42 | uploadVideo, | |
76314386 | 43 | userLogin, |
e1c55031 | 44 | waitJobs |
94565d52 C |
45 | } from '../../../../shared/extra-utils' |
46 | import { follow } from '../../../../shared/extra-utils/server/follows' | |
e1c55031 | 47 | import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
94565d52 | 48 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' |
1eddc9a7 | 49 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
2d53be02 | 50 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
0e1dc3e7 | 51 | |
afffe988 C |
52 | const expect = chai.expect |
53 | ||
0e1dc3e7 C |
54 | describe('Test users', function () { |
55 | let server: ServerInfo | |
56 | let accessToken: string | |
57 | let accessTokenUser: string | |
58 | let videoId: number | |
59 | let userId: number | |
f8b8c36b C |
60 | const user = { |
61 | username: 'user_1', | |
62 | password: 'super password' | |
63 | } | |
0e1dc3e7 C |
64 | |
65 | before(async function () { | |
e212f887 | 66 | this.timeout(30000) |
e1c55031 C |
67 | |
68 | server = await flushAndRunServer(1, { | |
69 | rates_limit: { | |
70 | login: { | |
71 | max: 30 | |
72 | } | |
73 | } | |
74 | }) | |
86d13ec2 C |
75 | |
76 | await setAccessTokensToServers([ server ]) | |
9b474844 C |
77 | |
78 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | |
0e1dc3e7 C |
79 | }) |
80 | ||
1eddc9a7 C |
81 | describe('OAuth client', function () { |
82 | it('Should create a new client') | |
0e1dc3e7 | 83 | |
1eddc9a7 | 84 | it('Should return the first client') |
0e1dc3e7 | 85 | |
1eddc9a7 | 86 | it('Should remove the last client') |
0e1dc3e7 | 87 | |
1eddc9a7 C |
88 | it('Should not login with an invalid client id', async function () { |
89 | const client = { id: 'client', secret: server.client.secret } | |
2d53be02 | 90 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 91 | |
1eddc9a7 C |
92 | expect(res.body.error).to.contain('client is invalid') |
93 | }) | |
0e1dc3e7 | 94 | |
1eddc9a7 C |
95 | it('Should not login with an invalid client secret', async function () { |
96 | const client = { id: server.client.id, secret: 'coucou' } | |
2d53be02 | 97 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 98 | |
1eddc9a7 C |
99 | expect(res.body.error).to.contain('client is invalid') |
100 | }) | |
0e1dc3e7 C |
101 | }) |
102 | ||
1eddc9a7 | 103 | describe('Login', function () { |
0e1dc3e7 | 104 | |
1eddc9a7 C |
105 | it('Should not login with an invalid username', async function () { |
106 | const user = { username: 'captain crochet', password: server.user.password } | |
2d53be02 | 107 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 108 | |
1eddc9a7 C |
109 | expect(res.body.error).to.contain('credentials are invalid') |
110 | }) | |
0e1dc3e7 | 111 | |
1eddc9a7 C |
112 | it('Should not login with an invalid password', async function () { |
113 | const user = { username: server.user.username, password: 'mew_three' } | |
2d53be02 | 114 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) |
0e1dc3e7 | 115 | |
1eddc9a7 C |
116 | expect(res.body.error).to.contain('credentials are invalid') |
117 | }) | |
0e1dc3e7 | 118 | |
1eddc9a7 C |
119 | it('Should not be able to upload a video', async function () { |
120 | accessToken = 'my_super_token' | |
0e1dc3e7 | 121 | |
1eddc9a7 | 122 | const videoAttributes = {} |
2d53be02 | 123 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 124 | }) |
0e1dc3e7 | 125 | |
1eddc9a7 C |
126 | it('Should not be able to follow', async function () { |
127 | accessToken = 'my_super_token' | |
2d53be02 | 128 | await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 129 | }) |
0e1dc3e7 | 130 | |
1eddc9a7 | 131 | it('Should not be able to unfollow') |
0e1dc3e7 | 132 | |
1eddc9a7 | 133 | it('Should be able to login', async function () { |
2d53be02 | 134 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) |
0e1dc3e7 | 135 | |
1eddc9a7 C |
136 | accessToken = res.body.access_token |
137 | }) | |
50b4dcce NB |
138 | |
139 | it('Should be able to login with an insensitive username', async function () { | |
140 | const user = { username: 'RoOt', password: server.user.password } | |
2d53be02 | 141 | await login(server.url, server.client, user, HttpStatusCode.OK_200) |
50b4dcce NB |
142 | |
143 | const user2 = { username: 'rOoT', password: server.user.password } | |
2d53be02 | 144 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) |
50b4dcce NB |
145 | |
146 | const user3 = { username: 'ROOt', password: server.user.password } | |
2d53be02 | 147 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) |
50b4dcce | 148 | }) |
0e1dc3e7 C |
149 | }) |
150 | ||
1eddc9a7 | 151 | describe('Upload', function () { |
0e1dc3e7 | 152 | |
1eddc9a7 C |
153 | it('Should upload the video with the correct token', async function () { |
154 | const videoAttributes = {} | |
155 | await uploadVideo(server.url, accessToken, videoAttributes) | |
156 | const res = await getVideosList(server.url) | |
a1587156 | 157 | const video = res.body.data[0] |
0e1dc3e7 | 158 | |
1eddc9a7 C |
159 | expect(video.account.name).to.equal('root') |
160 | videoId = video.id | |
161 | }) | |
162 | ||
163 | it('Should upload the video again with the correct token', async function () { | |
164 | const videoAttributes = {} | |
165 | await uploadVideo(server.url, accessToken, videoAttributes) | |
166 | }) | |
0e1dc3e7 C |
167 | }) |
168 | ||
1eddc9a7 | 169 | describe('Ratings', function () { |
22834691 | 170 | |
1eddc9a7 C |
171 | it('Should retrieve a video rating', async function () { |
172 | await rateVideo(server.url, accessToken, videoId, 'like') | |
173 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | |
174 | const rating = res.body | |
c100a614 | 175 | |
1eddc9a7 C |
176 | expect(rating.videoId).to.equal(videoId) |
177 | expect(rating.rating).to.equal('like') | |
178 | }) | |
c100a614 | 179 | |
1eddc9a7 C |
180 | it('Should retrieve ratings list', async function () { |
181 | await rateVideo(server.url, accessToken, videoId, 'like') | |
22834691 | 182 | |
2d53be02 | 183 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) |
22834691 | 184 | const ratings = res.body |
0e1dc3e7 | 185 | |
1eddc9a7 | 186 | expect(ratings.total).to.equal(1) |
a1587156 C |
187 | expect(ratings.data[0].video.id).to.equal(videoId) |
188 | expect(ratings.data[0].rating).to.equal('like') | |
1eddc9a7 | 189 | }) |
0e1dc3e7 | 190 | |
1eddc9a7 C |
191 | it('Should retrieve ratings list by rating type', async function () { |
192 | { | |
193 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | |
194 | const ratings = res.body | |
195 | expect(ratings.data.length).to.equal(1) | |
196 | } | |
197 | ||
198 | { | |
199 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | |
200 | const ratings = res.body | |
201 | expect(ratings.data.length).to.equal(0) | |
202 | } | |
203 | }) | |
0e1dc3e7 C |
204 | }) |
205 | ||
1eddc9a7 C |
206 | describe('Remove video', function () { |
207 | it('Should not be able to remove the video with an incorrect token', async function () { | |
2d53be02 | 208 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) |
1eddc9a7 | 209 | }) |
0e1dc3e7 | 210 | |
1eddc9a7 | 211 | it('Should not be able to remove the video with the token of another account') |
0e1dc3e7 | 212 | |
1eddc9a7 C |
213 | it('Should be able to remove the video with the correct token', async function () { |
214 | await removeVideo(server.url, accessToken, videoId) | |
215 | }) | |
0e1dc3e7 C |
216 | }) |
217 | ||
1eddc9a7 | 218 | describe('Logout', function () { |
7fed6375 C |
219 | it('Should logout (revoke token)', async function () { |
220 | await logout(server.url, server.accessToken) | |
221 | }) | |
0e1dc3e7 | 222 | |
7fed6375 | 223 | it('Should not be able to get the user information', async function () { |
2d53be02 | 224 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) |
7fed6375 | 225 | }) |
0e1dc3e7 | 226 | |
7fed6375 | 227 | it('Should not be able to upload a video', async function () { |
2d53be02 | 228 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) |
7fed6375 | 229 | }) |
0e1dc3e7 | 230 | |
1eddc9a7 C |
231 | it('Should not be able to rate a video', async function () { |
232 | const path = '/api/v1/videos/' | |
233 | const data = { | |
234 | rating: 'likes' | |
235 | } | |
0e1dc3e7 | 236 | |
1eddc9a7 C |
237 | const options = { |
238 | url: server.url, | |
239 | path: path + videoId, | |
240 | token: 'wrong token', | |
241 | fields: data, | |
2d53be02 | 242 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
1eddc9a7 C |
243 | } |
244 | await makePutBodyRequest(options) | |
245 | }) | |
0e1dc3e7 | 246 | |
e1c55031 C |
247 | it('Should be able to login again', async function () { |
248 | server.accessToken = await serverLogin(server) | |
249 | }) | |
0e1dc3e7 | 250 | |
1eddc9a7 | 251 | it('Should have an expired access token') |
0e1dc3e7 | 252 | |
1eddc9a7 C |
253 | it('Should refresh the token') |
254 | ||
e1c55031 C |
255 | it('Should be able to get my user information again', async function () { |
256 | await getMyUserInformation(server.url, server.accessToken) | |
257 | }) | |
0e1dc3e7 C |
258 | }) |
259 | ||
1eddc9a7 | 260 | describe('Creating a user', function () { |
ce5496d6 | 261 | |
1eddc9a7 C |
262 | it('Should be able to create a new user', async function () { |
263 | await createUser({ | |
264 | url: server.url, | |
265 | accessToken: accessToken, | |
266 | username: user.username, | |
267 | password: user.password, | |
268 | videoQuota: 2 * 1024 * 1024, | |
3487330d | 269 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST |
1eddc9a7 C |
270 | }) |
271 | }) | |
a76138ff | 272 | |
1eddc9a7 C |
273 | it('Should be able to login with this user', async function () { |
274 | accessTokenUser = await userLogin(server, user) | |
275 | }) | |
a76138ff | 276 | |
1eddc9a7 C |
277 | it('Should be able to get user information', async function () { |
278 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | |
ac0868bc | 279 | const userMe: MyUser = res1.body |
1eddc9a7 | 280 | |
76314386 | 281 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) |
1eddc9a7 C |
282 | const userGet: User = res2.body |
283 | ||
284 | for (const user of [ userMe, userGet ]) { | |
285 | expect(user.username).to.equal('user_1') | |
286 | expect(user.email).to.equal('user_1@example.com') | |
287 | expect(user.nsfwPolicy).to.equal('display') | |
288 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
289 | expect(user.roleLabel).to.equal('User') | |
290 | expect(user.id).to.be.a('number') | |
291 | expect(user.account.displayName).to.equal('user_1') | |
292 | expect(user.account.description).to.be.null | |
293 | } | |
294 | ||
295 | expect(userMe.adminFlags).to.be.undefined | |
3487330d | 296 | expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST) |
29128b2f RK |
297 | |
298 | expect(userMe.specialPlaylists).to.have.lengthOf(1) | |
ac0868bc | 299 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) |
76314386 RK |
300 | |
301 | // Check stats are included with withStats | |
302 | expect(userGet.videosCount).to.be.a('number') | |
303 | expect(userGet.videosCount).to.equal(0) | |
304 | expect(userGet.videoCommentsCount).to.be.a('number') | |
305 | expect(userGet.videoCommentsCount).to.equal(0) | |
4f32032f C |
306 | expect(userGet.abusesCount).to.be.a('number') |
307 | expect(userGet.abusesCount).to.equal(0) | |
308 | expect(userGet.abusesAcceptedCount).to.be.a('number') | |
309 | expect(userGet.abusesAcceptedCount).to.equal(0) | |
1eddc9a7 | 310 | }) |
ce5496d6 C |
311 | }) |
312 | ||
1eddc9a7 | 313 | describe('My videos & quotas', function () { |
11474c3c | 314 | |
1eddc9a7 | 315 | it('Should be able to upload a video with this user', async function () { |
5600def4 | 316 | this.timeout(10000) |
0e1dc3e7 | 317 | |
1eddc9a7 C |
318 | const videoAttributes = { |
319 | name: 'super user video', | |
320 | fixture: 'video_short.webm' | |
321 | } | |
322 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | |
323 | }) | |
afffe988 | 324 | |
1eddc9a7 C |
325 | it('Should have video quota updated', async function () { |
326 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | |
327 | const data = res.body | |
0e1dc3e7 | 328 | |
1eddc9a7 | 329 | expect(data.videoQuotaUsed).to.equal(218910) |
0e1dc3e7 | 330 | |
1eddc9a7 | 331 | const resUsers = await getUsersList(server.url, server.accessToken) |
0e1dc3e7 | 332 | |
1eddc9a7 C |
333 | const users: User[] = resUsers.body.data |
334 | const tmpUser = users.find(u => u.username === user.username) | |
335 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | |
336 | }) | |
0e1dc3e7 | 337 | |
1eddc9a7 C |
338 | it('Should be able to list my videos', async function () { |
339 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | |
340 | expect(res.body.total).to.equal(1) | |
0e1dc3e7 | 341 | |
1eddc9a7 C |
342 | const videos = res.body.data |
343 | expect(videos).to.have.lengthOf(1) | |
afffe988 | 344 | |
a1587156 | 345 | const video: Video = videos[0] |
a18f275d C |
346 | expect(video.name).to.equal('super user video') |
347 | expect(video.thumbnailPath).to.not.be.null | |
348 | expect(video.previewPath).to.not.be.null | |
1eddc9a7 | 349 | }) |
cca1e13b C |
350 | |
351 | it('Should be able to search in my videos', async function () { | |
352 | { | |
353 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') | |
354 | expect(res.body.total).to.equal(1) | |
355 | ||
356 | const videos = res.body.data | |
357 | expect(videos).to.have.lengthOf(1) | |
358 | } | |
359 | ||
360 | { | |
361 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') | |
362 | expect(res.body.total).to.equal(0) | |
363 | ||
364 | const videos = res.body.data | |
365 | expect(videos).to.have.lengthOf(0) | |
366 | } | |
367 | }) | |
5600def4 C |
368 | |
369 | it('Should disable webtorrent, enable HLS, and update my quota', async function () { | |
370 | this.timeout(60000) | |
371 | ||
372 | { | |
373 | const res = await getCustomConfig(server.url, server.accessToken) | |
374 | const config = res.body as CustomConfig | |
375 | config.transcoding.webtorrent.enabled = false | |
376 | config.transcoding.hls.enabled = true | |
377 | config.transcoding.enabled = true | |
378 | await updateCustomSubConfig(server.url, server.accessToken, config) | |
379 | } | |
380 | ||
381 | { | |
382 | const videoAttributes = { | |
383 | name: 'super user video 2', | |
384 | fixture: 'video_short.webm' | |
385 | } | |
386 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | |
387 | ||
388 | await waitJobs([ server ]) | |
389 | } | |
390 | ||
391 | { | |
392 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | |
393 | const data = res.body | |
394 | ||
395 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | |
396 | } | |
397 | }) | |
0e1dc3e7 C |
398 | }) |
399 | ||
1eddc9a7 | 400 | describe('Users listing', function () { |
0e1dc3e7 | 401 | |
1eddc9a7 C |
402 | it('Should list all the users', async function () { |
403 | const res = await getUsersList(server.url, server.accessToken) | |
404 | const result = res.body | |
405 | const total = result.total | |
406 | const users = result.data | |
afffe988 | 407 | |
1eddc9a7 C |
408 | expect(total).to.equal(2) |
409 | expect(users).to.be.an('array') | |
410 | expect(users.length).to.equal(2) | |
0e1dc3e7 | 411 | |
a1587156 | 412 | const user = users[0] |
1eddc9a7 C |
413 | expect(user.username).to.equal('user_1') |
414 | expect(user.email).to.equal('user_1@example.com') | |
415 | expect(user.nsfwPolicy).to.equal('display') | |
0e1dc3e7 | 416 | |
a1587156 | 417 | const rootUser = users[1] |
1eddc9a7 | 418 | expect(rootUser.username).to.equal('root') |
48f07b4a | 419 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 | 420 | expect(user.nsfwPolicy).to.equal('display') |
afffe988 | 421 | |
3cc665f4 C |
422 | expect(rootUser.lastLoginDate).to.exist |
423 | expect(user.lastLoginDate).to.exist | |
424 | ||
1eddc9a7 C |
425 | userId = user.id |
426 | }) | |
0e1dc3e7 | 427 | |
1eddc9a7 C |
428 | it('Should list only the first user by username asc', async function () { |
429 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | |
0e1dc3e7 | 430 | |
1eddc9a7 C |
431 | const result = res.body |
432 | const total = result.total | |
433 | const users = result.data | |
a7ba16b6 | 434 | |
1eddc9a7 C |
435 | expect(total).to.equal(2) |
436 | expect(users.length).to.equal(1) | |
afffe988 | 437 | |
a1587156 | 438 | const user = users[0] |
1eddc9a7 | 439 | expect(user.username).to.equal('root') |
48f07b4a | 440 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
1eddc9a7 C |
441 | expect(user.roleLabel).to.equal('Administrator') |
442 | expect(user.nsfwPolicy).to.equal('display') | |
443 | }) | |
0e1dc3e7 | 444 | |
1eddc9a7 C |
445 | it('Should list only the first user by username desc', async function () { |
446 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | |
447 | const result = res.body | |
448 | const total = result.total | |
449 | const users = result.data | |
24b9417c | 450 | |
1eddc9a7 C |
451 | expect(total).to.equal(2) |
452 | expect(users.length).to.equal(1) | |
24b9417c | 453 | |
a1587156 | 454 | const user = users[0] |
1eddc9a7 C |
455 | expect(user.username).to.equal('user_1') |
456 | expect(user.email).to.equal('user_1@example.com') | |
457 | expect(user.nsfwPolicy).to.equal('display') | |
458 | }) | |
24b9417c | 459 | |
1eddc9a7 C |
460 | it('Should list only the second user by createdAt desc', async function () { |
461 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | |
462 | const result = res.body | |
463 | const total = result.total | |
464 | const users = result.data | |
24b9417c | 465 | |
1eddc9a7 | 466 | expect(total).to.equal(2) |
24b9417c C |
467 | expect(users.length).to.equal(1) |
468 | ||
a1587156 | 469 | const user = users[0] |
1eddc9a7 C |
470 | expect(user.username).to.equal('user_1') |
471 | expect(user.email).to.equal('user_1@example.com') | |
472 | expect(user.nsfwPolicy).to.equal('display') | |
473 | }) | |
24b9417c | 474 | |
1eddc9a7 C |
475 | it('Should list all the users by createdAt asc', async function () { |
476 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | |
477 | const result = res.body | |
478 | const total = result.total | |
479 | const users = result.data | |
24b9417c | 480 | |
1eddc9a7 | 481 | expect(total).to.equal(2) |
24b9417c C |
482 | expect(users.length).to.equal(2) |
483 | ||
a1587156 C |
484 | expect(users[0].username).to.equal('root') |
485 | expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') | |
486 | expect(users[0].nsfwPolicy).to.equal('display') | |
24b9417c | 487 | |
a1587156 C |
488 | expect(users[1].username).to.equal('user_1') |
489 | expect(users[1].email).to.equal('user_1@example.com') | |
490 | expect(users[1].nsfwPolicy).to.equal('display') | |
11ba2ab3 | 491 | }) |
0e1dc3e7 | 492 | |
1eddc9a7 C |
493 | it('Should search user by username', async function () { |
494 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | |
495 | const users = res.body.data as User[] | |
496 | ||
497 | expect(res.body.total).to.equal(1) | |
498 | expect(users.length).to.equal(1) | |
0e1dc3e7 | 499 | |
a1587156 | 500 | expect(users[0].username).to.equal('root') |
11ba2ab3 | 501 | }) |
0e1dc3e7 | 502 | |
1eddc9a7 C |
503 | it('Should search user by email', async function () { |
504 | { | |
505 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | |
506 | const users = res.body.data as User[] | |
0e1dc3e7 | 507 | |
1eddc9a7 C |
508 | expect(res.body.total).to.equal(1) |
509 | expect(users.length).to.equal(1) | |
5c98d3bf | 510 | |
a1587156 C |
511 | expect(users[0].username).to.equal('user_1') |
512 | expect(users[0].email).to.equal('user_1@example.com') | |
1eddc9a7 | 513 | } |
7efe153b | 514 | |
1eddc9a7 C |
515 | { |
516 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | |
517 | const users = res.body.data as User[] | |
7efe153b | 518 | |
1eddc9a7 C |
519 | expect(res.body.total).to.equal(2) |
520 | expect(users.length).to.equal(2) | |
7efe153b | 521 | |
a1587156 C |
522 | expect(users[0].username).to.equal('root') |
523 | expect(users[1].username).to.equal('user_1') | |
1eddc9a7 | 524 | } |
11ba2ab3 | 525 | }) |
5c98d3bf C |
526 | }) |
527 | ||
1eddc9a7 C |
528 | describe('Update my account', function () { |
529 | it('Should update my password', async function () { | |
530 | await updateMyUser({ | |
531 | url: server.url, | |
532 | accessToken: accessTokenUser, | |
533 | currentPassword: 'super password', | |
43d0ea7f | 534 | password: 'new password' |
1eddc9a7 C |
535 | }) |
536 | user.password = 'new password' | |
c5911fd3 | 537 | |
2d53be02 | 538 | await userLogin(server, user, HttpStatusCode.OK_200) |
c5911fd3 C |
539 | }) |
540 | ||
1eddc9a7 C |
541 | it('Should be able to change the NSFW display attribute', async function () { |
542 | await updateMyUser({ | |
543 | url: server.url, | |
544 | accessToken: accessTokenUser, | |
545 | nsfwPolicy: 'do_not_list' | |
546 | }) | |
547 | ||
548 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
549 | const user = res.body | |
550 | ||
551 | expect(user.username).to.equal('user_1') | |
552 | expect(user.email).to.equal('user_1@example.com') | |
553 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
554 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
555 | expect(user.id).to.be.a('number') | |
556 | expect(user.account.displayName).to.equal('user_1') | |
557 | expect(user.account.description).to.be.null | |
558 | }) | |
c5911fd3 | 559 | |
1eddc9a7 C |
560 | it('Should be able to change the autoPlayVideo attribute', async function () { |
561 | await updateMyUser({ | |
562 | url: server.url, | |
563 | accessToken: accessTokenUser, | |
564 | autoPlayVideo: false | |
565 | }) | |
c5911fd3 | 566 | |
1eddc9a7 C |
567 | const res = await getMyUserInformation(server.url, accessTokenUser) |
568 | const user = res.body | |
569 | ||
570 | expect(user.autoPlayVideo).to.be.false | |
ed56ad11 C |
571 | }) |
572 | ||
6aa54148 L |
573 | it('Should be able to change the autoPlayNextVideo attribute', async function () { |
574 | await updateMyUser({ | |
575 | url: server.url, | |
576 | accessToken: accessTokenUser, | |
577 | autoPlayNextVideo: true | |
578 | }) | |
579 | ||
580 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
581 | const user = res.body | |
582 | ||
583 | expect(user.autoPlayNextVideo).to.be.true | |
584 | }) | |
585 | ||
675a8fc7 | 586 | it('Should be able to change the email attribute', async function () { |
1eddc9a7 C |
587 | await updateMyUser({ |
588 | url: server.url, | |
589 | accessToken: accessTokenUser, | |
675a8fc7 | 590 | currentPassword: 'new password', |
1eddc9a7 C |
591 | email: 'updated@example.com' |
592 | }) | |
593 | ||
594 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
595 | const user = res.body | |
596 | ||
597 | expect(user.username).to.equal('user_1') | |
598 | expect(user.email).to.equal('updated@example.com') | |
599 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
600 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
601 | expect(user.id).to.be.a('number') | |
602 | expect(user.account.displayName).to.equal('user_1') | |
603 | expect(user.account.description).to.be.null | |
604 | }) | |
ed56ad11 | 605 | |
f619de0e C |
606 | it('Should be able to update my avatar with a gif', async function () { |
607 | const fixture = 'avatar.gif' | |
ed56ad11 | 608 | |
1eddc9a7 C |
609 | await updateMyAvatar({ |
610 | url: server.url, | |
611 | accessToken: accessTokenUser, | |
612 | fixture | |
613 | }) | |
2422c46b | 614 | |
1eddc9a7 C |
615 | const res = await getMyUserInformation(server.url, accessTokenUser) |
616 | const user = res.body | |
2422c46b | 617 | |
f619de0e C |
618 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') |
619 | }) | |
620 | ||
621 | it('Should be able to update my avatar with a gif, and then a png', async function () { | |
622 | for (const extension of [ '.png', '.gif' ]) { | |
623 | const fixture = 'avatar' + extension | |
624 | ||
625 | await updateMyAvatar({ | |
626 | url: server.url, | |
627 | accessToken: accessTokenUser, | |
628 | fixture | |
629 | }) | |
630 | ||
631 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
632 | const user = res.body | |
633 | ||
634 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) | |
635 | } | |
1eddc9a7 C |
636 | }) |
637 | ||
638 | it('Should be able to update my display name', async function () { | |
639 | await updateMyUser({ | |
640 | url: server.url, | |
641 | accessToken: accessTokenUser, | |
642 | displayName: 'new display name' | |
643 | }) | |
644 | ||
645 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
646 | const user = res.body | |
647 | ||
648 | expect(user.username).to.equal('user_1') | |
649 | expect(user.email).to.equal('updated@example.com') | |
650 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
651 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
652 | expect(user.id).to.be.a('number') | |
653 | expect(user.account.displayName).to.equal('new display name') | |
654 | expect(user.account.description).to.be.null | |
655 | }) | |
2422c46b | 656 | |
1eddc9a7 C |
657 | it('Should be able to update my description', async function () { |
658 | await updateMyUser({ | |
659 | url: server.url, | |
660 | accessToken: accessTokenUser, | |
661 | description: 'my super description updated' | |
662 | }) | |
663 | ||
664 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
43d0ea7f | 665 | const user: User = res.body |
1eddc9a7 C |
666 | |
667 | expect(user.username).to.equal('user_1') | |
668 | expect(user.email).to.equal('updated@example.com') | |
669 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
670 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
671 | expect(user.id).to.be.a('number') | |
672 | expect(user.account.displayName).to.equal('new display name') | |
673 | expect(user.account.description).to.equal('my super description updated') | |
43d0ea7f C |
674 | expect(user.noWelcomeModal).to.be.false |
675 | expect(user.noInstanceConfigWarningModal).to.be.false | |
1eddc9a7 | 676 | }) |
9b474844 C |
677 | |
678 | it('Should be able to update my theme', async function () { | |
679 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | |
680 | await updateMyUser({ | |
681 | url: server.url, | |
682 | accessToken: accessTokenUser, | |
683 | theme | |
684 | }) | |
685 | ||
686 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
687 | const body: User = res.body | |
688 | ||
689 | expect(body.theme).to.equal(theme) | |
690 | } | |
691 | }) | |
43d0ea7f C |
692 | |
693 | it('Should be able to update my modal preferences', async function () { | |
694 | await updateMyUser({ | |
695 | url: server.url, | |
696 | accessToken: accessTokenUser, | |
697 | noInstanceConfigWarningModal: true, | |
698 | noWelcomeModal: true | |
699 | }) | |
700 | ||
701 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
702 | const user: User = res.body | |
703 | ||
704 | expect(user.noWelcomeModal).to.be.true | |
705 | expect(user.noInstanceConfigWarningModal).to.be.true | |
706 | }) | |
0e1dc3e7 C |
707 | }) |
708 | ||
1eddc9a7 | 709 | describe('Updating another user', function () { |
1eddc9a7 C |
710 | it('Should be able to update another user', async function () { |
711 | await updateUser({ | |
712 | url: server.url, | |
713 | userId, | |
714 | accessToken, | |
715 | email: 'updated2@example.com', | |
716 | emailVerified: true, | |
717 | videoQuota: 42, | |
718 | role: UserRole.MODERATOR, | |
6d989edc C |
719 | adminFlags: UserAdminFlag.NONE, |
720 | pluginAuth: 'toto' | |
1eddc9a7 C |
721 | }) |
722 | ||
723 | const res = await getUserInformation(server.url, accessToken, userId) | |
6d989edc | 724 | const user = res.body as User |
1eddc9a7 C |
725 | |
726 | expect(user.username).to.equal('user_1') | |
727 | expect(user.email).to.equal('updated2@example.com') | |
728 | expect(user.emailVerified).to.be.true | |
729 | expect(user.nsfwPolicy).to.equal('do_not_list') | |
730 | expect(user.videoQuota).to.equal(42) | |
731 | expect(user.roleLabel).to.equal('Moderator') | |
732 | expect(user.id).to.be.a('number') | |
733 | expect(user.adminFlags).to.equal(UserAdminFlag.NONE) | |
6d989edc C |
734 | expect(user.pluginAuth).to.equal('toto') |
735 | }) | |
736 | ||
737 | it('Should reset the auth plugin', async function () { | |
738 | await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) | |
739 | ||
740 | const res = await getUserInformation(server.url, accessToken, userId) | |
741 | const user = res.body as User | |
742 | expect(user.pluginAuth).to.be.null | |
1eddc9a7 | 743 | }) |
f8b8c36b | 744 | |
1eddc9a7 | 745 | it('Should have removed the user token', async function () { |
2d53be02 | 746 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
f8b8c36b | 747 | |
1eddc9a7 | 748 | accessTokenUser = await userLogin(server, user) |
b426edd4 C |
749 | }) |
750 | ||
1eddc9a7 C |
751 | it('Should be able to update another user password', async function () { |
752 | await updateUser({ | |
753 | url: server.url, | |
754 | userId, | |
755 | accessToken, | |
756 | password: 'password updated' | |
757 | }) | |
b426edd4 | 758 | |
2d53be02 | 759 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
b426edd4 | 760 | |
2d53be02 | 761 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) |
b426edd4 | 762 | |
1eddc9a7 C |
763 | user.password = 'password updated' |
764 | accessTokenUser = await userLogin(server, user) | |
765 | }) | |
757f0da3 C |
766 | }) |
767 | ||
1eddc9a7 C |
768 | describe('Video blacklists', function () { |
769 | it('Should be able to list video blacklist by a moderator', async function () { | |
770 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | |
771 | }) | |
0e1dc3e7 C |
772 | }) |
773 | ||
1eddc9a7 C |
774 | describe('Remove a user', function () { |
775 | it('Should be able to remove this user', async function () { | |
776 | await removeUser(server.url, userId, accessToken) | |
777 | }) | |
0e1dc3e7 | 778 | |
1eddc9a7 | 779 | it('Should not be able to login with this user', async function () { |
2d53be02 | 780 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) |
1eddc9a7 | 781 | }) |
0e1dc3e7 | 782 | |
1eddc9a7 C |
783 | it('Should not have videos of this user', async function () { |
784 | const res = await getVideosList(server.url) | |
0e1dc3e7 | 785 | |
1eddc9a7 | 786 | expect(res.body.total).to.equal(1) |
0e1dc3e7 | 787 | |
a1587156 | 788 | const video = res.body.data[0] |
1eddc9a7 C |
789 | expect(video.account.name).to.equal('root') |
790 | }) | |
0e1dc3e7 C |
791 | }) |
792 | ||
1eddc9a7 | 793 | describe('Registering a new user', function () { |
76314386 RK |
794 | let user15AccessToken |
795 | ||
1eddc9a7 | 796 | it('Should register a new user', async function () { |
1f20622f | 797 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
e590b4a5 C |
798 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
799 | ||
800 | await registerUserWithChannel({ url: server.url, user, channel }) | |
1eddc9a7 | 801 | }) |
0e1dc3e7 | 802 | |
1eddc9a7 C |
803 | it('Should be able to login with this registered user', async function () { |
804 | const user15 = { | |
805 | username: 'user_15', | |
806 | password: 'my super password' | |
807 | } | |
5c98d3bf | 808 | |
76314386 | 809 | user15AccessToken = await userLogin(server, user15) |
1eddc9a7 | 810 | }) |
5c98d3bf | 811 | |
1f20622f | 812 | it('Should have the correct display name', async function () { |
76314386 | 813 | const res = await getMyUserInformation(server.url, user15AccessToken) |
1f20622f C |
814 | const user: User = res.body |
815 | ||
816 | expect(user.account.displayName).to.equal('super user 15') | |
817 | }) | |
818 | ||
1eddc9a7 | 819 | it('Should have the correct video quota', async function () { |
76314386 | 820 | const res = await getMyUserInformation(server.url, user15AccessToken) |
1eddc9a7 | 821 | const user = res.body |
0e1dc3e7 | 822 | |
1eddc9a7 C |
823 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
824 | }) | |
92b9d60c | 825 | |
e590b4a5 C |
826 | it('Should have created the channel', async function () { |
827 | const res = await getVideoChannel(server.url, 'my_user_15_channel') | |
828 | ||
829 | expect(res.body.displayName).to.equal('my channel rocks') | |
830 | }) | |
831 | ||
1eddc9a7 C |
832 | it('Should remove me', async function () { |
833 | { | |
834 | const res = await getUsersList(server.url, server.accessToken) | |
835 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | |
836 | } | |
92b9d60c | 837 | |
76314386 | 838 | await deleteMe(server.url, user15AccessToken) |
1eddc9a7 C |
839 | |
840 | { | |
841 | const res = await getUsersList(server.url, server.accessToken) | |
842 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | |
843 | } | |
844 | }) | |
92b9d60c C |
845 | }) |
846 | ||
1eddc9a7 | 847 | describe('User blocking', function () { |
76314386 RK |
848 | let user16Id |
849 | let user16AccessToken | |
8491293b RK |
850 | const user16 = { |
851 | username: 'user_16', | |
852 | password: 'my super password' | |
853 | } | |
76314386 | 854 | |
8491293b | 855 | it('Should block a user', async function () { |
1eddc9a7 C |
856 | const resUser = await createUser({ |
857 | url: server.url, | |
858 | accessToken: server.accessToken, | |
859 | username: user16.username, | |
860 | password: user16.password | |
861 | }) | |
76314386 | 862 | user16Id = resUser.body.user.id |
e6921918 | 863 | |
76314386 | 864 | user16AccessToken = await userLogin(server, user16) |
e6921918 | 865 | |
2d53be02 | 866 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
1eddc9a7 | 867 | await blockUser(server.url, user16Id, server.accessToken) |
e6921918 | 868 | |
2d53be02 RK |
869 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) |
870 | await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) | |
8491293b RK |
871 | }) |
872 | ||
873 | it('Should search user by banned status', async function () { | |
874 | { | |
875 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) | |
876 | const users = res.body.data as User[] | |
877 | ||
878 | expect(res.body.total).to.equal(1) | |
879 | expect(users.length).to.equal(1) | |
880 | ||
881 | expect(users[0].username).to.equal(user16.username) | |
882 | } | |
883 | ||
884 | { | |
885 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) | |
886 | const users = res.body.data as User[] | |
887 | ||
888 | expect(res.body.total).to.equal(1) | |
889 | expect(users.length).to.equal(1) | |
890 | ||
891 | expect(users[0].username).to.not.equal(user16.username) | |
892 | } | |
893 | }) | |
e6921918 | 894 | |
8491293b | 895 | it('Should unblock a user', async function () { |
1eddc9a7 | 896 | await unblockUser(server.url, user16Id, server.accessToken) |
76314386 | 897 | user16AccessToken = await userLogin(server, user16) |
2d53be02 | 898 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
76314386 RK |
899 | }) |
900 | }) | |
901 | ||
902 | describe('User stats', function () { | |
903 | let user17Id | |
904 | let user17AccessToken | |
905 | ||
906 | it('Should report correct initial statistics about a user', async function () { | |
907 | const user17 = { | |
908 | username: 'user_17', | |
909 | password: 'my super password' | |
910 | } | |
911 | const resUser = await createUser({ | |
912 | url: server.url, | |
913 | accessToken: server.accessToken, | |
914 | username: user17.username, | |
915 | password: user17.password | |
916 | }) | |
917 | ||
918 | user17Id = resUser.body.user.id | |
919 | user17AccessToken = await userLogin(server, user17) | |
920 | ||
921 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | |
922 | const user: User = res.body | |
923 | ||
924 | expect(user.videosCount).to.equal(0) | |
925 | expect(user.videoCommentsCount).to.equal(0) | |
4f32032f C |
926 | expect(user.abusesCount).to.equal(0) |
927 | expect(user.abusesCreatedCount).to.equal(0) | |
928 | expect(user.abusesAcceptedCount).to.equal(0) | |
76314386 RK |
929 | }) |
930 | ||
931 | it('Should report correct videos count', async function () { | |
932 | const videoAttributes = { | |
933 | name: 'video to test user stats' | |
934 | } | |
935 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | |
936 | const res1 = await getVideosList(server.url) | |
937 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | |
938 | ||
939 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | |
940 | const user: User = res2.body | |
941 | ||
942 | expect(user.videosCount).to.equal(1) | |
943 | }) | |
944 | ||
945 | it('Should report correct video comments for user', async function () { | |
946 | const text = 'super comment' | |
947 | await addVideoCommentThread(server.url, user17AccessToken, videoId, text) | |
948 | ||
949 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | |
950 | const user: User = res.body | |
951 | ||
952 | expect(user.videoCommentsCount).to.equal(1) | |
953 | }) | |
954 | ||
4f32032f | 955 | it('Should report correct abuses counts', async function () { |
76314386 | 956 | const reason = 'my super bad reason' |
4f32032f | 957 | await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) |
76314386 | 958 | |
edbc9325 | 959 | const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) |
76314386 RK |
960 | const abuseId = res1.body.data[0].id |
961 | ||
962 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | |
963 | const user2: User = res2.body | |
964 | ||
4f32032f C |
965 | expect(user2.abusesCount).to.equal(1) // number of incriminations |
966 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created | |
76314386 | 967 | |
d95d1559 | 968 | const body: AbuseUpdate = { state: AbuseState.ACCEPTED } |
4f32032f | 969 | await updateAbuse(server.url, server.accessToken, abuseId, body) |
76314386 RK |
970 | |
971 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | |
972 | const user3: User = res3.body | |
973 | ||
4f32032f | 974 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted |
1eddc9a7 | 975 | }) |
e6921918 C |
976 | }) |
977 | ||
7c3b7976 C |
978 | after(async function () { |
979 | await cleanupTests([ server ]) | |
0e1dc3e7 C |
980 | }) |
981 | }) |