diff options
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 91 |
1 files changed, 44 insertions, 47 deletions
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' |
41 | import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' | 37 | import { 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 |