diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-13 11:05:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 41d1d075011174e73dccb74006181a92a618d7b4 (patch) | |
tree | 4dc1af0e266977f062cf9716837d04de1cdd628d /server/tests/plugins | |
parent | 6c5065a011b099618681a37bd77eaa7bd3db752e (diff) | |
download | PeerTube-41d1d075011174e73dccb74006181a92a618d7b4.tar.gz PeerTube-41d1d075011174e73dccb74006181a92a618d7b4.tar.zst PeerTube-41d1d075011174e73dccb74006181a92a618d7b4.zip |
Introduce login command
Diffstat (limited to 'server/tests/plugins')
-rw-r--r-- | server/tests/plugins/action-hooks.ts | 3 | ||||
-rw-r--r-- | server/tests/plugins/external-auth.ts | 57 | ||||
-rw-r--r-- | server/tests/plugins/id-and-pass-auth.ts | 49 |
3 files changed, 56 insertions, 53 deletions
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 () { |