aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
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
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')
-rw-r--r--server/tests/plugins/external-auth.ts47
-rw-r--r--server/tests/plugins/plugin-helpers.ts3
-rw-r--r--server/tests/plugins/plugin-router.ts9
3 files changed, 31 insertions, 28 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
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index e76d7917a..c0d95e1e0 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -16,6 +16,7 @@ import {
16} from '../../../shared/extra-utils' 16} from '../../../shared/extra-utils'
17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18import { expect } from 'chai' 18import { expect } from 'chai'
19import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
19 20
20function postCommand (server: ServerInfo, command: string, bodyArg?: object) { 21function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command } 22 const body = { command }
@@ -25,7 +26,7 @@ function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
25 url: server.url, 26 url: server.url,
26 path: '/plugins/test-four/router/commander', 27 path: '/plugins/test-four/router/commander',
27 fields: body, 28 fields: body,
28 statusCodeExpected: 204 29 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
29 }) 30 })
30} 31}
31 32
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index cf4130f4b..9e78568cd 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -10,6 +10,7 @@ import {
10 setAccessTokensToServers, uninstallPlugin 10 setAccessTokensToServers, uninstallPlugin
11} from '../../../shared/extra-utils' 11} from '../../../shared/extra-utils'
12import { expect } from 'chai' 12import { expect } from 'chai'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 14
14describe('Test plugin helpers', function () { 15describe('Test plugin helpers', function () {
15 let server: ServerInfo 16 let server: ServerInfo
@@ -36,7 +37,7 @@ describe('Test plugin helpers', function () {
36 const res = await makeGetRequest({ 37 const res = await makeGetRequest({
37 url: server.url, 38 url: server.url,
38 path: path + 'ping', 39 path: path + 'ping',
39 statusCodeExpected: 200 40 statusCodeExpected: HttpStatusCode.OK_200
40 }) 41 })
41 42
42 expect(res.body.message).to.equal('pong') 43 expect(res.body.message).to.equal('pong')
@@ -55,7 +56,7 @@ describe('Test plugin helpers', function () {
55 url: server.url, 56 url: server.url,
56 path: path + 'form/post/mirror', 57 path: path + 'form/post/mirror',
57 fields: body, 58 fields: body,
58 statusCodeExpected: 200 59 statusCodeExpected: HttpStatusCode.OK_200
59 }) 60 })
60 61
61 expect(res.body).to.deep.equal(body) 62 expect(res.body).to.deep.equal(body)
@@ -73,14 +74,14 @@ describe('Test plugin helpers', function () {
73 await makeGetRequest({ 74 await makeGetRequest({
74 url: server.url, 75 url: server.url,
75 path: path + 'ping', 76 path: path + 'ping',
76 statusCodeExpected: 404 77 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
77 }) 78 })
78 79
79 await makePostBodyRequest({ 80 await makePostBodyRequest({
80 url: server.url, 81 url: server.url,
81 path: path + 'ping', 82 path: path + 'ping',
82 fields: {}, 83 fields: {},
83 statusCodeExpected: 404 84 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
84 }) 85 })
85 } 86 }
86 }) 87 })