aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/users')
-rw-r--r--server/tests/api/users/user-subscriptions.ts3
-rw-r--r--server/tests/api/users/users-multiple-servers.ts3
-rw-r--r--server/tests/api/users/users-verification.ts28
-rw-r--r--server/tests/api/users/users.ts91
4 files changed, 59 insertions, 66 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index c119622ad..1d0fc35f1 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -13,7 +13,6 @@ import {
13 SubscriptionsCommand, 13 SubscriptionsCommand,
14 updateVideo, 14 updateVideo,
15 uploadVideo, 15 uploadVideo,
16 userLogin,
17 waitJobs 16 waitJobs
18} from '@shared/extra-utils' 17} from '@shared/extra-utils'
19 18
@@ -42,7 +41,7 @@ describe('Test users subscriptions', function () {
42 const user = { username: 'user' + server.serverNumber, password: 'password' } 41 const user = { username: 'user' + server.serverNumber, password: 'password' }
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 42 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
44 43
45 const accessToken = await userLogin(server, user) 44 const accessToken = await server.loginCommand.getAccessToken(user)
46 users.push({ accessToken }) 45 users.push({ accessToken })
47 46
48 const videoName1 = 'video 1-' + server.serverNumber 47 const videoName1 = 'video 1-' + server.serverNumber
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 7b650cb8f..99fa08fe2 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -19,7 +19,6 @@ import {
19 updateMyAvatar, 19 updateMyAvatar,
20 updateMyUser, 20 updateMyUser,
21 uploadVideo, 21 uploadVideo,
22 userLogin,
23 waitJobs 22 waitJobs
24} from '@shared/extra-utils' 23} from '@shared/extra-utils'
25import { User } from '@shared/models' 24import { User } from '@shared/models'
@@ -64,7 +63,7 @@ describe('Test users with multiple servers', function () {
64 password: user.password 63 password: user.password
65 }) 64 })
66 userId = res.body.user.id 65 userId = res.body.user.id
67 userAccessToken = await userLogin(servers[0], user) 66 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
68 } 67 }
69 68
70 { 69 {
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index 23f81d804..ade730323 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -2,23 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 flushAndRunServer,
9 getMyUserInformation, 9 getMyUserInformation,
10 getUserInformation, 10 getUserInformation,
11 login, 11 MockSmtpServer,
12 registerUser, 12 registerUser,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers,
14 updateMyUser, 15 updateMyUser,
15 userLogin, 16 verifyEmail,
16 verifyEmail 17 waitJobs
17} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
18import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 19import { User } from '@shared/models'
19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
20import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
21import { User } from '../../../../shared/models/users'
22 20
23const expect = chai.expect 21const expect = chai.expect
24 22
@@ -91,15 +89,15 @@ describe('Test users account verification', function () {
91 }) 89 })
92 90
93 it('Should not allow login for user with unverified email', async function () { 91 it('Should not allow login for user with unverified email', async function () {
94 const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) 92 const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
95 expect(resLogin.body.detail).to.contain('User email is not verified.') 93 expect(detail).to.contain('User email is not verified.')
96 }) 94 })
97 95
98 it('Should verify the user via email and allow login', async function () { 96 it('Should verify the user via email and allow login', async function () {
99 await verifyEmail(server.url, userId, verificationString) 97 await verifyEmail(server.url, userId, verificationString)
100 98
101 const res = await login(server.url, server.client, user1) 99 const body = await server.loginCommand.login({ user: user1 })
102 userAccessToken = res.body.access_token 100 userAccessToken = body.access_token
103 101
104 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 102 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId)
105 expect(resUserVerified.body.emailVerified).to.be.true 103 expect(resUserVerified.body.emailVerified).to.be.true
@@ -164,7 +162,7 @@ describe('Test users account verification', function () {
164 await waitJobs(server) 162 await waitJobs(server)
165 expect(emails).to.have.lengthOf(expectedEmailsLength) 163 expect(emails).to.have.lengthOf(expectedEmailsLength)
166 164
167 const accessToken = await userLogin(server, user2) 165 const accessToken = await server.loginCommand.getAccessToken(user2)
168 166
169 const resMyUserInfo = await getMyUserInformation(server.url, accessToken) 167 const resMyUserInfo = await getMyUserInformation(server.url, accessToken)
170 expect(resMyUserInfo.body.emailVerified).to.be.null 168 expect(resMyUserInfo.body.emailVerified).to.be.null
@@ -181,7 +179,7 @@ describe('Test users account verification', function () {
181 } 179 }
182 }) 180 })
183 181
184 await userLogin(server, user2) 182 await server.loginCommand.getAccessToken(user2)
185 }) 183 })
186 184
187 after(async function () { 185 after(async function () {
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 69a8dba34..608bedb8b 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -18,11 +18,8 @@ import {
18 getUsersListPaginationAndSort, 18 getUsersListPaginationAndSort,
19 getVideosList, 19 getVideosList,
20 killallServers, 20 killallServers,
21 login,
22 logout,
23 makePutBodyRequest, 21 makePutBodyRequest,
24 rateVideo, 22 rateVideo,
25 refreshToken,
26 registerUserWithChannel, 23 registerUserWithChannel,
27 removeUser, 24 removeUser,
28 removeVideo, 25 removeVideo,
@@ -35,7 +32,6 @@ import {
35 updateMyUser, 32 updateMyUser,
36 updateUser, 33 updateUser,
37 uploadVideo, 34 uploadVideo,
38 userLogin,
39 waitJobs 35 waitJobs
40} from '@shared/extra-utils' 36} from '@shared/extra-utils'
41import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' 37import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
@@ -78,22 +74,22 @@ describe('Test users', function () {
78 74
79 it('Should not login with an invalid client id', async function () { 75 it('Should not login with an invalid client id', async function () {
80 const client = { id: 'client', secret: server.client.secret } 76 const client = { id: 'client', secret: server.client.secret }
81 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) 77 const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
82 78
83 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) 79 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
84 expect(res.body.error).to.contain('client is invalid') 80 expect(body.error).to.contain('client is invalid')
85 expect(res.body.type.startsWith('https://')).to.be.true 81 expect(body.type.startsWith('https://')).to.be.true
86 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) 82 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
87 }) 83 })
88 84
89 it('Should not login with an invalid client secret', async function () { 85 it('Should not login with an invalid client secret', async function () {
90 const client = { id: server.client.id, secret: 'coucou' } 86 const client = { id: server.client.id, secret: 'coucou' }
91 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) 87 const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
92 88
93 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) 89 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
94 expect(res.body.error).to.contain('client is invalid') 90 expect(body.error).to.contain('client is invalid')
95 expect(res.body.type.startsWith('https://')).to.be.true 91 expect(body.type.startsWith('https://')).to.be.true
96 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) 92 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
97 }) 93 })
98 }) 94 })
99 95
@@ -101,22 +97,22 @@ describe('Test users', function () {
101 97
102 it('Should not login with an invalid username', async function () { 98 it('Should not login with an invalid username', async function () {
103 const user = { username: 'captain crochet', password: server.user.password } 99 const user = { username: 'captain crochet', password: server.user.password }
104 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) 100 const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
105 101
106 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) 102 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
107 expect(res.body.error).to.contain('credentials are invalid') 103 expect(body.error).to.contain('credentials are invalid')
108 expect(res.body.type.startsWith('https://')).to.be.true 104 expect(body.type.startsWith('https://')).to.be.true
109 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) 105 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
110 }) 106 })
111 107
112 it('Should not login with an invalid password', async function () { 108 it('Should not login with an invalid password', async function () {
113 const user = { username: server.user.username, password: 'mew_three' } 109 const user = { username: server.user.username, password: 'mew_three' }
114 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) 110 const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 111
116 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) 112 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
117 expect(res.body.error).to.contain('credentials are invalid') 113 expect(body.error).to.contain('credentials are invalid')
118 expect(res.body.type.startsWith('https://')).to.be.true 114 expect(body.type.startsWith('https://')).to.be.true
119 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) 115 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
120 }) 116 })
121 117
122 it('Should not be able to upload a video', async function () { 118 it('Should not be able to upload a video', async function () {
@@ -139,20 +135,20 @@ describe('Test users', function () {
139 it('Should not be able to unfollow') 135 it('Should not be able to unfollow')
140 136
141 it('Should be able to login', async function () { 137 it('Should be able to login', async function () {
142 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) 138 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 })
143 139
144 accessToken = res.body.access_token 140 accessToken = body.access_token
145 }) 141 })
146 142
147 it('Should be able to login with an insensitive username', async function () { 143 it('Should be able to login with an insensitive username', async function () {
148 const user = { username: 'RoOt', password: server.user.password } 144 const user = { username: 'RoOt', password: server.user.password }
149 await login(server.url, server.client, user, HttpStatusCode.OK_200) 145 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 })
150 146
151 const user2 = { username: 'rOoT', password: server.user.password } 147 const user2 = { username: 'rOoT', password: server.user.password }
152 await login(server.url, server.client, user2, HttpStatusCode.OK_200) 148 await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 })
153 149
154 const user3 = { username: 'ROOt', password: server.user.password } 150 const user3 = { username: 'ROOt', password: server.user.password }
155 await login(server.url, server.client, user3, HttpStatusCode.OK_200) 151 await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 })
156 }) 152 })
157 }) 153 })
158 154
@@ -222,7 +218,7 @@ describe('Test users', function () {
222 218
223 describe('Logout', function () { 219 describe('Logout', function () {
224 it('Should logout (revoke token)', async function () { 220 it('Should logout (revoke token)', async function () {
225 await logout(server.url, server.accessToken) 221 await server.loginCommand.logout({ token: server.accessToken })
226 }) 222 })
227 223
228 it('Should not be able to get the user information', async function () { 224 it('Should not be able to get the user information', async function () {
@@ -250,9 +246,9 @@ describe('Test users', function () {
250 }) 246 })
251 247
252 it('Should be able to login again', async function () { 248 it('Should be able to login again', async function () {
253 const res = await login(server.url, server.client, server.user) 249 const body = await server.loginCommand.login()
254 server.accessToken = res.body.access_token 250 server.accessToken = body.access_token
255 server.refreshToken = res.body.refresh_token 251 server.refreshToken = body.refresh_token
256 }) 252 })
257 253
258 it('Should be able to get my user information again', async function () { 254 it('Should be able to get my user information again', async function () {
@@ -268,11 +264,11 @@ describe('Test users', function () {
268 await killallServers([ server ]) 264 await killallServers([ server ])
269 await reRunServer(server) 265 await reRunServer(server)
270 266
271 await getMyUserInformation(server.url, server.accessToken, 401) 267 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
272 }) 268 })
273 269
274 it('Should not be able to refresh an access token with an expired refresh token', async function () { 270 it('Should not be able to refresh an access token with an expired refresh token', async function () {
275 await refreshToken(server, server.refreshToken, 400) 271 await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
276 }) 272 })
277 273
278 it('Should refresh the token', async function () { 274 it('Should refresh the token', async function () {
@@ -284,7 +280,7 @@ describe('Test users', function () {
284 await killallServers([ server ]) 280 await killallServers([ server ])
285 await reRunServer(server) 281 await reRunServer(server)
286 282
287 const res = await refreshToken(server, server.refreshToken) 283 const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken })
288 server.accessToken = res.body.access_token 284 server.accessToken = res.body.access_token
289 server.refreshToken = res.body.refresh_token 285 server.refreshToken = res.body.refresh_token
290 }) 286 })
@@ -308,7 +304,7 @@ describe('Test users', function () {
308 }) 304 })
309 305
310 it('Should be able to login with this user', async function () { 306 it('Should be able to login with this user', async function () {
311 accessTokenUser = await userLogin(server, user) 307 accessTokenUser = await server.loginCommand.getAccessToken(user)
312 }) 308 })
313 309
314 it('Should be able to get user information', async function () { 310 it('Should be able to get user information', async function () {
@@ -562,6 +558,7 @@ describe('Test users', function () {
562 }) 558 })
563 559
564 describe('Update my account', function () { 560 describe('Update my account', function () {
561
565 it('Should update my password', async function () { 562 it('Should update my password', async function () {
566 await updateMyUser({ 563 await updateMyUser({
567 url: server.url, 564 url: server.url,
@@ -571,7 +568,7 @@ describe('Test users', function () {
571 }) 568 })
572 user.password = 'new password' 569 user.password = 'new password'
573 570
574 await userLogin(server, user, HttpStatusCode.OK_200) 571 await server.loginCommand.login({ user })
575 }) 572 })
576 573
577 it('Should be able to change the NSFW display attribute', async function () { 574 it('Should be able to change the NSFW display attribute', async function () {
@@ -781,7 +778,7 @@ describe('Test users', function () {
781 it('Should have removed the user token', async function () { 778 it('Should have removed the user token', async function () {
782 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 779 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
783 780
784 accessTokenUser = await userLogin(server, user) 781 accessTokenUser = await server.loginCommand.getAccessToken(user)
785 }) 782 })
786 783
787 it('Should be able to update another user password', async function () { 784 it('Should be able to update another user password', async function () {
@@ -794,10 +791,10 @@ describe('Test users', function () {
794 791
795 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 792 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
796 793
797 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) 794 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
798 795
799 user.password = 'password updated' 796 user.password = 'password updated'
800 accessTokenUser = await userLogin(server, user) 797 accessTokenUser = await server.loginCommand.getAccessToken(user)
801 }) 798 })
802 }) 799 })
803 800
@@ -813,7 +810,7 @@ describe('Test users', function () {
813 }) 810 })
814 811
815 it('Should not be able to login with this user', async function () { 812 it('Should not be able to login with this user', async function () {
816 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) 813 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
817 }) 814 })
818 815
819 it('Should not have videos of this user', async function () { 816 it('Should not have videos of this user', async function () {
@@ -842,7 +839,7 @@ describe('Test users', function () {
842 password: 'my super password' 839 password: 'my super password'
843 } 840 }
844 841
845 user15AccessToken = await userLogin(server, user15) 842 user15AccessToken = await server.loginCommand.getAccessToken(user15)
846 }) 843 })
847 844
848 it('Should have the correct display name', async function () { 845 it('Should have the correct display name', async function () {
@@ -897,13 +894,13 @@ describe('Test users', function () {
897 }) 894 })
898 user16Id = resUser.body.user.id 895 user16Id = resUser.body.user.id
899 896
900 user16AccessToken = await userLogin(server, user16) 897 user16AccessToken = await server.loginCommand.getAccessToken(user16)
901 898
902 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 899 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
903 await blockUser(server.url, user16Id, server.accessToken) 900 await blockUser(server.url, user16Id, server.accessToken)
904 901
905 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) 902 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
906 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) 903 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
907 }) 904 })
908 905
909 it('Should search user by banned status', async function () { 906 it('Should search user by banned status', async function () {
@@ -930,7 +927,7 @@ describe('Test users', function () {
930 927
931 it('Should unblock a user', async function () { 928 it('Should unblock a user', async function () {
932 await unblockUser(server.url, user16Id, server.accessToken) 929 await unblockUser(server.url, user16Id, server.accessToken)
933 user16AccessToken = await userLogin(server, user16) 930 user16AccessToken = await server.loginCommand.getAccessToken(user16)
934 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 931 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
935 }) 932 })
936 }) 933 })
@@ -952,7 +949,7 @@ describe('Test users', function () {
952 }) 949 })
953 950
954 user17Id = resUser.body.user.id 951 user17Id = resUser.body.user.id
955 user17AccessToken = await userLogin(server, user17) 952 user17AccessToken = await server.loginCommand.getAccessToken(user17)
956 953
957 const res = await getUserInformation(server.url, server.accessToken, user17Id, true) 954 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
958 const user: User = res.body 955 const user: User = res.body