aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/external-auth.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/tests/plugins/external-auth.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/tests/plugins/external-auth.ts')
-rw-r--r--server/tests/plugins/external-auth.ts47
1 files changed, 24 insertions, 23 deletions
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index 6d907cc51..a1b5e8f5d 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -22,6 +22,7 @@ import {
22 createUser 22 createUser
23} from '../../../shared/extra-utils' 23} from '../../../shared/extra-utils'
24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
25import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
25 26
26async function loginExternal (options: { 27async function loginExternal (options: {
27 server: ServerInfo 28 server: ServerInfo
@@ -29,8 +30,8 @@ async function loginExternal (options: {
29 authName: string 30 authName: string
30 username: string 31 username: string
31 query?: any 32 query?: any
32 statusCodeExpected?: number 33 statusCodeExpected?: HttpStatusCode
33 statusCodeExpectedStep2?: number 34 statusCodeExpectedStep2?: HttpStatusCode
34}) { 35}) {
35 const res = await getExternalAuth({ 36 const res = await getExternalAuth({
36 url: options.server.url, 37 url: options.server.url,
@@ -38,10 +39,10 @@ async function loginExternal (options: {
38 npmVersion: '0.0.1', 39 npmVersion: '0.0.1',
39 authName: options.authName, 40 authName: options.authName,
40 query: options.query, 41 query: options.query,
41 statusCodeExpected: options.statusCodeExpected || 302 42 statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302
42 }) 43 })
43 44
44 if (res.status !== 302) return 45 if (res.status !== HttpStatusCode.FOUND_302) return
45 46
46 const location = res.header.location 47 const location = res.header.location
47 const { externalAuthToken } = decodeQueryString(location) 48 const { externalAuthToken } = decodeQueryString(location)
@@ -105,7 +106,7 @@ describe('Test external auth plugins', function () {
105 query: { 106 query: {
106 username: 'cyan' 107 username: 'cyan'
107 }, 108 },
108 statusCodeExpected: 302 109 statusCodeExpected: HttpStatusCode.FOUND_302
109 }) 110 })
110 111
111 const location = res.header.location 112 const location = res.header.location
@@ -120,13 +121,13 @@ describe('Test external auth plugins', function () {
120 }) 121 })
121 122
122 it('Should reject auto external login with a missing or invalid token', async function () { 123 it('Should reject auto external login with a missing or invalid token', async function () {
123 await loginUsingExternalToken(server, 'cyan', '', 400) 124 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400)
124 await loginUsingExternalToken(server, 'cyan', 'blabla', 400) 125 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400)
125 }) 126 })
126 127
127 it('Should reject auto external login with a missing or invalid username', async function () { 128 it('Should reject auto external login with a missing or invalid username', async function () {
128 await loginUsingExternalToken(server, '', externalAuthToken, 400) 129 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
129 await loginUsingExternalToken(server, '', externalAuthToken, 400) 130 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
130 }) 131 })
131 132
132 it('Should reject auto external login with an expired token', async function () { 133 it('Should reject auto external login with an expired token', async function () {
@@ -134,7 +135,7 @@ describe('Test external auth plugins', function () {
134 135
135 await wait(5000) 136 await wait(5000)
136 137
137 await loginUsingExternalToken(server, 'cyan', externalAuthToken, 400) 138 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
138 139
139 await waitUntilLog(server, 'expired external auth token') 140 await waitUntilLog(server, 'expired external auth token')
140 }) 141 })
@@ -202,7 +203,7 @@ describe('Test external auth plugins', function () {
202 } 203 }
203 204
204 { 205 {
205 await refreshToken(server, kefkaRefreshToken, 400) 206 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400)
206 } 207 }
207 }) 208 })
208 209
@@ -228,7 +229,7 @@ describe('Test external auth plugins', function () {
228 it('Should have logged out Cyan', async function () { 229 it('Should have logged out Cyan', async function () {
229 await waitUntilLog(server, 'On logout cyan') 230 await waitUntilLog(server, 'On logout cyan')
230 231
231 await getMyUserInformation(server.url, cyanAccessToken, 401) 232 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401)
232 }) 233 })
233 234
234 it('Should login Cyan and keep the old existing profile', async function () { 235 it('Should login Cyan and keep the old existing profile', async function () {
@@ -261,7 +262,7 @@ describe('Test external auth plugins', function () {
261 accessToken: cyanAccessToken, 262 accessToken: cyanAccessToken,
262 email: 'toto@example.com', 263 email: 'toto@example.com',
263 currentPassword: 'toto', 264 currentPassword: 'toto',
264 statusCodeExpected: 400 265 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
265 }) 266 })
266 }) 267 })
267 268
@@ -270,7 +271,7 @@ describe('Test external auth plugins', function () {
270 271
271 await wait(5000) 272 await wait(5000)
272 273
273 await getMyUserInformation(server.url, kefkaAccessToken, 401) 274 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401)
274 }) 275 })
275 276
276 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 277 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -281,7 +282,7 @@ describe('Test external auth plugins', function () {
281 settings: { disableKefka: true } 282 settings: { disableKefka: true }
282 }) 283 })
283 284
284 await userLogin(server, { username: 'kefka', password: 'fake' }, 400) 285 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
285 286
286 await loginExternal({ 287 await loginExternal({
287 server, 288 server,
@@ -291,7 +292,7 @@ describe('Test external auth plugins', function () {
291 username: 'kefka' 292 username: 'kefka'
292 }, 293 },
293 username: 'kefka', 294 username: 'kefka',
294 statusCodeExpected: 404 295 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
295 }) 296 })
296 }) 297 })
297 298
@@ -322,12 +323,12 @@ describe('Test external auth plugins', function () {
322 username: 'cyan' 323 username: 'cyan'
323 }, 324 },
324 username: 'cyan', 325 username: 'cyan',
325 statusCodeExpected: 404 326 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
326 }) 327 })
327 328
328 await userLogin(server, { username: 'cyan', password: null }, 400) 329 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400)
329 await userLogin(server, { username: 'cyan', password: '' }, 400) 330 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400)
330 await userLogin(server, { username: 'cyan', password: 'fake' }, 400) 331 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
331 }) 332 })
332 333
333 it('Should not login kefka with another plugin', async function () { 334 it('Should not login kefka with another plugin', async function () {
@@ -336,7 +337,7 @@ describe('Test external auth plugins', function () {
336 npmName: 'test-external-auth-two', 337 npmName: 'test-external-auth-two',
337 authName: 'external-auth-4', 338 authName: 'external-auth-4',
338 username: 'kefka2', 339 username: 'kefka2',
339 statusCodeExpectedStep2: 400 340 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
340 }) 341 })
341 342
342 await loginExternal({ 343 await loginExternal({
@@ -344,7 +345,7 @@ describe('Test external auth plugins', function () {
344 npmName: 'test-external-auth-two', 345 npmName: 'test-external-auth-two',
345 authName: 'external-auth-4', 346 authName: 'external-auth-4',
346 username: 'kefka', 347 username: 'kefka',
347 statusCodeExpectedStep2: 400 348 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
348 }) 349 })
349 }) 350 })
350 351
@@ -361,7 +362,7 @@ describe('Test external auth plugins', function () {
361 npmName: 'test-external-auth-two', 362 npmName: 'test-external-auth-two',
362 authName: 'external-auth-6', 363 authName: 'external-auth-6',
363 username: 'existing_user', 364 username: 'existing_user',
364 statusCodeExpectedStep2: 400 365 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
365 }) 366 })
366 }) 367 })
367 368