diff options
63 files changed, 409 insertions, 443 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' |
17 | import { Video } from '../../../../shared/models/videos' | 16 | import { 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' |
24 | import { AbuseCreate, AbuseState } from '@shared/models' | 23 | import { 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' |
17 | import { | 16 | import { |
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' |
12 | import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' | 11 | import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' |
13 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 12 | import { 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' |
17 | import { CustomConfig } from '@shared/models' | 16 | import { 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' |
13 | import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' | 12 | import { 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' |
13 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | 12 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 13 | import { 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' |
15 | import { | 14 | import { |
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' |
13 | import { | 12 | import { |
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 | ||
24 | describe('Test video lives API validator', function () { | 23 | describe('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' |
13 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | 12 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' |
14 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 13 | import { 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' |
19 | import { PeerTubePlugin, PluginType } from '@shared/models' | 18 | import { 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 | ||
17 | import { | 16 | import { |
@@ -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' |
33 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | 32 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' |
34 | import { | 33 | import { |
@@ -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' |
25 | import { VideoBlacklistType, VideoDetails } from '@shared/models' | 24 | import { 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' |
18 | import { VideoCreateResult } from '@shared/models' | 17 | import { 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' |
24 | import { VideoChannelUpdate } from '@shared/models' | 23 | import { 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' |
21 | import { VideoCreateResult } from '@shared/models' | 20 | import { 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' |
23 | import { VideoPrivacy } from '@shared/models' | 22 | import { 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' |
14 | import { UserRole } from '../../../../shared/models/users' | 13 | import { UserRole } from '../../../../shared/models/users' |
15 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 14 | import { 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' |
28 | import { | 27 | import { |
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' |
23 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' | 22 | import { 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' |
16 | import { UserNotificationType } from '@shared/models' | 15 | import { 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' |
20 | import { UserNotificationType, Video } from '@shared/models' | 19 | import { 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' |
25 | import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' | 24 | import { 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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { Video } from '@shared/models' | ||
6 | import { | 5 | import { |
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' |
17 | import { Video } from '@shared/models' | ||
19 | 18 | ||
20 | const expect = chai.expect | 19 | const 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' |
21 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | 20 | import { 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 | ||
22 | const expect = chai.expect | 21 | const 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' |
22 | import { Video, VideoPrivacy } from '@shared/models' | 21 | import { 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 | ||
3 | import 'mocha' | 3 | import { expect } from 'chai' |
4 | import * as chai from 'chai' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | import { cleanupTests, getVideo, registerUser, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils' | 5 | import { |
6 | import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index' | 6 | cleanupTests, |
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 7 | flushAndRunServer, |
8 | 8 | getVideo, | |
9 | const expect = chai.expect | 9 | registerUser, |
10 | setAccessTokensToServers, | ||
11 | uploadVideo, | ||
12 | viewVideo, | ||
13 | wait | ||
14 | } from '@shared/extra-utils' | ||
10 | 15 | ||
11 | describe('Test application behind a reverse proxy', function () { | 16 | describe('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' |
25 | import { User } from '@shared/models' | 24 | import { 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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { | 6 | import { |
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' |
18 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | 19 | import { User } from '@shared/models' |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
20 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
21 | import { User } from '../../../../shared/models/users' | ||
22 | 20 | ||
23 | const expect = chai.expect | 21 | const 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' |
41 | import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' | 37 | import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' |
@@ -78,22 +74,22 @@ describe('Test users', function () { | |||
78 | 74 | ||
79 | it('Should not login with an invalid client id', async function () { | 75 | it('Should not login with an invalid client id', async function () { |
80 | const client = { id: 'client', secret: server.client.secret } | 76 | const client = { id: 'client', secret: server.client.secret } |
81 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 77 | const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
82 | 78 | ||
83 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 79 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
84 | expect(res.body.error).to.contain('client is invalid') | 80 | expect(body.error).to.contain('client is invalid') |
85 | expect(res.body.type.startsWith('https://')).to.be.true | 81 | expect(body.type.startsWith('https://')).to.be.true |
86 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 82 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
87 | }) | 83 | }) |
88 | 84 | ||
89 | it('Should not login with an invalid client secret', async function () { | 85 | it('Should not login with an invalid client secret', async function () { |
90 | const client = { id: server.client.id, secret: 'coucou' } | 86 | const client = { id: server.client.id, secret: 'coucou' } |
91 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 87 | const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
92 | 88 | ||
93 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 89 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
94 | expect(res.body.error).to.contain('client is invalid') | 90 | expect(body.error).to.contain('client is invalid') |
95 | expect(res.body.type.startsWith('https://')).to.be.true | 91 | expect(body.type.startsWith('https://')).to.be.true |
96 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 92 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
97 | }) | 93 | }) |
98 | }) | 94 | }) |
99 | 95 | ||
@@ -101,22 +97,22 @@ describe('Test users', function () { | |||
101 | 97 | ||
102 | it('Should not login with an invalid username', async function () { | 98 | it('Should not login with an invalid username', async function () { |
103 | const user = { username: 'captain crochet', password: server.user.password } | 99 | const user = { username: 'captain crochet', password: server.user.password } |
104 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 100 | const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
105 | 101 | ||
106 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 102 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
107 | expect(res.body.error).to.contain('credentials are invalid') | 103 | expect(body.error).to.contain('credentials are invalid') |
108 | expect(res.body.type.startsWith('https://')).to.be.true | 104 | expect(body.type.startsWith('https://')).to.be.true |
109 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 105 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
110 | }) | 106 | }) |
111 | 107 | ||
112 | it('Should not login with an invalid password', async function () { | 108 | it('Should not login with an invalid password', async function () { |
113 | const user = { username: server.user.username, password: 'mew_three' } | 109 | const user = { username: server.user.username, password: 'mew_three' } |
114 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 110 | const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
115 | 111 | ||
116 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 112 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
117 | expect(res.body.error).to.contain('credentials are invalid') | 113 | expect(body.error).to.contain('credentials are invalid') |
118 | expect(res.body.type.startsWith('https://')).to.be.true | 114 | expect(body.type.startsWith('https://')).to.be.true |
119 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 115 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
120 | }) | 116 | }) |
121 | 117 | ||
122 | it('Should not be able to upload a video', async function () { | 118 | it('Should not be able to upload a video', async function () { |
@@ -139,20 +135,20 @@ describe('Test users', function () { | |||
139 | it('Should not be able to unfollow') | 135 | it('Should not be able to unfollow') |
140 | 136 | ||
141 | it('Should be able to login', async function () { | 137 | it('Should be able to login', async function () { |
142 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) | 138 | const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) |
143 | 139 | ||
144 | accessToken = res.body.access_token | 140 | accessToken = body.access_token |
145 | }) | 141 | }) |
146 | 142 | ||
147 | it('Should be able to login with an insensitive username', async function () { | 143 | it('Should be able to login with an insensitive username', async function () { |
148 | const user = { username: 'RoOt', password: server.user.password } | 144 | const user = { username: 'RoOt', password: server.user.password } |
149 | await login(server.url, server.client, user, HttpStatusCode.OK_200) | 145 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) |
150 | 146 | ||
151 | const user2 = { username: 'rOoT', password: server.user.password } | 147 | const user2 = { username: 'rOoT', password: server.user.password } |
152 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) | 148 | await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) |
153 | 149 | ||
154 | const user3 = { username: 'ROOt', password: server.user.password } | 150 | const user3 = { username: 'ROOt', password: server.user.password } |
155 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) | 151 | await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) |
156 | }) | 152 | }) |
157 | }) | 153 | }) |
158 | 154 | ||
@@ -222,7 +218,7 @@ describe('Test users', function () { | |||
222 | 218 | ||
223 | describe('Logout', function () { | 219 | describe('Logout', function () { |
224 | it('Should logout (revoke token)', async function () { | 220 | it('Should logout (revoke token)', async function () { |
225 | await logout(server.url, server.accessToken) | 221 | await server.loginCommand.logout({ token: server.accessToken }) |
226 | }) | 222 | }) |
227 | 223 | ||
228 | it('Should not be able to get the user information', async function () { | 224 | it('Should not be able to get the user information', async function () { |
@@ -250,9 +246,9 @@ describe('Test users', function () { | |||
250 | }) | 246 | }) |
251 | 247 | ||
252 | it('Should be able to login again', async function () { | 248 | it('Should be able to login again', async function () { |
253 | const res = await login(server.url, server.client, server.user) | 249 | const body = await server.loginCommand.login() |
254 | server.accessToken = res.body.access_token | 250 | server.accessToken = body.access_token |
255 | server.refreshToken = res.body.refresh_token | 251 | server.refreshToken = body.refresh_token |
256 | }) | 252 | }) |
257 | 253 | ||
258 | it('Should be able to get my user information again', async function () { | 254 | it('Should be able to get my user information again', async function () { |
@@ -268,11 +264,11 @@ describe('Test users', function () { | |||
268 | await killallServers([ server ]) | 264 | await killallServers([ server ]) |
269 | await reRunServer(server) | 265 | await reRunServer(server) |
270 | 266 | ||
271 | await getMyUserInformation(server.url, server.accessToken, 401) | 267 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) |
272 | }) | 268 | }) |
273 | 269 | ||
274 | it('Should not be able to refresh an access token with an expired refresh token', async function () { | 270 | it('Should not be able to refresh an access token with an expired refresh token', async function () { |
275 | await refreshToken(server, server.refreshToken, 400) | 271 | await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
276 | }) | 272 | }) |
277 | 273 | ||
278 | it('Should refresh the token', async function () { | 274 | it('Should refresh the token', async function () { |
@@ -284,7 +280,7 @@ describe('Test users', function () { | |||
284 | await killallServers([ server ]) | 280 | await killallServers([ server ]) |
285 | await reRunServer(server) | 281 | await reRunServer(server) |
286 | 282 | ||
287 | const res = await refreshToken(server, server.refreshToken) | 283 | const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) |
288 | server.accessToken = res.body.access_token | 284 | server.accessToken = res.body.access_token |
289 | server.refreshToken = res.body.refresh_token | 285 | server.refreshToken = res.body.refresh_token |
290 | }) | 286 | }) |
@@ -308,7 +304,7 @@ describe('Test users', function () { | |||
308 | }) | 304 | }) |
309 | 305 | ||
310 | it('Should be able to login with this user', async function () { | 306 | it('Should be able to login with this user', async function () { |
311 | accessTokenUser = await userLogin(server, user) | 307 | accessTokenUser = await server.loginCommand.getAccessToken(user) |
312 | }) | 308 | }) |
313 | 309 | ||
314 | it('Should be able to get user information', async function () { | 310 | it('Should be able to get user information', async function () { |
@@ -562,6 +558,7 @@ describe('Test users', function () { | |||
562 | }) | 558 | }) |
563 | 559 | ||
564 | describe('Update my account', function () { | 560 | describe('Update my account', function () { |
561 | |||
565 | it('Should update my password', async function () { | 562 | it('Should update my password', async function () { |
566 | await updateMyUser({ | 563 | await updateMyUser({ |
567 | url: server.url, | 564 | url: server.url, |
@@ -571,7 +568,7 @@ describe('Test users', function () { | |||
571 | }) | 568 | }) |
572 | user.password = 'new password' | 569 | user.password = 'new password' |
573 | 570 | ||
574 | await userLogin(server, user, HttpStatusCode.OK_200) | 571 | await server.loginCommand.login({ user }) |
575 | }) | 572 | }) |
576 | 573 | ||
577 | it('Should be able to change the NSFW display attribute', async function () { | 574 | it('Should be able to change the NSFW display attribute', async function () { |
@@ -781,7 +778,7 @@ describe('Test users', function () { | |||
781 | it('Should have removed the user token', async function () { | 778 | it('Should have removed the user token', async function () { |
782 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 779 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
783 | 780 | ||
784 | accessTokenUser = await userLogin(server, user) | 781 | accessTokenUser = await server.loginCommand.getAccessToken(user) |
785 | }) | 782 | }) |
786 | 783 | ||
787 | it('Should be able to update another user password', async function () { | 784 | it('Should be able to update another user password', async function () { |
@@ -794,10 +791,10 @@ describe('Test users', function () { | |||
794 | 791 | ||
795 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 792 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) |
796 | 793 | ||
797 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 794 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
798 | 795 | ||
799 | user.password = 'password updated' | 796 | user.password = 'password updated' |
800 | accessTokenUser = await userLogin(server, user) | 797 | accessTokenUser = await server.loginCommand.getAccessToken(user) |
801 | }) | 798 | }) |
802 | }) | 799 | }) |
803 | 800 | ||
@@ -813,7 +810,7 @@ describe('Test users', function () { | |||
813 | }) | 810 | }) |
814 | 811 | ||
815 | it('Should not be able to login with this user', async function () { | 812 | it('Should not be able to login with this user', async function () { |
816 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 813 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
817 | }) | 814 | }) |
818 | 815 | ||
819 | it('Should not have videos of this user', async function () { | 816 | it('Should not have videos of this user', async function () { |
@@ -842,7 +839,7 @@ describe('Test users', function () { | |||
842 | password: 'my super password' | 839 | password: 'my super password' |
843 | } | 840 | } |
844 | 841 | ||
845 | user15AccessToken = await userLogin(server, user15) | 842 | user15AccessToken = await server.loginCommand.getAccessToken(user15) |
846 | }) | 843 | }) |
847 | 844 | ||
848 | it('Should have the correct display name', async function () { | 845 | it('Should have the correct display name', async function () { |
@@ -897,13 +894,13 @@ describe('Test users', function () { | |||
897 | }) | 894 | }) |
898 | user16Id = resUser.body.user.id | 895 | user16Id = resUser.body.user.id |
899 | 896 | ||
900 | user16AccessToken = await userLogin(server, user16) | 897 | user16AccessToken = await server.loginCommand.getAccessToken(user16) |
901 | 898 | ||
902 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 899 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
903 | await blockUser(server.url, user16Id, server.accessToken) | 900 | await blockUser(server.url, user16Id, server.accessToken) |
904 | 901 | ||
905 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) | 902 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) |
906 | await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) | 903 | await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
907 | }) | 904 | }) |
908 | 905 | ||
909 | it('Should search user by banned status', async function () { | 906 | it('Should search user by banned status', async function () { |
@@ -930,7 +927,7 @@ describe('Test users', function () { | |||
930 | 927 | ||
931 | it('Should unblock a user', async function () { | 928 | it('Should unblock a user', async function () { |
932 | await unblockUser(server.url, user16Id, server.accessToken) | 929 | await unblockUser(server.url, user16Id, server.accessToken) |
933 | user16AccessToken = await userLogin(server, user16) | 930 | user16AccessToken = await server.loginCommand.getAccessToken(user16) |
934 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 931 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) |
935 | }) | 932 | }) |
936 | }) | 933 | }) |
@@ -952,7 +949,7 @@ describe('Test users', function () { | |||
952 | }) | 949 | }) |
953 | 950 | ||
954 | user17Id = resUser.body.user.id | 951 | user17Id = resUser.body.user.id |
955 | user17AccessToken = await userLogin(server, user17) | 952 | user17AccessToken = await server.loginCommand.getAccessToken(user17) |
956 | 953 | ||
957 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | 954 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) |
958 | const user: User = res.body | 955 | const user: User = res.body |
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' |
22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 21 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
23 | import { User } from '../../../../shared/models/users' | 22 | import { 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' |
22 | import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' | 21 | import { 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' |
21 | import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' | 20 | import { 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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { Video, VideoCreateResult } from '@shared/models' | ||
7 | import { | 6 | import { |
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, |
16 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | 20 | waitJobs |
17 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 21 | } from '@shared/extra-utils' |
18 | import { userLogin } from '../../../../shared/extra-utils/users/login' | 22 | import { Video, VideoCreateResult, VideoPrivacy } from '@shared/models' |
19 | import { createUser } from '../../../../shared/extra-utils/users/users' | ||
20 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' | ||
21 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
22 | 23 | ||
23 | const expect = chai.expect | 24 | const 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 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
5 | import { | 6 | import { |
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' |
16 | import { Video, VideoPrivacy } from '../../../../shared/models/videos' | ||
17 | import { UserRole } from '../../../../shared/models/users' | 16 | import { UserRole } from '../../../../shared/models/users' |
18 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 17 | import { Video, VideoPrivacy } from '../../../../shared/models/videos' |
19 | 18 | ||
20 | const expect = chai.expect | 19 | const 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' |
22 | import { Video, VideoDetails } from '@shared/models' | 21 | import { 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 @@ | |||
1 | import 'mocha' | 1 | import 'mocha' |
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 2 | import { cleanupTests, CLICommand, createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils' |
3 | import { | ||
4 | cleanupTests, | ||
5 | CLICommand, | ||
6 | createUser, | ||
7 | flushAndRunServer, | ||
8 | login, | ||
9 | ServerInfo, | ||
10 | setAccessTokensToServers | ||
11 | } from '../../../shared/extra-utils' | ||
12 | 3 | ||
13 | describe('Test reset password scripts', function () { | 4 | describe('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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
5 | import { User } from '@shared/models/users/user.model' | 6 | import { User } from '@shared/models/users/user.model' |
6 | import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo, userLogin } from '../../../shared/extra-utils' | 7 | import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo } from '../../../shared/extra-utils' |
7 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 8 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
8 | 9 | ||
9 | describe('Official plugin auth-ldap', function () { | 10 | describe('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' |
23 | import { User, VideoPrivacy } from '@shared/models' | 22 | import { 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' |
20 | import { | 19 | import { |
@@ -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' |
22 | import { User, UserRole } from '@shared/models' | 18 | import { 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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | ||
5 | import { | 6 | import { |
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' |
20 | import { User, UserRole } from '@shared/models' | 17 | import { 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 () { |
diff --git a/shared/extra-utils/requests/requests.ts b/shared/extra-utils/requests/requests.ts index f9d112aca..c5ee63e05 100644 --- a/shared/extra-utils/requests/requests.ts +++ b/shared/extra-utils/requests/requests.ts | |||
@@ -27,6 +27,7 @@ function makeGetRequest (options: { | |||
27 | range?: string | 27 | range?: string |
28 | redirects?: number | 28 | redirects?: number |
29 | accept?: string | 29 | accept?: string |
30 | host?: string | ||
30 | }) { | 31 | }) { |
31 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 | 32 | if (!options.statusCodeExpected) options.statusCodeExpected = HttpStatusCode.BAD_REQUEST_400 |
32 | if (options.contentType === undefined) options.contentType = 'application/json' | 33 | if (options.contentType === undefined) options.contentType = 'application/json' |
@@ -38,6 +39,7 @@ function makeGetRequest (options: { | |||
38 | if (options.query) req.query(options.query) | 39 | if (options.query) req.query(options.query) |
39 | if (options.range) req.set('Range', options.range) | 40 | if (options.range) req.set('Range', options.range) |
40 | if (options.accept) req.set('Accept', options.accept) | 41 | if (options.accept) req.set('Accept', options.accept) |
42 | if (options.host) req.set('Host', options.host) | ||
41 | if (options.redirects) req.redirects(options.redirects) | 43 | if (options.redirects) req.redirects(options.redirects) |
42 | 44 | ||
43 | return req.expect(options.statusCodeExpected) | 45 | return req.expect(options.statusCodeExpected) |
@@ -113,6 +115,7 @@ function makePostBodyRequest (options: { | |||
113 | path: string | 115 | path: string |
114 | token?: string | 116 | token?: string |
115 | fields?: { [ fieldName: string ]: any } | 117 | fields?: { [ fieldName: string ]: any } |
118 | type?: string | ||
116 | statusCodeExpected?: HttpStatusCode | 119 | statusCodeExpected?: HttpStatusCode |
117 | }) { | 120 | }) { |
118 | if (!options.fields) options.fields = {} | 121 | if (!options.fields) options.fields = {} |
@@ -123,6 +126,7 @@ function makePostBodyRequest (options: { | |||
123 | .set('Accept', 'application/json') | 126 | .set('Accept', 'application/json') |
124 | 127 | ||
125 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) | 128 | if (options.token) req.set('Authorization', 'Bearer ' + options.token) |
129 | if (options.type) req.type(options.type) | ||
126 | 130 | ||
127 | return req.send(options.fields) | 131 | return req.send(options.fields) |
128 | .expect(options.statusCodeExpected) | 132 | .expect(options.statusCodeExpected) |
diff --git a/shared/extra-utils/server/clients.ts b/shared/extra-utils/server/clients.ts deleted file mode 100644 index 894fe4911..000000000 --- a/shared/extra-utils/server/clients.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { URL } from 'url' | ||
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
4 | |||
5 | function getClient (url: string) { | ||
6 | const path = '/api/v1/oauth-clients/local' | ||
7 | |||
8 | return request(url) | ||
9 | .get(path) | ||
10 | .set('Host', new URL(url).host) | ||
11 | .set('Accept', 'application/json') | ||
12 | .expect(HttpStatusCode.OK_200) | ||
13 | .expect('Content-Type', /json/) | ||
14 | } | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | getClient | ||
20 | } | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index f5dc0326f..4d9599680 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -16,7 +16,7 @@ import { AbusesCommand } from '../moderation' | |||
16 | import { OverviewsCommand } from '../overviews' | 16 | import { OverviewsCommand } from '../overviews' |
17 | import { SearchCommand } from '../search' | 17 | import { SearchCommand } from '../search' |
18 | import { SocketIOCommand } from '../socket' | 18 | import { SocketIOCommand } from '../socket' |
19 | import { AccountsCommand, BlocklistCommand, NotificationsCommand, SubscriptionsCommand } from '../users' | 19 | import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand } from '../users' |
20 | import { | 20 | import { |
21 | BlacklistCommand, | 21 | BlacklistCommand, |
22 | CaptionsCommand, | 22 | CaptionsCommand, |
@@ -126,6 +126,7 @@ interface ServerInfo { | |||
126 | sqlCommand?: SQLCommand | 126 | sqlCommand?: SQLCommand |
127 | notificationsCommand?: NotificationsCommand | 127 | notificationsCommand?: NotificationsCommand |
128 | serversCommand?: ServersCommand | 128 | serversCommand?: ServersCommand |
129 | loginCommand?: LoginCommand | ||
129 | } | 130 | } |
130 | 131 | ||
131 | function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { | 132 | function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) { |
@@ -357,6 +358,7 @@ function assignCommands (server: ServerInfo) { | |||
357 | server.sqlCommand = new SQLCommand(server) | 358 | server.sqlCommand = new SQLCommand(server) |
358 | server.notificationsCommand = new NotificationsCommand(server) | 359 | server.notificationsCommand = new NotificationsCommand(server) |
359 | server.serversCommand = new ServersCommand(server) | 360 | server.serversCommand = new ServersCommand(server) |
361 | server.loginCommand = new LoginCommand(server) | ||
360 | } | 362 | } |
361 | 363 | ||
362 | async function reRunServer (server: ServerInfo, configOverride?: any) { | 364 | async function reRunServer (server: ServerInfo, configOverride?: any) { |
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 4e61554a2..af9ecd926 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts | |||
@@ -33,6 +33,7 @@ interface InternalGetCommandOptions extends InternalCommonCommandOptions { | |||
33 | accept?: string | 33 | accept?: string |
34 | redirects?: number | 34 | redirects?: number |
35 | range?: string | 35 | range?: string |
36 | host?: string | ||
36 | } | 37 | } |
37 | 38 | ||
38 | abstract class AbstractCommand { | 39 | abstract class AbstractCommand { |
@@ -78,7 +79,7 @@ abstract class AbstractCommand { | |||
78 | } | 79 | } |
79 | 80 | ||
80 | protected getRequest (options: InternalGetCommandOptions) { | 81 | protected getRequest (options: InternalGetCommandOptions) { |
81 | const { redirects, query, contentType, accept, range } = options | 82 | const { redirects, query, contentType, accept, range, host } = options |
82 | 83 | ||
83 | return makeGetRequest({ | 84 | return makeGetRequest({ |
84 | ...this.buildCommonRequestOptions(options), | 85 | ...this.buildCommonRequestOptions(options), |
@@ -87,6 +88,7 @@ abstract class AbstractCommand { | |||
87 | query, | 88 | query, |
88 | contentType, | 89 | contentType, |
89 | range, | 90 | range, |
91 | host, | ||
90 | accept | 92 | accept |
91 | }) | 93 | }) |
92 | } | 94 | } |
@@ -109,13 +111,15 @@ abstract class AbstractCommand { | |||
109 | 111 | ||
110 | protected postBodyRequest (options: InternalCommonCommandOptions & { | 112 | protected postBodyRequest (options: InternalCommonCommandOptions & { |
111 | fields?: { [ fieldName: string ]: any } | 113 | fields?: { [ fieldName: string ]: any } |
114 | type?: string | ||
112 | }) { | 115 | }) { |
113 | const { fields } = options | 116 | const { type, fields } = options |
114 | 117 | ||
115 | return makePostBodyRequest({ | 118 | return makePostBodyRequest({ |
116 | ...this.buildCommonRequestOptions(options), | 119 | ...this.buildCommonRequestOptions(options), |
117 | 120 | ||
118 | fields | 121 | fields, |
122 | type | ||
119 | }) | 123 | }) |
120 | } | 124 | } |
121 | 125 | ||
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts index ed166c756..b200ae705 100644 --- a/shared/extra-utils/users/index.ts +++ b/shared/extra-utils/users/index.ts | |||
@@ -2,6 +2,7 @@ export * from './accounts-command' | |||
2 | export * from './accounts' | 2 | export * from './accounts' |
3 | export * from './blocklist-command' | 3 | export * from './blocklist-command' |
4 | export * from './login' | 4 | export * from './login' |
5 | export * from './login-command' | ||
5 | export * from './notifications' | 6 | export * from './notifications' |
6 | export * from './notifications-command' | 7 | export * from './notifications-command' |
7 | export * from './subscriptions-command' | 8 | export * from './subscriptions-command' |
diff --git a/shared/extra-utils/users/login-command.ts b/shared/extra-utils/users/login-command.ts new file mode 100644 index 000000000..97efcb766 --- /dev/null +++ b/shared/extra-utils/users/login-command.ts | |||
@@ -0,0 +1,134 @@ | |||
1 | import { PeerTubeRequestError } from '@server/helpers/requests' | ||
2 | import { HttpStatusCode } from '@shared/core-utils' | ||
3 | import { PeerTubeProblemDocument } from '@shared/models' | ||
4 | import { unwrapBody } from '../requests' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class LoginCommand extends AbstractCommand { | ||
8 | |||
9 | login (options: OverrideCommandOptions & { | ||
10 | client?: { id?: string, secret?: string } | ||
11 | user?: { username: string, password: string } | ||
12 | } = {}) { | ||
13 | const { client = this.server.client, user = this.server.user } = options | ||
14 | const path = '/api/v1/users/token' | ||
15 | |||
16 | const body = { | ||
17 | client_id: client.id, | ||
18 | client_secret: client.secret, | ||
19 | username: user.username, | ||
20 | password: user.password, | ||
21 | response_type: 'code', | ||
22 | grant_type: 'password', | ||
23 | scope: 'upload' | ||
24 | } | ||
25 | |||
26 | return unwrapBody<{ access_token: string, refresh_token: string } & PeerTubeProblemDocument>(this.postBodyRequest({ | ||
27 | ...options, | ||
28 | |||
29 | path, | ||
30 | type: 'form', | ||
31 | fields: body, | ||
32 | implicitToken: false, | ||
33 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
34 | })) | ||
35 | } | ||
36 | |||
37 | getAccessToken (user?: { username: string, password: string }): Promise<string> | ||
38 | getAccessToken (username: string, password: string): Promise<string> | ||
39 | async getAccessToken (arg1?: { username: string, password: string } | string, password?: string) { | ||
40 | let user: { username: string, password: string } | ||
41 | |||
42 | if (!arg1) user = this.server.user | ||
43 | else if (typeof arg1 === 'object') user = arg1 | ||
44 | else user = { username: arg1, password } | ||
45 | |||
46 | try { | ||
47 | const body = await this.login({ user }) | ||
48 | |||
49 | return body.access_token | ||
50 | } catch (err) { | ||
51 | throw new Error('Cannot authenticate. Please check your username/password.') | ||
52 | } | ||
53 | } | ||
54 | |||
55 | loginUsingExternalToken (options: OverrideCommandOptions & { | ||
56 | username: string | ||
57 | externalAuthToken: string | ||
58 | }) { | ||
59 | const { username, externalAuthToken } = options | ||
60 | const path = '/api/v1/users/token' | ||
61 | |||
62 | const body = { | ||
63 | client_id: this.server.client.id, | ||
64 | client_secret: this.server.client.secret, | ||
65 | username: username, | ||
66 | response_type: 'code', | ||
67 | grant_type: 'password', | ||
68 | scope: 'upload', | ||
69 | externalAuthToken | ||
70 | } | ||
71 | |||
72 | return this.postBodyRequest({ | ||
73 | ...options, | ||
74 | |||
75 | path, | ||
76 | type: 'form', | ||
77 | fields: body, | ||
78 | implicitToken: false, | ||
79 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | logout (options: OverrideCommandOptions & { | ||
84 | token: string | ||
85 | }) { | ||
86 | const path = '/api/v1/users/revoke-token' | ||
87 | |||
88 | return unwrapBody<{ redirectUrl: string }>(this.postBodyRequest({ | ||
89 | ...options, | ||
90 | |||
91 | path, | ||
92 | type: 'form', | ||
93 | implicitToken: false, | ||
94 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
95 | })) | ||
96 | } | ||
97 | |||
98 | refreshToken (options: OverrideCommandOptions & { | ||
99 | refreshToken: string | ||
100 | }) { | ||
101 | const path = '/api/v1/users/token' | ||
102 | |||
103 | const body = { | ||
104 | client_id: this.server.client.id, | ||
105 | client_secret: this.server.client.secret, | ||
106 | refresh_token: options.refreshToken, | ||
107 | response_type: 'code', | ||
108 | grant_type: 'refresh_token' | ||
109 | } | ||
110 | |||
111 | return this.postBodyRequest({ | ||
112 | ...options, | ||
113 | |||
114 | path, | ||
115 | type: 'form', | ||
116 | fields: body, | ||
117 | implicitToken: false, | ||
118 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
119 | }) | ||
120 | } | ||
121 | |||
122 | getClient (options: OverrideCommandOptions = {}) { | ||
123 | const path = '/api/v1/oauth-clients/local' | ||
124 | |||
125 | return this.getRequestBody<{ client_id: string, client_secret: string }>({ | ||
126 | ...options, | ||
127 | |||
128 | path, | ||
129 | host: this.server.host, | ||
130 | implicitToken: false, | ||
131 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
132 | }) | ||
133 | } | ||
134 | } | ||
diff --git a/shared/extra-utils/users/login.ts b/shared/extra-utils/users/login.ts index c14367542..d4ee8e517 100644 --- a/shared/extra-utils/users/login.ts +++ b/shared/extra-utils/users/login.ts | |||
@@ -1,133 +1,19 @@ | |||
1 | import * as request from 'supertest' | ||
2 | |||
3 | import { ServerInfo } from '../server/servers' | 1 | import { ServerInfo } from '../server/servers' |
4 | import { getClient } from '../server/clients' | ||
5 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
6 | |||
7 | type Client = { id?: string, secret?: string } | ||
8 | type User = { username: string, password: string } | ||
9 | type Server = { url?: string, client?: Client, user?: User } | ||
10 | |||
11 | function login (url: string, client: Client, user: User, expectedStatus = HttpStatusCode.OK_200) { | ||
12 | const path = '/api/v1/users/token' | ||
13 | |||
14 | const body = { | ||
15 | client_id: client.id, | ||
16 | client_secret: client.secret, | ||
17 | username: user.username, | ||
18 | password: user.password, | ||
19 | response_type: 'code', | ||
20 | grant_type: 'password', | ||
21 | scope: 'upload' | ||
22 | } | ||
23 | |||
24 | return request(url) | ||
25 | .post(path) | ||
26 | .type('form') | ||
27 | .send(body) | ||
28 | .expect(expectedStatus) | ||
29 | } | ||
30 | |||
31 | function logout (url: string, token: string, expectedStatus = HttpStatusCode.OK_200) { | ||
32 | const path = '/api/v1/users/revoke-token' | ||
33 | |||
34 | return request(url) | ||
35 | .post(path) | ||
36 | .set('Authorization', 'Bearer ' + token) | ||
37 | .type('form') | ||
38 | .expect(expectedStatus) | ||
39 | } | ||
40 | |||
41 | async function serverLogin (server: Server) { | ||
42 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) | ||
43 | |||
44 | return res.body.access_token as string | ||
45 | } | ||
46 | |||
47 | function refreshToken (server: ServerInfo, refreshToken: string, expectedStatus = HttpStatusCode.OK_200) { | ||
48 | const path = '/api/v1/users/token' | ||
49 | |||
50 | const body = { | ||
51 | client_id: server.client.id, | ||
52 | client_secret: server.client.secret, | ||
53 | refresh_token: refreshToken, | ||
54 | response_type: 'code', | ||
55 | grant_type: 'refresh_token' | ||
56 | } | ||
57 | |||
58 | return request(server.url) | ||
59 | .post(path) | ||
60 | .type('form') | ||
61 | .send(body) | ||
62 | .expect(expectedStatus) | ||
63 | } | ||
64 | |||
65 | async function userLogin (server: Server, user: User, expectedStatus = HttpStatusCode.OK_200) { | ||
66 | const res = await login(server.url, server.client, user, expectedStatus) | ||
67 | |||
68 | return res.body.access_token as string | ||
69 | } | ||
70 | |||
71 | async function getAccessToken (url: string, username: string, password: string) { | ||
72 | const resClient = await getClient(url) | ||
73 | const client = { | ||
74 | id: resClient.body.client_id, | ||
75 | secret: resClient.body.client_secret | ||
76 | } | ||
77 | |||
78 | const user = { username, password } | ||
79 | |||
80 | try { | ||
81 | const res = await login(url, client, user) | ||
82 | return res.body.access_token | ||
83 | } catch (err) { | ||
84 | throw new Error('Cannot authenticate. Please check your username/password.') | ||
85 | } | ||
86 | } | ||
87 | 2 | ||
88 | function setAccessTokensToServers (servers: ServerInfo[]) { | 3 | function setAccessTokensToServers (servers: ServerInfo[]) { |
89 | const tasks: Promise<any>[] = [] | 4 | const tasks: Promise<any>[] = [] |
90 | 5 | ||
91 | for (const server of servers) { | 6 | for (const server of servers) { |
92 | const p = serverLogin(server).then(t => { server.accessToken = t }) | 7 | const p = server.loginCommand.getAccessToken() |
8 | .then(t => { server.accessToken = t }) | ||
93 | tasks.push(p) | 9 | tasks.push(p) |
94 | } | 10 | } |
95 | 11 | ||
96 | return Promise.all(tasks) | 12 | return Promise.all(tasks) |
97 | } | 13 | } |
98 | 14 | ||
99 | function loginUsingExternalToken (server: Server, username: string, externalAuthToken: string, expectedStatus = HttpStatusCode.OK_200) { | ||
100 | const path = '/api/v1/users/token' | ||
101 | |||
102 | const body = { | ||
103 | client_id: server.client.id, | ||
104 | client_secret: server.client.secret, | ||
105 | username: username, | ||
106 | response_type: 'code', | ||
107 | grant_type: 'password', | ||
108 | scope: 'upload', | ||
109 | externalAuthToken | ||
110 | } | ||
111 | |||
112 | return request(server.url) | ||
113 | .post(path) | ||
114 | .type('form') | ||
115 | .send(body) | ||
116 | .expect(expectedStatus) | ||
117 | } | ||
118 | |||
119 | // --------------------------------------------------------------------------- | 15 | // --------------------------------------------------------------------------- |
120 | 16 | ||
121 | export { | 17 | export { |
122 | login, | 18 | setAccessTokensToServers |
123 | logout, | ||
124 | serverLogin, | ||
125 | refreshToken, | ||
126 | userLogin, | ||
127 | getAccessToken, | ||
128 | setAccessTokensToServers, | ||
129 | Server, | ||
130 | Client, | ||
131 | User, | ||
132 | loginUsingExternalToken | ||
133 | } | 19 | } |
diff --git a/shared/extra-utils/users/notifications.ts b/shared/extra-utils/users/notifications.ts index 81f0729fa..79cb6f617 100644 --- a/shared/extra-utils/users/notifications.ts +++ b/shared/extra-utils/users/notifications.ts | |||
@@ -7,7 +7,7 @@ import { UserNotification, UserNotificationSetting, UserNotificationSettingValue | |||
7 | import { MockSmtpServer } from '../mock-servers/mock-email' | 7 | import { MockSmtpServer } from '../mock-servers/mock-email' |
8 | import { doubleFollow } from '../server/follows' | 8 | import { doubleFollow } from '../server/follows' |
9 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | 9 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' |
10 | import { setAccessTokensToServers, userLogin } from './login' | 10 | import { setAccessTokensToServers } from './login' |
11 | import { createUser, getMyUserInformation } from './users' | 11 | import { createUser, getMyUserInformation } from './users' |
12 | 12 | ||
13 | function getAllNotificationsSettings (): UserNotificationSetting { | 13 | function getAllNotificationsSettings (): UserNotificationSetting { |
@@ -662,7 +662,7 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an | |||
662 | password: user.password, | 662 | password: user.password, |
663 | videoQuota: 10 * 1000 * 1000 | 663 | videoQuota: 10 * 1000 * 1000 |
664 | }) | 664 | }) |
665 | const userAccessToken = await userLogin(servers[0], user) | 665 | const userAccessToken = await servers[0].loginCommand.getAccessToken(user) |
666 | 666 | ||
667 | await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() }) | 667 | await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() }) |
668 | await servers[0].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() }) | 668 | await servers[0].notificationsCommand.updateMySettings({ settings: getAllNotificationsSettings() }) |
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index 0f15962ad..835ad08ba 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts | |||
@@ -7,7 +7,6 @@ import { UserRegister } from '../../models/users/user-register.model' | |||
7 | import { UserRole } from '../../models/users/user-role' | 7 | import { UserRole } from '../../models/users/user-role' |
8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' | 8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' |
9 | import { ServerInfo } from '../server/servers' | 9 | import { ServerInfo } from '../server/servers' |
10 | import { userLogin } from './login' | ||
11 | 10 | ||
12 | function createUser (parameters: { | 11 | function createUser (parameters: { |
13 | url: string | 12 | url: string |
@@ -55,7 +54,7 @@ async function generateUser (server: ServerInfo, username: string) { | |||
55 | const password = 'my super password' | 54 | const password = 'my super password' |
56 | const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 55 | const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
57 | 56 | ||
58 | const token = await userLogin(server, { username, password }) | 57 | const token = await server.loginCommand.getAccessToken({ username, password }) |
59 | 58 | ||
60 | const resMe = await getMyUserInformation(server.url, token) | 59 | const resMe = await getMyUserInformation(server.url, token) |
61 | 60 | ||
@@ -70,7 +69,7 @@ async function generateUserAccessToken (server: ServerInfo, username: string) { | |||
70 | const password = 'my super password' | 69 | const password = 'my super password' |
71 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 70 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
72 | 71 | ||
73 | return userLogin(server, { username, password }) | 72 | return server.loginCommand.getAccessToken({ username, password }) |
74 | } | 73 | } |
75 | 74 | ||
76 | function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { | 75 | function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) { |