aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/activitypub/fetch.ts3
-rw-r--r--server/tests/api/check-params/abuses.ts3
-rw-r--r--server/tests/api/check-params/blocklist.ts5
-rw-r--r--server/tests/api/check-params/bulk.ts5
-rw-r--r--server/tests/api/check-params/config.ts5
-rw-r--r--server/tests/api/check-params/custom-pages.ts5
-rw-r--r--server/tests/api/check-params/debug.ts5
-rw-r--r--server/tests/api/check-params/follows.ts5
-rw-r--r--server/tests/api/check-params/jobs.ts5
-rw-r--r--server/tests/api/check-params/live.ts7
-rw-r--r--server/tests/api/check-params/logs.ts5
-rw-r--r--server/tests/api/check-params/plugins.ts5
-rw-r--r--server/tests/api/check-params/redundancy.ts3
-rw-r--r--server/tests/api/check-params/upload-quota.ts5
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts5
-rw-r--r--server/tests/api/check-params/users.ts9
-rw-r--r--server/tests/api/check-params/video-blacklist.ts5
-rw-r--r--server/tests/api/check-params/video-captions.ts5
-rw-r--r--server/tests/api/check-params/video-channels.ts5
-rw-r--r--server/tests/api/check-params/video-comments.ts7
-rw-r--r--server/tests/api/check-params/video-imports.ts7
-rw-r--r--server/tests/api/check-params/videos-filter.ts7
-rw-r--r--server/tests/api/check-params/videos.ts7
-rw-r--r--server/tests/api/moderation/abuses.ts3
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts7
-rw-r--r--server/tests/api/moderation/blocklist.ts7
-rw-r--r--server/tests/api/moderation/video-blacklist.ts5
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts3
-rw-r--r--server/tests/api/server/bulk.ts11
-rw-r--r--server/tests/api/server/email.ts7
-rw-r--r--server/tests/api/server/follow-constraints.ts5
-rw-r--r--server/tests/api/server/follows.ts3
-rw-r--r--server/tests/api/server/reverse-proxy.ts23
-rw-r--r--server/tests/api/server/stats.ts3
-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
-rw-r--r--server/tests/api/videos/multiple-servers.ts3
-rw-r--r--server/tests/api/videos/video-change-ownership.ts11
-rw-r--r--server/tests/api/videos/video-channels.ts3
-rw-r--r--server/tests/api/videos/video-comments.ts3
-rw-r--r--server/tests/api/videos/video-nsfw.ts5
-rw-r--r--server/tests/api/videos/video-playlists.ts6
-rw-r--r--server/tests/api/videos/video-privacy.ts23
-rw-r--r--server/tests/api/videos/videos-filter.ts11
-rw-r--r--server/tests/api/videos/videos-history.ts3
-rw-r--r--server/tests/cli/peertube.ts3
-rw-r--r--server/tests/cli/reset-password.ts13
-rw-r--r--server/tests/external-plugins/auth-ldap.ts27
-rw-r--r--server/tests/feeds/feeds.ts5
-rw-r--r--server/tests/plugins/action-hooks.ts3
-rw-r--r--server/tests/plugins/external-auth.ts57
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts49
54 files changed, 253 insertions, 297 deletions
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index d5e21404c..c1af23016 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -11,7 +11,6 @@ import {
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 uploadVideo, 13 uploadVideo,
14 userLogin,
15 waitJobs 14 waitJobs
16} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
17import { Video } from '../../../../shared/models/videos' 16import { Video } from '../../../../shared/models/videos'
@@ -36,7 +35,7 @@ describe('Test ActivityPub fetcher', function () {
36 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 35 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
37 } 36 }
38 37
39 const userAccessToken = await userLogin(servers[0], user) 38 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
40 39
41 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) 40 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
42 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) 41 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index e158e50dc..14949d301 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -18,7 +18,6 @@ import {
18 ServerInfo, 18 ServerInfo,
19 setAccessTokensToServers, 19 setAccessTokensToServers,
20 uploadVideo, 20 uploadVideo,
21 userLogin,
22 waitJobs 21 waitJobs
23} from '@shared/extra-utils' 22} from '@shared/extra-utils'
24import { AbuseCreate, AbuseState } from '@shared/models' 23import { AbuseCreate, AbuseState } from '@shared/models'
@@ -47,7 +46,7 @@ describe('Test abuses API validators', function () {
47 const username = 'user1' 46 const username = 'user1'
48 const password = 'my super password' 47 const password = 'my super password'
49 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 48 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
50 userToken = await userLogin(server, { username, password }) 49 userToken = await server.loginCommand.getAccessToken({ username, password })
51 50
52 userToken2 = await generateUserAccessToken(server, 'user_2') 51 userToken2 = await generateUserAccessToken(server, 'user_2')
53 52
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 5ed8810ce..11a79387f 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -11,8 +11,7 @@ import {
11 makeGetRequest, 11 makeGetRequest,
12 makePostBodyRequest, 12 makePostBodyRequest,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers
15 userLogin
16} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
17import { 16import {
18 checkBadCountPagination, 17 checkBadCountPagination,
@@ -37,7 +36,7 @@ describe('Test blocklist API validators', function () {
37 const user = { username: 'user1', password: 'password' } 36 const user = { username: 'user1', password: 'password' }
38 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 37 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
39 38
40 userAccessToken = await userLogin(server, user) 39 userAccessToken = await server.loginCommand.getAccessToken(user)
41 40
42 await doubleFollow(servers[0], servers[1]) 41 await doubleFollow(servers[0], servers[1])
43 }) 42 })
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 07b920ba7..85520b3bd 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -6,8 +6,7 @@ import {
6 createUser, 6 createUser,
7 flushAndRunServer, 7 flushAndRunServer,
8 ServerInfo, 8 ServerInfo,
9 setAccessTokensToServers, 9 setAccessTokensToServers
10 userLogin
11} from '../../../../shared/extra-utils' 10} from '../../../../shared/extra-utils'
12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' 11import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
@@ -27,7 +26,7 @@ describe('Test bulk API validators', function () {
27 const user = { username: 'user1', password: 'password' } 26 const user = { username: 'user1', password: 'password' }
28 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 27 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
29 28
30 userAccessToken = await userLogin(server, user) 29 userAccessToken = await server.loginCommand.getAccessToken(user)
31 }) 30 })
32 31
33 describe('When removing comments of', function () { 32 describe('When removing comments of', function () {
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 291de93ea..e93523e4b 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -11,8 +11,7 @@ import {
11 makeGetRequest, 11 makeGetRequest,
12 makePutBodyRequest, 12 makePutBodyRequest,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers
15 userLogin
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
17import { CustomConfig } from '@shared/models' 16import { CustomConfig } from '@shared/models'
18 17
@@ -208,7 +207,7 @@ describe('Test config API validators', function () {
208 password: 'password' 207 password: 'password'
209 } 208 }
210 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 209 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
211 userAccessToken = await userLogin(server, user) 210 userAccessToken = await server.loginCommand.getAccessToken(user)
212 }) 211 })
213 212
214 describe('When getting the configuration', function () { 213 describe('When getting the configuration', function () {
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts
index 74ca3384c..c1dd258aa 100644
--- a/server/tests/api/check-params/custom-pages.ts
+++ b/server/tests/api/check-params/custom-pages.ts
@@ -7,8 +7,7 @@ import {
7 createUser, 7 createUser,
8 flushAndRunServer, 8 flushAndRunServer,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers
11 userLogin
12} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
13import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' 12import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests'
14 13
@@ -29,7 +28,7 @@ describe('Test custom pages validators', function () {
29 const user = { username: 'user1', password: 'password' } 28 const user = { username: 'user1', password: 'password' }
30 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 29 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
31 30
32 userAccessToken = await userLogin(server, user) 31 userAccessToken = await server.loginCommand.getAccessToken(user)
33 }) 32 })
34 33
35 describe('When updating instance homepage', function () { 34 describe('When updating instance homepage', function () {
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index 37bf0f99b..dc033a441 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -7,8 +7,7 @@ import {
7 createUser, 7 createUser,
8 flushAndRunServer, 8 flushAndRunServer,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers
11 userLogin
12} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 12import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
@@ -32,7 +31,7 @@ describe('Test debug API validators', function () {
32 password: 'my super password' 31 password: 'my super password'
33 } 32 }
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 33 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user) 34 userAccessToken = await server.loginCommand.getAccessToken(user)
36 }) 35 })
37 36
38 describe('When getting debug endpoint', function () { 37 describe('When getting debug endpoint', function () {
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index c03dd5c9c..8cf5b130e 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -9,8 +9,7 @@ import {
9 makeDeleteRequest, makeGetRequest, 9 makeDeleteRequest, makeGetRequest,
10 makePostBodyRequest, 10 makePostBodyRequest,
11 ServerInfo, 11 ServerInfo,
12 setAccessTokensToServers, 12 setAccessTokensToServers
13 userLogin
14} from '../../../../shared/extra-utils' 13} from '../../../../shared/extra-utils'
15import { 14import {
16 checkBadCountPagination, 15 checkBadCountPagination,
@@ -42,7 +41,7 @@ describe('Test server follows API validators', function () {
42 } 41 }
43 42
44 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
45 userAccessToken = await userLogin(server, user) 44 userAccessToken = await server.loginCommand.getAccessToken(user)
46 }) 45 })
47 46
48 describe('When adding follows', function () { 47 describe('When adding follows', function () {
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 3c1d2049b..cbe6a28b8 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -7,8 +7,7 @@ import {
7 createUser, 7 createUser,
8 flushAndRunServer, 8 flushAndRunServer,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers
11 userLogin
12} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
13import { 12import {
14 checkBadCountPagination, 13 checkBadCountPagination,
@@ -37,7 +36,7 @@ describe('Test jobs API validators', function () {
37 password: 'my super password' 36 password: 'my super password'
38 } 37 }
39 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 38 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
40 userAccessToken = await userLogin(server, user) 39 userAccessToken = await server.loginCommand.getAccessToken(user)
41 }) 40 })
42 41
43 describe('When listing jobs', function () { 42 describe('When listing jobs', function () {
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 394967285..045f3a1b1 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -17,8 +17,7 @@ import {
17 ServerInfo, 17 ServerInfo,
18 setAccessTokensToServers, 18 setAccessTokensToServers,
19 stopFfmpeg, 19 stopFfmpeg,
20 uploadVideoAndGetId, 20 uploadVideoAndGetId
21 userLogin
22} from '../../../../shared/extra-utils' 21} from '../../../../shared/extra-utils'
23 22
24describe('Test video lives API validator', function () { 23describe('Test video lives API validator', function () {
@@ -53,7 +52,7 @@ describe('Test video lives API validator', function () {
53 const username = 'user1' 52 const username = 'user1'
54 const password = 'my super password' 53 const password = 'my super password'
55 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
56 userAccessToken = await userLogin(server, { username, password }) 55 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
57 56
58 { 57 {
59 const res = await getMyUserInformation(server.url, server.accessToken) 58 const res = await getMyUserInformation(server.url, server.accessToken)
@@ -150,7 +149,7 @@ describe('Test video lives API validator', function () {
150 } 149 }
151 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 150 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
152 151
153 const accessTokenUser = await userLogin(server, user) 152 const accessTokenUser = await server.loginCommand.getAccessToken(user)
154 const res = await getMyUserInformation(server.url, accessTokenUser) 153 const res = await getMyUserInformation(server.url, accessTokenUser)
155 const customChannelId = res.body.videoChannels[0].id 154 const customChannelId = res.body.videoChannels[0].id
156 155
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index dac1e6b98..83ecfec93 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -7,8 +7,7 @@ import {
7 createUser, 7 createUser,
8 flushAndRunServer, 8 flushAndRunServer,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers
11 userLogin
12} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 12import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
@@ -32,7 +31,7 @@ describe('Test logs API validators', function () {
32 password: 'my super password' 31 password: 'my super password'
33 } 32 }
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 33 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user) 34 userAccessToken = await server.loginCommand.getAccessToken(user)
36 }) 35 })
37 36
38 describe('When getting logs', function () { 37 describe('When getting logs', function () {
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 8509b8ac5..130cf6869 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -13,8 +13,7 @@ import {
13 makePostBodyRequest, 13 makePostBodyRequest,
14 makePutBodyRequest, 14 makePutBodyRequest,
15 ServerInfo, 15 ServerInfo,
16 setAccessTokensToServers, 16 setAccessTokensToServers
17 userLogin
18} from '@shared/extra-utils' 17} from '@shared/extra-utils'
19import { PeerTubePlugin, PluginType } from '@shared/models' 18import { PeerTubePlugin, PluginType } from '@shared/models'
20 19
@@ -45,7 +44,7 @@ describe('Test server plugins API validators', function () {
45 } 44 }
46 45
47 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 46 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
48 userAccessToken = await userLogin(server, user) 47 userAccessToken = await server.loginCommand.getAccessToken(user)
49 48
50 { 49 {
51 const res = await server.pluginsCommand.install({ npmName: npmPlugin }) 50 const res = await server.pluginsCommand.install({ npmName: npmPlugin })
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index dac6938de..2e10e378a 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -19,7 +19,6 @@ import {
19 ServerInfo, 19 ServerInfo,
20 setAccessTokensToServers, 20 setAccessTokensToServers,
21 uploadVideoAndGetId, 21 uploadVideoAndGetId,
22 userLogin,
23 waitJobs 22 waitJobs
24} from '../../../../shared/extra-utils' 23} from '../../../../shared/extra-utils'
25 24
@@ -45,7 +44,7 @@ describe('Test server redundancy API validators', function () {
45 } 44 }
46 45
47 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 46 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
48 userAccessToken = await userLogin(servers[0], user) 47 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
49 48
50 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id 49 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
51 50
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index c444663b8..3dc6cf2b4 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -15,7 +15,6 @@ import {
15 setDefaultVideoChannel, 15 setDefaultVideoChannel,
16 updateUser, 16 updateUser,
17 uploadVideo, 17 uploadVideo,
18 userLogin,
19 waitJobs 18 waitJobs
20} from '../../../../shared/extra-utils' 19} from '../../../../shared/extra-utils'
21 20
@@ -50,7 +49,7 @@ describe('Test upload quota', function () {
50 49
51 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 50 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
52 await registerUser(server.url, user.username, user.password) 51 await registerUser(server.url, user.username, user.password)
53 const userAccessToken = await userLogin(server, user) 52 const userAccessToken = await server.loginCommand.getAccessToken(user)
54 53
55 const videoAttributes = { fixture: 'video_short2.webm' } 54 const videoAttributes = { fixture: 'video_short2.webm' }
56 for (let i = 0; i < 5; i++) { 55 for (let i = 0; i < 5; i++) {
@@ -65,7 +64,7 @@ describe('Test upload quota', function () {
65 64
66 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 65 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
67 await registerUser(server.url, user.username, user.password) 66 await registerUser(server.url, user.username, user.password)
68 const userAccessToken = await userLogin(server, user) 67 const userAccessToken = await server.loginCommand.getAccessToken(user)
69 68
70 const videoAttributes = { fixture: 'video_short2.webm' } 69 const videoAttributes = { fixture: 'video_short2.webm' }
71 for (let i = 0; i < 5; i++) { 70 for (let i = 0; i < 5; i++) {
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 538201647..64e2703b9 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -10,8 +10,7 @@ import {
10 makeGetRequest, 10 makeGetRequest,
11 makePostBodyRequest, 11 makePostBodyRequest,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers
14 userLogin
15} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
16 15
17import { 16import {
@@ -41,7 +40,7 @@ describe('Test user subscriptions API validators', function () {
41 password: 'my super password' 40 password: 'my super password'
42 } 41 }
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 userAccessToken = await userLogin(server, user) 43 userAccessToken = await server.loginCommand.getAccessToken(user)
45 }) 44 })
46 45
47 describe('When listing my subscriptions', function () { 46 describe('When listing my subscriptions', function () {
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index fda7e9640..54baeebe1 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -27,8 +27,7 @@ import {
27 ServerInfo, 27 ServerInfo,
28 setAccessTokensToServers, 28 setAccessTokensToServers,
29 unblockUser, 29 unblockUser,
30 uploadVideo, 30 uploadVideo
31 userLogin
32} from '../../../../shared/extra-utils' 31} from '../../../../shared/extra-utils'
33import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 32import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
34import { 33import {
@@ -87,7 +86,7 @@ describe('Test users API validators', function () {
87 password: user.password, 86 password: user.password,
88 videoQuota: videoQuota 87 videoQuota: videoQuota
89 }) 88 })
90 userAccessToken = await userLogin(server, user) 89 userAccessToken = await server.loginCommand.getAccessToken(user)
91 } 90 }
92 91
93 { 92 {
@@ -104,7 +103,7 @@ describe('Test users API validators', function () {
104 role: UserRole.MODERATOR 103 role: UserRole.MODERATOR
105 }) 104 })
106 105
107 moderatorAccessToken = await userLogin(server, moderator) 106 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
108 } 107 }
109 108
110 { 109 {
@@ -394,7 +393,7 @@ describe('Test users API validators', function () {
394 username: 'user1', 393 username: 'user1',
395 password: 'my super password' 394 password: 'my super password'
396 } 395 }
397 userAccessToken = await userLogin(server, user) 396 userAccessToken = await server.loginCommand.getAccessToken(user)
398 397
399 const fields = { 398 const fields = {
400 username: 'user3', 399 username: 'user3',
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 98cf2e11a..c33bc196d 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -19,7 +19,6 @@ import {
19 ServerInfo, 19 ServerInfo,
20 setAccessTokensToServers, 20 setAccessTokensToServers,
21 uploadVideo, 21 uploadVideo,
22 userLogin,
23 waitJobs 22 waitJobs
24} from '@shared/extra-utils' 23} from '@shared/extra-utils'
25import { VideoBlacklistType, VideoDetails } from '@shared/models' 24import { VideoBlacklistType, VideoDetails } from '@shared/models'
@@ -46,14 +45,14 @@ describe('Test video blacklist API validators', function () {
46 const username = 'user1' 45 const username = 'user1'
47 const password = 'my super password' 46 const password = 'my super password'
48 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 47 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
49 userAccessToken1 = await userLogin(servers[0], { username, password }) 48 userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password })
50 } 49 }
51 50
52 { 51 {
53 const username = 'user2' 52 const username = 'user2'
54 const password = 'my super password' 53 const password = 'my super password'
55 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 54 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
56 userAccessToken2 = await userLogin(servers[0], { username, password }) 55 userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password })
57 } 56 }
58 57
59 { 58 {
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index baab0f276..f2fd61b91 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -12,8 +12,7 @@ import {
12 makeUploadRequest, 12 makeUploadRequest,
13 ServerInfo, 13 ServerInfo,
14 setAccessTokensToServers, 14 setAccessTokensToServers,
15 uploadVideo, 15 uploadVideo
16 userLogin
17} from '@shared/extra-utils' 16} from '@shared/extra-utils'
18import { VideoCreateResult } from '@shared/models' 17import { VideoCreateResult } from '@shared/models'
19 18
@@ -44,7 +43,7 @@ describe('Test video captions API validator', function () {
44 password: 'my super password' 43 password: 'my super password'
45 } 44 }
46 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 45 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
47 userAccessToken = await userLogin(server, user) 46 userAccessToken = await server.loginCommand.getAccessToken(user)
48 } 47 }
49 }) 48 })
50 49
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 3b72d3796..5361f6917 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -18,8 +18,7 @@ import {
18 makePutBodyRequest, 18 makePutBodyRequest,
19 makeUploadRequest, 19 makeUploadRequest,
20 ServerInfo, 20 ServerInfo,
21 setAccessTokensToServers, 21 setAccessTokensToServers
22 userLogin
23} from '@shared/extra-utils' 22} from '@shared/extra-utils'
24import { VideoChannelUpdate } from '@shared/models' 23import { VideoChannelUpdate } from '@shared/models'
25 24
@@ -47,7 +46,7 @@ describe('Test video channels API validator', function () {
47 46
48 { 47 {
49 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 48 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
50 accessTokenUser = await userLogin(server, user) 49 accessTokenUser = await server.loginCommand.getAccessToken(user)
51 } 50 }
52 51
53 command = server.channelsCommand 52 command = server.channelsCommand
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 0f8c81392..c21aebaae 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -15,8 +15,7 @@ import {
15 makePostBodyRequest, 15 makePostBodyRequest,
16 ServerInfo, 16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 uploadVideo, 18 uploadVideo
19 userLogin
20} from '@shared/extra-utils' 19} from '@shared/extra-utils'
21import { VideoCreateResult } from '@shared/models' 20import { VideoCreateResult } from '@shared/models'
22 21
@@ -55,13 +54,13 @@ describe('Test video comments API validator', function () {
55 { 54 {
56 const user = { username: 'user1', password: 'my super password' } 55 const user = { username: 'user1', password: 'my super password' }
57 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 56 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
58 userAccessToken = await userLogin(server, user) 57 userAccessToken = await server.loginCommand.getAccessToken(user)
59 } 58 }
60 59
61 { 60 {
62 const user = { username: 'user2', password: 'my super password' } 61 const user = { username: 'user2', password: 'my super password' }
63 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 62 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
64 userAccessToken2 = await userLogin(server, user) 63 userAccessToken2 = await server.loginCommand.getAccessToken(user)
65 } 64 }
66 }) 65 })
67 66
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 2cc124cc1..51260affa 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -17,8 +17,7 @@ import {
17 makePostBodyRequest, 17 makePostBodyRequest,
18 makeUploadRequest, 18 makeUploadRequest,
19 ServerInfo, 19 ServerInfo,
20 setAccessTokensToServers, 20 setAccessTokensToServers
21 userLogin
22} from '@shared/extra-utils' 21} from '@shared/extra-utils'
23import { VideoPrivacy } from '@shared/models' 22import { VideoPrivacy } from '@shared/models'
24 23
@@ -40,7 +39,7 @@ describe('Test video imports API validator', function () {
40 const username = 'user1' 39 const username = 'user1'
41 const password = 'my super password' 40 const password = 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 41 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
43 userAccessToken = await userLogin(server, { username, password }) 42 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
44 43
45 { 44 {
46 const res = await getMyUserInformation(server.url, server.accessToken) 45 const res = await getMyUserInformation(server.url, server.accessToken)
@@ -167,7 +166,7 @@ describe('Test video imports API validator', function () {
167 } 166 }
168 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 167 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
169 168
170 const accessTokenUser = await userLogin(server, user) 169 const accessTokenUser = await server.loginCommand.getAccessToken(user)
171 const res = await getMyUserInformation(server.url, accessTokenUser) 170 const res = await getMyUserInformation(server.url, accessTokenUser)
172 const customChannelId = res.body.videoChannels[0].id 171 const customChannelId = res.body.videoChannels[0].id
173 172
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index 4d54a4fd0..095b94656 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -8,8 +8,7 @@ import {
8 makeGetRequest, 8 makeGetRequest,
9 ServerInfo, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 setDefaultVideoChannel, 11 setDefaultVideoChannel
12 userLogin
13} from '../../../../shared/extra-utils' 12} from '../../../../shared/extra-utils'
14import { UserRole } from '../../../../shared/models/users' 13import { UserRole } from '../../../../shared/models/users'
15import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
@@ -52,7 +51,7 @@ describe('Test video filters validators', function () {
52 51
53 const user = { username: 'user1', password: 'my super password' } 52 const user = { username: 'user1', password: 'my super password' }
54 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 53 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
55 userAccessToken = await userLogin(server, user) 54 userAccessToken = await server.loginCommand.getAccessToken(user)
56 55
57 const moderator = { username: 'moderator', password: 'my super password' } 56 const moderator = { username: 'moderator', password: 'my super password' }
58 await createUser( 57 await createUser(
@@ -66,7 +65,7 @@ describe('Test video filters validators', function () {
66 role: UserRole.MODERATOR 65 role: UserRole.MODERATOR
67 } 66 }
68 ) 67 )
69 moderatorAccessToken = await userLogin(server, moderator) 68 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
70 }) 69 })
71 70
72 describe('When setting a video filter', function () { 71 describe('When setting a video filter', function () {
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 6549063b1..8e11232bd 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -22,8 +22,7 @@ import {
22 removeVideo, 22 removeVideo,
23 root, 23 root,
24 ServerInfo, 24 ServerInfo,
25 setAccessTokensToServers, 25 setAccessTokensToServers
26 userLogin
27} from '../../../../shared/extra-utils' 26} from '../../../../shared/extra-utils'
28import { 27import {
29 checkBadCountPagination, 28 checkBadCountPagination,
@@ -55,7 +54,7 @@ describe('Test videos API validator', function () {
55 const username = 'user1' 54 const username = 'user1'
56 const password = 'my super password' 55 const password = 'my super password'
57 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 56 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
58 userAccessToken = await userLogin(server, { username, password }) 57 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
59 58
60 { 59 {
61 const res = await getMyUserInformation(server.url, server.accessToken) 60 const res = await getMyUserInformation(server.url, server.accessToken)
@@ -286,7 +285,7 @@ describe('Test videos API validator', function () {
286 } 285 }
287 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 286 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
288 287
289 const accessTokenUser = await userLogin(server, user) 288 const accessTokenUser = await server.loginCommand.getAccessToken(user)
290 const res = await getMyUserInformation(server.url, accessTokenUser) 289 const res = await getMyUserInformation(server.url, accessTokenUser)
291 const customChannelId = res.body.videoChannels[0].id 290 const customChannelId = res.body.videoChannels[0].id
292 291
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index e428cf1a8..d7462f38f 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -17,7 +17,6 @@ import {
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 uploadVideo, 18 uploadVideo,
19 uploadVideoAndGetId, 19 uploadVideoAndGetId,
20 userLogin,
21 waitJobs 20 waitJobs
22} from '@shared/extra-utils' 21} from '@shared/extra-utils'
23import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' 22import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models'
@@ -280,7 +279,7 @@ describe('Test abuses', function () {
280 // register a second user to have two reporters/reportees 279 // register a second user to have two reporters/reportees
281 const user = { username: 'user2', password: 'password' } 280 const user = { username: 'user2', password: 'password' }
282 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) 281 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
283 const userAccessToken = await userLogin(servers[0], user) 282 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
284 283
285 // upload a third video via this user 284 // upload a third video via this user
286 const video3Attributes = { 285 const video3Attributes = {
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index b676a4db4..4f2be6198 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -10,7 +10,6 @@ import {
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 uploadVideo, 12 uploadVideo,
13 userLogin,
14 waitJobs 13 waitJobs
15} from '@shared/extra-utils' 14} from '@shared/extra-utils'
16import { UserNotificationType } from '@shared/models' 15import { UserNotificationType } from '@shared/models'
@@ -86,7 +85,7 @@ describe('Test blocklist', function () {
86 videoQuotaDaily: -1 85 videoQuotaDaily: -1
87 }) 86 })
88 87
89 userToken1 = await userLogin(servers[0], user) 88 userToken1 = await servers[0].loginCommand.getAccessToken(user)
90 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 89 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
91 } 90 }
92 91
@@ -94,14 +93,14 @@ describe('Test blocklist', function () {
94 const user = { username: 'user2', password: 'password' } 93 const user = { username: 'user2', password: 'password' }
95 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 94 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
96 95
97 userToken2 = await userLogin(servers[0], user) 96 userToken2 = await servers[0].loginCommand.getAccessToken(user)
98 } 97 }
99 98
100 { 99 {
101 const user = { username: 'user3', password: 'password' } 100 const user = { username: 'user3', password: 'password' }
102 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 101 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
103 102
104 remoteUserToken = await userLogin(servers[1], user) 103 remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
105 } 104 }
106 105
107 await doubleFollow(servers[0], servers[1]) 106 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index 44e3de4e4..c38a7dad4 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -14,7 +14,6 @@ import {
14 ServerInfo, 14 ServerInfo,
15 setAccessTokensToServers, 15 setAccessTokensToServers,
16 uploadVideo, 16 uploadVideo,
17 userLogin,
18 waitJobs 17 waitJobs
19} from '@shared/extra-utils' 18} from '@shared/extra-utils'
20import { UserNotificationType, Video } from '@shared/models' 19import { UserNotificationType, Video } from '@shared/models'
@@ -94,7 +93,7 @@ describe('Test blocklist', function () {
94 const user = { username: 'user1', password: 'password' } 93 const user = { username: 'user1', password: 'password' }
95 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 94 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
96 95
97 userToken1 = await userLogin(servers[0], user) 96 userToken1 = await servers[0].loginCommand.getAccessToken(user)
98 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 97 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
99 } 98 }
100 99
@@ -102,14 +101,14 @@ describe('Test blocklist', function () {
102 const user = { username: 'moderator', password: 'password' } 101 const user = { username: 'moderator', password: 'password' }
103 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 102 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
104 103
105 userModeratorToken = await userLogin(servers[0], user) 104 userModeratorToken = await servers[0].loginCommand.getAccessToken(user)
106 } 105 }
107 106
108 { 107 {
109 const user = { username: 'user2', password: 'password' } 108 const user = { username: 'user2', password: 'password' }
110 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 109 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
111 110
112 userToken2 = await userLogin(servers[1], user) 111 userToken2 = await servers[1].loginCommand.getAccessToken(user)
113 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) 112 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
114 } 113 }
115 114
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 8b4723a2b..b61effc57 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -19,7 +19,6 @@ import {
19 setAccessTokensToServers, 19 setAccessTokensToServers,
20 updateVideo, 20 updateVideo,
21 uploadVideo, 21 uploadVideo,
22 userLogin,
23 waitJobs 22 waitJobs
24} from '@shared/extra-utils' 23} from '@shared/extra-utils'
25import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' 24import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
@@ -366,7 +365,7 @@ describe('Test video blacklist', function () {
366 role: UserRole.USER 365 role: UserRole.USER
367 }) 366 })
368 367
369 userWithoutFlag = await userLogin(servers[0], user) 368 userWithoutFlag = await servers[0].loginCommand.getAccessToken(user)
370 369
371 const res = await getMyUserInformation(servers[0].url, userWithoutFlag) 370 const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
372 const body: User = res.body 371 const body: User = res.body
@@ -384,7 +383,7 @@ describe('Test video blacklist', function () {
384 role: UserRole.USER 383 role: UserRole.USER
385 }) 384 })
386 385
387 userWithFlag = await userLogin(servers[0], user) 386 userWithFlag = await servers[0].loginCommand.getAccessToken(user)
388 } 387 }
389 388
390 await waitJobs(servers) 389 await waitJobs(servers)
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index 83be9cd1e..3cba2b019 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -13,7 +13,6 @@ import {
13 updateMyUser, 13 updateMyUser,
14 updateVideo, 14 updateVideo,
15 uploadVideo, 15 uploadVideo,
16 userLogin,
17 wait, 16 wait,
18 waitJobs 17 waitJobs
19} from '@shared/extra-utils' 18} from '@shared/extra-utils'
@@ -47,7 +46,7 @@ describe('Test ActivityPub video channels search', function () {
47 { 46 {
48 const user = { username: 'user1_server2', password: 'password' } 47 const user = { username: 'user1_server2', password: 'password' }
49 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 48 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
50 userServer2Token = await userLogin(servers[1], user) 49 userServer2Token = await servers[1].loginCommand.getAccessToken(user)
51 50
52 const channel = { 51 const channel = {
53 name: 'channel1_server2', 52 name: 'channel1_server2',
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index 5c8673e00..a09c21228 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -2,7 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { Video } from '@shared/models'
6import { 5import {
7 BulkCommand, 6 BulkCommand,
8 cleanupTests, 7 cleanupTests,
@@ -13,9 +12,9 @@ import {
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 uploadVideo, 14 uploadVideo,
16 userLogin,
17 waitJobs 15 waitJobs
18} from '../../../../shared/extra-utils/index' 16} from '@shared/extra-utils'
17import { Video } from '@shared/models'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
@@ -41,21 +40,21 @@ describe('Test bulk actions', function () {
41 const user = { username: 'user1', password: 'password' } 40 const user = { username: 'user1', password: 'password' }
42 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 41 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
43 42
44 user1Token = await userLogin(servers[0], user) 43 user1Token = await servers[0].loginCommand.getAccessToken(user)
45 } 44 }
46 45
47 { 46 {
48 const user = { username: 'user2', password: 'password' } 47 const user = { username: 'user2', password: 'password' }
49 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 48 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
50 49
51 user2Token = await userLogin(servers[0], user) 50 user2Token = await servers[0].loginCommand.getAccessToken(user)
52 } 51 }
53 52
54 { 53 {
55 const user = { username: 'user3', password: 'password' } 54 const user = { username: 'user3', password: 'password' }
56 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 55 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
57 56
58 user3Token = await userLogin(servers[1], user) 57 user3Token = await servers[1].loginCommand.getAccessToken(user)
59 } 58 }
60 59
61 await doubleFollow(servers[0], servers[1]) 60 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index 5d997713b..c64c120e3 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -15,7 +15,6 @@ import {
15 setAccessTokensToServers, 15 setAccessTokensToServers,
16 unblockUser, 16 unblockUser,
17 uploadVideo, 17 uploadVideo,
18 userLogin,
19 verifyEmail 18 verifyEmail
20} from '../../../../shared/extra-utils' 19} from '../../../../shared/extra-utils'
21import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 20import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
@@ -62,7 +61,7 @@ describe('Test emails', function () {
62 const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 61 const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
63 userId = res.body.user.id 62 userId = res.body.user.id
64 63
65 userAccessToken = await userLogin(server, user) 64 userAccessToken = await server.loginCommand.getAccessToken(user)
66 } 65 }
67 66
68 { 67 {
@@ -128,7 +127,7 @@ describe('Test emails', function () {
128 it('Should login with this new password', async function () { 127 it('Should login with this new password', async function () {
129 user.password = 'super_password2' 128 user.password = 'super_password2'
130 129
131 await userLogin(server, user) 130 await server.loginCommand.getAccessToken(user)
132 }) 131 })
133 }) 132 })
134 133
@@ -175,7 +174,7 @@ describe('Test emails', function () {
175 }) 174 })
176 175
177 it('Should login with this new password', async function () { 176 it('Should login with this new password', async function () {
178 await userLogin(server, { 177 await server.loginCommand.getAccessToken({
179 username: 'create_password', 178 username: 'create_password',
180 password: 'newly_created_password' 179 password: 'newly_created_password'
181 }) 180 })
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 0f1c6264d..74cdf353b 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -15,8 +15,7 @@ import {
15 getVideoWithToken, 15 getVideoWithToken,
16 ServerInfo, 16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 uploadVideo, 18 uploadVideo
19 userLogin
20} from '../../../../shared/extra-utils' 19} from '../../../../shared/extra-utils'
21 20
22const expect = chai.expect 21const expect = chai.expect
@@ -49,7 +48,7 @@ describe('Test follow constraints', function () {
49 password: 'super_password' 48 password: 'super_password'
50 } 49 }
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 50 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
52 userAccessToken = await userLogin(servers[0], user) 51 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
53 52
54 await doubleFollow(servers[0], servers[1]) 53 await doubleFollow(servers[0], servers[1])
55 }) 54 })
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index 4a9ed2d05..c2a0620a5 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -16,7 +16,6 @@ import {
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 testCaptionFile, 17 testCaptionFile,
18 uploadVideo, 18 uploadVideo,
19 userLogin,
20 waitJobs 19 waitJobs
21} from '@shared/extra-utils' 20} from '@shared/extra-utils'
22import { Video, VideoPrivacy } from '@shared/models' 21import { Video, VideoPrivacy } from '@shared/models'
@@ -330,7 +329,7 @@ describe('Test follows', function () {
330 { 329 {
331 const user = { username: 'captain', password: 'password' } 330 const user = { username: 'captain', password: 'password' }
332 await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password }) 331 await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password })
333 const userAccessToken = await userLogin(servers[2], user) 332 const userAccessToken = await servers[2].loginCommand.getAccessToken(user)
334 333
335 const resVideos = await getVideosList(servers[2].url) 334 const resVideos = await getVideosList(servers[2].url)
336 video4 = resVideos.body.data.find(v => v.name === 'server3-4') 335 video4 = resVideos.body.data.find(v => v.name === 'server3-4')
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index 17d1ee4a5..d9c669571 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -1,12 +1,17 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import { expect } from 'chai'
4import * as chai from 'chai' 4import { HttpStatusCode } from '@shared/core-utils'
5import { cleanupTests, getVideo, registerUser, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils' 5import {
6import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index' 6 cleanupTests,
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 7 flushAndRunServer,
8 8 getVideo,
9const expect = chai.expect 9 registerUser,
10 setAccessTokensToServers,
11 uploadVideo,
12 viewVideo,
13 wait
14} from '@shared/extra-utils'
10 15
11describe('Test application behind a reverse proxy', function () { 16describe('Test application behind a reverse proxy', function () {
12 let server = null 17 let server = null
@@ -97,10 +102,10 @@ describe('Test application behind a reverse proxy', function () {
97 const user = { username: 'root', password: 'fail' } 102 const user = { username: 'root', password: 'fail' }
98 103
99 for (let i = 0; i < 19; i++) { 104 for (let i = 0; i < 19; i++) {
100 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) 105 await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400)
101 } 106 }
102 107
103 await userLogin(server, user, HttpStatusCode.TOO_MANY_REQUESTS_429) 108 await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429)
104 }) 109 })
105 110
106 it('Should rate limit signup', async function () { 111 it('Should rate limit signup', async function () {
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index ded305899..aa26f978d 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -10,7 +10,6 @@ import {
10 ServerInfo, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 uploadVideo, 12 uploadVideo,
13 userLogin,
14 viewVideo, 13 viewVideo,
15 wait, 14 wait,
16 waitJobs 15 waitJobs
@@ -119,7 +118,7 @@ describe('Test stats (excluding redundancy)', function () {
119 } 118 }
120 119
121 { 120 {
122 await userLogin(server, user) 121 await server.loginCommand.getAccessToken(user)
123 122
124 const data = await server.statsCommand.get() 123 const data = await server.statsCommand.get()
125 124
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
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 1905aac83..740314bfd 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -24,7 +24,6 @@ import {
24 testImage, 24 testImage,
25 updateVideo, 25 updateVideo,
26 uploadVideo, 26 uploadVideo,
27 userLogin,
28 viewVideo, 27 viewVideo,
29 wait, 28 wait,
30 waitJobs, 29 waitJobs,
@@ -155,7 +154,7 @@ describe('Test multiple servers', function () {
155 password: 'super_password' 154 password: 'super_password'
156 } 155 }
157 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 156 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
158 const userAccessToken = await userLogin(servers[1], user) 157 const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
159 158
160 const videoAttributes = { 159 const videoAttributes = {
161 name: 'my super name for server 2', 160 name: 'my super name for server 2',
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 1b81fe047..17c738e6f 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -16,8 +16,7 @@ import {
16 ServerInfo, 16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 setDefaultVideoChannel, 18 setDefaultVideoChannel,
19 uploadVideo, 19 uploadVideo
20 userLogin
21} from '../../../../shared/extra-utils' 20} from '../../../../shared/extra-utils'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 21import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { User } from '../../../../shared/models/users' 22import { User } from '../../../../shared/models/users'
@@ -82,8 +81,8 @@ describe('Test video change ownership - nominal', function () {
82 videoQuota: videoQuota 81 videoQuota: videoQuota
83 }) 82 })
84 83
85 firstUserToken = await userLogin(servers[0], firstUser) 84 firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser)
86 secondUserToken = await userLogin(servers[0], secondUser) 85 secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser)
87 86
88 { 87 {
89 const res = await getMyUserInformation(servers[0].url, firstUserToken) 88 const res = await getMyUserInformation(servers[0].url, firstUserToken)
@@ -323,8 +322,8 @@ describe('Test video change ownership - quota too small', function () {
323 videoQuota: limitedVideoQuota 322 videoQuota: limitedVideoQuota
324 }) 323 })
325 324
326 firstUserToken = await userLogin(server, firstUser) 325 firstUserToken = await server.loginCommand.getAccessToken(firstUser)
327 secondUserToken = await userLogin(server, secondUser) 326 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
328 327
329 // Upload some videos on the server 328 // Upload some videos on the server
330 const video1Attributes = { 329 const video1Attributes = {
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index e441ebbd4..83645640c 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -16,7 +16,6 @@ import {
16 testImage, 16 testImage,
17 updateVideo, 17 updateVideo,
18 uploadVideo, 18 uploadVideo,
19 userLogin,
20 wait 19 wait
21} from '../../../../shared/extra-utils' 20} from '../../../../shared/extra-utils'
22import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' 21import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index'
@@ -391,7 +390,7 @@ describe('Test video channels', function () {
391 390
392 { 391 {
393 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) 392 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
394 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' }) 393 const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' })
395 394
396 const res = await getMyUserInformation(servers[0].url, accessToken) 395 const res = await getMyUserInformation(servers[0].url, accessToken)
397 const videoChannel = res.body.videoChannels[0] 396 const videoChannel = res.body.videoChannels[0]
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 548d9fbf5..f9bd23646 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -8,7 +8,6 @@ import {
8 createUser, 8 createUser,
9 dateIsValid, 9 dateIsValid,
10 flushAndRunServer, 10 flushAndRunServer,
11 getAccessToken,
12 ServerInfo, 11 ServerInfo,
13 setAccessTokensToServers, 12 setAccessTokensToServers,
14 testImage, 13 testImage,
@@ -52,7 +51,7 @@ describe('Test video comments', function () {
52 username: 'user1', 51 username: 'user1',
53 password: 'password' 52 password: 'password'
54 }) 53 })
55 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') 54 userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password')
56 55
57 command = server.commentsCommand 56 command = server.commentsCommand
58 }) 57 })
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index c9c3792eb..a30b11ace 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -15,8 +15,7 @@ import {
15 ServerInfo, 15 ServerInfo,
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 updateMyUser, 17 updateMyUser,
18 uploadVideo, 18 uploadVideo
19 userLogin
20} from '@shared/extra-utils' 19} from '@shared/extra-utils'
21import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' 20import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models'
22 21
@@ -151,7 +150,7 @@ describe('Test video NSFW policy', function () {
151 const password = 'my super password' 150 const password = 'my super password'
152 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 151 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
153 152
154 userAccessToken = await userLogin(server, { username, password }) 153 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
155 154
156 const res = await getMyUserInformation(server.url, userAccessToken) 155 const res = await getMyUserInformation(server.url, userAccessToken)
157 const user = res.body 156 const user = res.body
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 2bb019348..38133e2ce 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -10,7 +10,6 @@ import {
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 generateUserAccessToken, 12 generateUserAccessToken,
13 getAccessToken,
14 getMyUserInformation, 13 getMyUserInformation,
15 PlaylistsCommand, 14 PlaylistsCommand,
16 removeUser, 15 removeUser,
@@ -21,7 +20,6 @@ import {
21 updateVideo, 20 updateVideo,
22 uploadVideo, 21 uploadVideo,
23 uploadVideoAndGetId, 22 uploadVideoAndGetId,
24 userLogin,
25 wait, 23 wait,
26 waitJobs 24 waitJobs
27} from '@shared/extra-utils' 25} from '@shared/extra-utils'
@@ -122,7 +120,7 @@ describe('Test video playlists', function () {
122 username: 'user1', 120 username: 'user1',
123 password: 'password' 121 password: 'password'
124 }) 122 })
125 userTokenServer1 = await getAccessToken(servers[0].url, 'user1', 'password') 123 userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password')
126 } 124 }
127 125
128 await waitJobs(servers) 126 await waitJobs(servers)
@@ -1129,7 +1127,7 @@ describe('Test video playlists', function () {
1129 }) 1127 })
1130 1128
1131 const userId = res.body.user.id 1129 const userId = res.body.user.id
1132 const userAccessToken = await userLogin(servers[0], user) 1130 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
1133 1131
1134 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) 1132 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
1135 const userChannel = (resChannel.body as User).videoChannels[0] 1133 const userChannel = (resChannel.body as User).videoChannels[0]
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 950aeb7cf..f831dd8a9 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -2,23 +2,24 @@
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 { Video, VideoCreateResult } from '@shared/models'
7import { 6import {
8 cleanupTests, 7 cleanupTests,
8 createUser,
9 doubleFollow,
9 flushAndRunServer, 10 flushAndRunServer,
11 getMyVideos,
12 getVideo,
10 getVideosList, 13 getVideosList,
11 getVideosListWithToken, 14 getVideosListWithToken,
15 getVideoWithToken,
12 ServerInfo, 16 ServerInfo,
13 setAccessTokensToServers, 17 setAccessTokensToServers,
14 uploadVideo 18 updateVideo,
15} from '../../../../shared/extra-utils/index' 19 uploadVideo,
16import { doubleFollow } from '../../../../shared/extra-utils/server/follows' 20 waitJobs
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 21} from '@shared/extra-utils'
18import { userLogin } from '../../../../shared/extra-utils/users/login' 22import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models'
19import { createUser } from '../../../../shared/extra-utils/users/users'
20import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
21import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
22 23
23const expect = chai.expect 24const expect = chai.expect
24 25
@@ -126,7 +127,7 @@ describe('Test video privacy', function () {
126 } 127 }
127 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 128 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
128 129
129 anotherUserToken = await userLogin(servers[0], user) 130 anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
130 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) 131 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403)
131 }) 132 })
132 133
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 7428b82c5..519dad646 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -1,7 +1,8 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 createUser, 8 createUser,
@@ -10,12 +11,10 @@ import {
10 makeGetRequest, 11 makeGetRequest,
11 ServerInfo, 12 ServerInfo,
12 setAccessTokensToServers, 13 setAccessTokensToServers,
13 uploadVideo, 14 uploadVideo
14 userLogin
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17import { UserRole } from '../../../../shared/models/users' 16import { UserRole } from '../../../../shared/models/users'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 17import { Video, VideoPrivacy } from '../../../../shared/models/videos'
19 18
20const expect = chai.expect 19const expect = chai.expect
21 20
@@ -72,7 +71,7 @@ describe('Test videos filter', function () {
72 role: UserRole.MODERATOR 71 role: UserRole.MODERATOR
73 } 72 }
74 ) 73 )
75 server['moderatorAccessToken'] = await userLogin(server, moderator) 74 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
76 75
77 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) 76 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
78 77
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 9a7635c35..256271bd0 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -16,7 +16,6 @@ import {
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 updateMyUser, 17 updateMyUser,
18 uploadVideo, 18 uploadVideo,
19 userLogin,
20 wait 19 wait
21} from '@shared/extra-utils' 20} from '@shared/extra-utils'
22import { Video, VideoDetails } from '@shared/models' 21import { Video, VideoDetails } from '@shared/models'
@@ -61,7 +60,7 @@ describe('Test videos history', function () {
61 password: 'super password' 60 password: 'super password'
62 } 61 }
63 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 62 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
64 userAccessToken = await userLogin(server, user) 63 userAccessToken = await server.loginCommand.getAccessToken(user)
65 }) 64 })
66 65
67 it('Should get videos, without watching history', async function () { 66 it('Should get videos, without watching history', async function () {
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index 5ab07edb0..e055b4684 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -21,7 +21,6 @@ import {
21 setAccessTokensToServers, 21 setAccessTokensToServers,
22 testHelloWorldRegisteredSettings, 22 testHelloWorldRegisteredSettings,
23 uploadVideoAndGetId, 23 uploadVideoAndGetId,
24 userLogin,
25 waitJobs 24 waitJobs
26} from '../../../shared/extra-utils' 25} from '../../../shared/extra-utils'
27 26
@@ -41,7 +40,7 @@ describe('Test CLI wrapper', function () {
41 40
42 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' }) 41 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
43 42
44 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' }) 43 userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
45 44
46 { 45 {
47 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } 46 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index 97a6eae15..a5f958bf7 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -1,14 +1,5 @@
1import 'mocha' 1import 'mocha'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 2import { cleanupTests, CLICommand, createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils'
3import {
4 cleanupTests,
5 CLICommand,
6 createUser,
7 flushAndRunServer,
8 login,
9 ServerInfo,
10 setAccessTokensToServers
11} from '../../../shared/extra-utils'
12 3
13describe('Test reset password scripts', function () { 4describe('Test reset password scripts', function () {
14 let server: ServerInfo 5 let server: ServerInfo
@@ -27,7 +18,7 @@ describe('Test reset password scripts', function () {
27 const env = server.cliCommand.getEnv() 18 const env = server.cliCommand.getEnv()
28 await CLICommand.exec(`echo coucou | ${env} npm run reset-password -- -u user_1`) 19 await CLICommand.exec(`echo coucou | ${env} npm run reset-password -- -u user_1`)
29 20
30 await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, HttpStatusCode.OK_200) 21 await server.loginCommand.login({ user: { username: 'user_1', password: 'coucou' } })
31 }) 22 })
32 23
33 after(async function () { 24 after(async function () {
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts
index 0d4edbee0..8153e2b81 100644
--- a/server/tests/external-plugins/auth-ldap.ts
+++ b/server/tests/external-plugins/auth-ldap.ts
@@ -2,8 +2,9 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { User } from '@shared/models/users/user.model' 6import { User } from '@shared/models/users/user.model'
6import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils' 7import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo } from '../../../shared/extra-utils'
7import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 8import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
8 9
9describe('Official plugin auth-ldap', function () { 10describe('Official plugin auth-ldap', function () {
@@ -21,7 +22,7 @@ describe('Official plugin auth-ldap', function () {
21 }) 22 })
22 23
23 it('Should not login with without LDAP settings', async function () { 24 it('Should not login with without LDAP settings', async function () {
24 await userLogin(server, { username: 'fry', password: 'fry' }, 400) 25 await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
25 }) 26 })
26 27
27 it('Should not login with bad LDAP settings', async function () { 28 it('Should not login with bad LDAP settings', async function () {
@@ -39,7 +40,7 @@ describe('Official plugin auth-ldap', function () {
39 } 40 }
40 }) 41 })
41 42
42 await userLogin(server, { username: 'fry', password: 'fry' }, 400) 43 await server.loginCommand.login({ user: { username: 'fry', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
43 }) 44 })
44 45
45 it('Should not login with good LDAP settings but wrong username/password', async function () { 46 it('Should not login with good LDAP settings but wrong username/password', async function () {
@@ -57,16 +58,16 @@ describe('Official plugin auth-ldap', function () {
57 } 58 }
58 }) 59 })
59 60
60 await userLogin(server, { username: 'fry', password: 'bad password' }, 400) 61 await server.loginCommand.login({ user: { username: 'fry', password: 'bad password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
61 await userLogin(server, { username: 'fryr', password: 'fry' }, 400) 62 await server.loginCommand.login({ user: { username: 'fryr', password: 'fry' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
62 }) 63 })
63 64
64 it('Should login with the appropriate username/password', async function () { 65 it('Should login with the appropriate username/password', async function () {
65 accessToken = await userLogin(server, { username: 'fry', password: 'fry' }) 66 accessToken = await server.loginCommand.getAccessToken({ username: 'fry', password: 'fry' })
66 }) 67 })
67 68
68 it('Should login with the appropriate email/password', async function () { 69 it('Should login with the appropriate email/password', async function () {
69 accessToken = await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }) 70 accessToken = await server.loginCommand.getAccessToken({ username: 'fry@planetexpress.com', password: 'fry' })
70 }) 71 })
71 72
72 it('Should login get my profile', async function () { 73 it('Should login get my profile', async function () {
@@ -86,19 +87,25 @@ describe('Official plugin auth-ldap', function () {
86 it('Should not be able to login if the user is banned', async function () { 87 it('Should not be able to login if the user is banned', async function () {
87 await blockUser(server.url, userId, server.accessToken) 88 await blockUser(server.url, userId, server.accessToken)
88 89
89 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) 90 await server.loginCommand.login({
91 user: { username: 'fry@planetexpress.com', password: 'fry' },
92 expectedStatus: HttpStatusCode.BAD_REQUEST_400
93 })
90 }) 94 })
91 95
92 it('Should be able to login if the user is unbanned', async function () { 96 it('Should be able to login if the user is unbanned', async function () {
93 await unblockUser(server.url, userId, server.accessToken) 97 await unblockUser(server.url, userId, server.accessToken)
94 98
95 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }) 99 await server.loginCommand.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
96 }) 100 })
97 101
98 it('Should not login if the plugin is uninstalled', async function () { 102 it('Should not login if the plugin is uninstalled', async function () {
99 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' }) 103 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-auth-ldap' })
100 104
101 await userLogin(server, { username: 'fry@planetexpress.com', password: 'fry' }, 400) 105 await server.loginCommand.login({
106 user: { username: 'fry@planetexpress.com', password: 'fry' },
107 expectedStatus: HttpStatusCode.BAD_REQUEST_400
108 })
102 }) 109 })
103 110
104 after(async function () { 111 after(async function () {
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 610849105..9c78ae0e8 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -17,7 +17,6 @@ import {
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 uploadVideo, 18 uploadVideo,
19 uploadVideoAndGetId, 19 uploadVideoAndGetId,
20 userLogin,
21 waitJobs 20 waitJobs
22} from '@shared/extra-utils' 21} from '@shared/extra-utils'
23import { User, VideoPrivacy } from '@shared/models' 22import { User, VideoPrivacy } from '@shared/models'
@@ -64,7 +63,7 @@ describe('Test syndication feeds', () => {
64 { 63 {
65 const attr = { username: 'john', password: 'password' } 64 const attr = { username: 'john', password: 'password' }
66 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) 65 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
67 userAccessToken = await userLogin(servers[0], attr) 66 userAccessToken = await servers[0].loginCommand.getAccessToken(attr)
68 67
69 const res = await getMyUserInformation(servers[0].url, userAccessToken) 68 const res = await getMyUserInformation(servers[0].url, userAccessToken)
70 const user: User = res.body 69 const user: User = res.body
@@ -301,7 +300,7 @@ describe('Test syndication feeds', () => {
301 it('Should list no videos for a user with no videos and no subscriptions', async function () { 300 it('Should list no videos for a user with no videos and no subscriptions', async function () {
302 const attr = { username: 'feeduser', password: 'password' } 301 const attr = { username: 'feeduser', password: 'password' }
303 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) 302 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
304 const feeduserAccessToken = await userLogin(servers[0], attr) 303 const feeduserAccessToken = await servers[0].loginCommand.getAccessToken(attr)
305 304
306 { 305 {
307 const res = await getMyUserInformation(servers[0].url, feeduserAccessToken) 306 const res = await getMyUserInformation(servers[0].url, feeduserAccessToken)
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index cf81e44b7..84f4e8501 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -14,7 +14,6 @@ import {
14 updateUser, 14 updateUser,
15 updateVideo, 15 updateVideo,
16 uploadVideo, 16 uploadVideo,
17 userLogin,
18 viewVideo 17 viewVideo
19} from '../../../shared/extra-utils' 18} from '../../../shared/extra-utils'
20import { 19import {
@@ -138,7 +137,7 @@ describe('Test plugin action hooks', function () {
138 }) 137 })
139 138
140 it('Should run action:api.user.oauth2-got-token', async function () { 139 it('Should run action:api.user.oauth2-got-token', async function () {
141 await userLogin(servers[0], { username: 'created_user', password: 'super_password' }) 140 await servers[0].loginCommand.getAccessToken('created_user', 'super_password')
142 141
143 await checkHook('action:api.user.oauth2-got-token') 142 await checkHook('action:api.user.oauth2-got-token')
144 }) 143 })
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index f7cee588a..e421fd224 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -9,14 +9,10 @@ import {
9 decodeQueryString, 9 decodeQueryString,
10 flushAndRunServer, 10 flushAndRunServer,
11 getMyUserInformation, 11 getMyUserInformation,
12 loginUsingExternalToken,
13 logout,
14 PluginsCommand, 12 PluginsCommand,
15 refreshToken,
16 ServerInfo, 13 ServerInfo,
17 setAccessTokensToServers, 14 setAccessTokensToServers,
18 updateMyUser, 15 updateMyUser,
19 userLogin,
20 wait 16 wait
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
22import { User, UserRole } from '@shared/models' 18import { User, UserRole } from '@shared/models'
@@ -43,12 +39,11 @@ async function loginExternal (options: {
43 const location = res.header.location 39 const location = res.header.location
44 const { externalAuthToken } = decodeQueryString(location) 40 const { externalAuthToken } = decodeQueryString(location)
45 41
46 const resLogin = await loginUsingExternalToken( 42 const resLogin = await options.server.loginCommand.loginUsingExternalToken({
47 options.server, 43 username: options.username,
48 options.username, 44 externalAuthToken: externalAuthToken as string,
49 externalAuthToken as string, 45 expectedStatus: options.statusCodeExpectedStep2
50 options.statusCodeExpectedStep2 46 })
51 )
52 47
53 return resLogin.body 48 return resLogin.body
54} 49}
@@ -110,13 +105,17 @@ describe('Test external auth plugins', function () {
110 }) 105 })
111 106
112 it('Should reject auto external login with a missing or invalid token', async function () { 107 it('Should reject auto external login with a missing or invalid token', async function () {
113 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400) 108 const command = server.loginCommand
114 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400) 109
110 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
111 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 }) 112 })
116 113
117 it('Should reject auto external login with a missing or invalid username', async function () { 114 it('Should reject auto external login with a missing or invalid username', async function () {
118 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 115 const command = server.loginCommand
119 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 116
117 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
118 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
120 }) 119 })
121 120
122 it('Should reject auto external login with an expired token', async function () { 121 it('Should reject auto external login with an expired token', async function () {
@@ -124,7 +123,11 @@ describe('Test external auth plugins', function () {
124 123
125 await wait(5000) 124 await wait(5000)
126 125
127 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 126 await server.loginCommand.loginUsingExternalToken({
127 username: 'cyan',
128 externalAuthToken,
129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
130 })
128 131
129 await server.serversCommand.waitUntilLog('expired external auth token', 2) 132 await server.serversCommand.waitUntilLog('expired external auth token', 2)
130 }) 133 })
@@ -182,7 +185,7 @@ describe('Test external auth plugins', function () {
182 185
183 it('Should refresh Cyan token, but not Kefka token', async function () { 186 it('Should refresh Cyan token, but not Kefka token', async function () {
184 { 187 {
185 const resRefresh = await refreshToken(server, cyanRefreshToken) 188 const resRefresh = await server.loginCommand.refreshToken({ refreshToken: cyanRefreshToken })
186 cyanAccessToken = resRefresh.body.access_token 189 cyanAccessToken = resRefresh.body.access_token
187 cyanRefreshToken = resRefresh.body.refresh_token 190 cyanRefreshToken = resRefresh.body.refresh_token
188 191
@@ -192,7 +195,7 @@ describe('Test external auth plugins', function () {
192 } 195 }
193 196
194 { 197 {
195 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400) 198 await server.loginCommand.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
196 } 199 }
197 }) 200 })
198 201
@@ -212,7 +215,7 @@ describe('Test external auth plugins', function () {
212 }) 215 })
213 216
214 it('Should logout Cyan', async function () { 217 it('Should logout Cyan', async function () {
215 await logout(server.url, cyanAccessToken) 218 await server.loginCommand.logout({ token: cyanAccessToken })
216 }) 219 })
217 220
218 it('Should have logged out Cyan', async function () { 221 it('Should have logged out Cyan', async function () {
@@ -269,7 +272,7 @@ describe('Test external auth plugins', function () {
269 settings: { disableKefka: true } 272 settings: { disableKefka: true }
270 }) 273 })
271 274
272 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 275 await server.loginCommand.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
273 276
274 await loginExternal({ 277 await loginExternal({
275 server, 278 server,
@@ -307,9 +310,9 @@ describe('Test external auth plugins', function () {
307 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 310 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
308 }) 311 })
309 312
310 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400) 313 await server.loginCommand.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
311 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400) 314 await server.loginCommand.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
312 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 315 await server.loginCommand.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
313 }) 316 })
314 317
315 it('Should not login kefka with another plugin', async function () { 318 it('Should not login kefka with another plugin', async function () {
@@ -369,9 +372,8 @@ describe('Test external auth plugins', function () {
369 username: 'cid' 372 username: 'cid'
370 }) 373 })
371 374
372 const resLogout = await logout(server.url, resLogin.access_token) 375 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token })
373 376 expect(redirectUrl).to.equal('https://example.com/redirectUrl')
374 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl')
375 }) 377 })
376 378
377 it('Should call the plugin\'s onLogout method with the request', async function () { 379 it('Should call the plugin\'s onLogout method with the request', async function () {
@@ -382,8 +384,7 @@ describe('Test external auth plugins', function () {
382 username: 'cid' 384 username: 'cid'
383 }) 385 })
384 386
385 const resLogout = await logout(server.url, resLogin.access_token) 387 const { redirectUrl } = await server.loginCommand.logout({ token: resLogin.access_token })
386 388 expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
387 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
388 }) 389 })
389}) 390})
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index a0b31bc1f..e3da64110 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -2,19 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
5import { 6import {
6 cleanupTests, 7 cleanupTests,
7 flushAndRunServer, 8 flushAndRunServer,
8 getMyUserInformation, 9 getMyUserInformation,
9 getUsersList, 10 getUsersList,
10 login,
11 logout,
12 PluginsCommand, 11 PluginsCommand,
13 refreshToken,
14 ServerInfo, 12 ServerInfo,
15 setAccessTokensToServers, 13 setAccessTokensToServers,
16 updateMyUser, 14 updateMyUser,
17 userLogin,
18 wait 15 wait
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
20import { User, UserRole } from '@shared/models' 17import { User, UserRole } from '@shared/models'
@@ -52,11 +49,11 @@ describe('Test id and pass auth plugins', function () {
52 }) 49 })
53 50
54 it('Should not login', async function () { 51 it('Should not login', async function () {
55 await userLogin(server, { username: 'toto', password: 'password' }, 400) 52 await server.loginCommand.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
56 }) 53 })
57 54
58 it('Should login Spyro, create the user and use the token', async function () { 55 it('Should login Spyro, create the user and use the token', async function () {
59 const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' }) 56 const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' })
60 57
61 const res = await getMyUserInformation(server.url, accessToken) 58 const res = await getMyUserInformation(server.url, accessToken)
62 59
@@ -68,9 +65,9 @@ describe('Test id and pass auth plugins', function () {
68 65
69 it('Should login Crash, create the user and use the token', async function () { 66 it('Should login Crash, create the user and use the token', async function () {
70 { 67 {
71 const res = await login(server.url, server.client, { username: 'crash', password: 'crash password' }) 68 const body = await server.loginCommand.login({ user: { username: 'crash', password: 'crash password' } })
72 crashAccessToken = res.body.access_token 69 crashAccessToken = body.access_token
73 crashRefreshToken = res.body.refresh_token 70 crashRefreshToken = body.refresh_token
74 } 71 }
75 72
76 { 73 {
@@ -85,9 +82,9 @@ describe('Test id and pass auth plugins', function () {
85 82
86 it('Should login the first Laguna, create the user and use the token', async function () { 83 it('Should login the first Laguna, create the user and use the token', async function () {
87 { 84 {
88 const res = await login(server.url, server.client, { username: 'laguna', password: 'laguna password' }) 85 const body = await server.loginCommand.login({ user: { username: 'laguna', password: 'laguna password' } })
89 lagunaAccessToken = res.body.access_token 86 lagunaAccessToken = body.access_token
90 lagunaRefreshToken = res.body.refresh_token 87 lagunaRefreshToken = body.refresh_token
91 } 88 }
92 89
93 { 90 {
@@ -102,7 +99,7 @@ describe('Test id and pass auth plugins', function () {
102 99
103 it('Should refresh crash token, but not laguna token', async function () { 100 it('Should refresh crash token, but not laguna token', async function () {
104 { 101 {
105 const resRefresh = await refreshToken(server, crashRefreshToken) 102 const resRefresh = await server.loginCommand.refreshToken({ refreshToken: crashRefreshToken })
106 crashAccessToken = resRefresh.body.access_token 103 crashAccessToken = resRefresh.body.access_token
107 crashRefreshToken = resRefresh.body.refresh_token 104 crashRefreshToken = resRefresh.body.refresh_token
108 105
@@ -112,7 +109,7 @@ describe('Test id and pass auth plugins', function () {
112 } 109 }
113 110
114 { 111 {
115 await refreshToken(server, lagunaRefreshToken, 400) 112 await server.loginCommand.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
116 } 113 }
117 }) 114 })
118 115
@@ -132,7 +129,7 @@ describe('Test id and pass auth plugins', function () {
132 }) 129 })
133 130
134 it('Should logout Crash', async function () { 131 it('Should logout Crash', async function () {
135 await logout(server.url, crashAccessToken) 132 await server.loginCommand.logout({ token: crashAccessToken })
136 }) 133 })
137 134
138 it('Should have logged out Crash', async function () { 135 it('Should have logged out Crash', async function () {
@@ -142,7 +139,7 @@ describe('Test id and pass auth plugins', function () {
142 }) 139 })
143 140
144 it('Should login Crash and keep the old existing profile', async function () { 141 it('Should login Crash and keep the old existing profile', async function () {
145 crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) 142 crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' })
146 143
147 const res = await getMyUserInformation(server.url, crashAccessToken) 144 const res = await getMyUserInformation(server.url, crashAccessToken)
148 145
@@ -162,16 +159,18 @@ describe('Test id and pass auth plugins', function () {
162 }) 159 })
163 160
164 it('Should reject an invalid username, email, role or display name', async function () { 161 it('Should reject an invalid username, email, role or display name', async function () {
165 await userLogin(server, { username: 'ward', password: 'ward password' }, 400) 162 const command = server.loginCommand
163
164 await command.login({ user: { username: 'ward', password: 'ward password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
166 await server.serversCommand.waitUntilLog('valid username') 165 await server.serversCommand.waitUntilLog('valid username')
167 166
168 await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) 167 await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
169 await server.serversCommand.waitUntilLog('valid display name') 168 await server.serversCommand.waitUntilLog('valid display name')
170 169
171 await userLogin(server, { username: 'raine', password: 'raine password' }, 400) 170 await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
172 await server.serversCommand.waitUntilLog('valid role') 171 await server.serversCommand.waitUntilLog('valid role')
173 172
174 await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) 173 await command.login({ user: { username: 'ellone', password: 'elonne password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
175 await server.serversCommand.waitUntilLog('valid email') 174 await server.serversCommand.waitUntilLog('valid email')
176 }) 175 })
177 176
@@ -181,8 +180,9 @@ describe('Test id and pass auth plugins', function () {
181 settings: { disableSpyro: true } 180 settings: { disableSpyro: true }
182 }) 181 })
183 182
184 await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) 183 const command = server.loginCommand
185 await userLogin(server, { username: 'spyro', password: 'fake' }, 400) 184 await command.login({ user: { username: 'spyro', password: 'spyro password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
185 await command.login({ user: { username: 'spyro', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
186 }) 186 })
187 187
188 it('Should have disabled this auth', async function () { 188 it('Should have disabled this auth', async function () {
@@ -198,7 +198,10 @@ describe('Test id and pass auth plugins', function () {
198 it('Should uninstall the plugin one and do not login existing Crash', async function () { 198 it('Should uninstall the plugin one and do not login existing Crash', async function () {
199 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' }) 199 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' })
200 200
201 await userLogin(server, { username: 'crash', password: 'crash password' }, 400) 201 await server.loginCommand.login({
202 user: { username: 'crash', password: 'crash password' },
203 expectedStatus: HttpStatusCode.BAD_REQUEST_400
204 })
202 }) 205 })
203 206
204 it('Should display the correct configuration', async function () { 207 it('Should display the correct configuration', async function () {