aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 10:56:29 +0200
committerChocobozzz <me@florianbigard.com>2019-04-11 10:58:09 +0200
commit5d79474cc66383ecbfcef6366f63a34c3af21cbf (patch)
tree6b2cd85c25294ca04c94cbbcc90353d25e9cee06 /server
parent2b3f1919fda81c2781ceeb9071d426c184e1b21c (diff)
downloadPeerTube-5d79474cc66383ecbfcef6366f63a34c3af21cbf.tar.gz
PeerTube-5d79474cc66383ecbfcef6366f63a34c3af21cbf.tar.zst
PeerTube-5d79474cc66383ecbfcef6366f63a34c3af21cbf.zip
Add debug component to help admins to fix IP issues
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/server/debug.ts25
-rw-r--r--server/controllers/api/server/index.ts2
-rw-r--r--server/tests/api/check-params/debug.ts78
-rw-r--r--server/tests/api/check-params/index.ts1
4 files changed, 106 insertions, 0 deletions
diff --git a/server/controllers/api/server/debug.ts b/server/controllers/api/server/debug.ts
new file mode 100644
index 000000000..4450038f6
--- /dev/null
+++ b/server/controllers/api/server/debug.ts
@@ -0,0 +1,25 @@
1import * as express from 'express'
2import { UserRight } from '../../../../shared/models/users'
3import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
4
5const debugRouter = express.Router()
6
7debugRouter.get('/debug',
8 authenticate,
9 ensureUserHasRight(UserRight.MANAGE_DEBUG),
10 asyncMiddleware(getDebug)
11)
12
13// ---------------------------------------------------------------------------
14
15export {
16 debugRouter
17}
18
19// ---------------------------------------------------------------------------
20
21async function getDebug (req: express.Request, res: express.Response) {
22 return res.json({
23 ip: req.ip
24 }).end()
25}
diff --git a/server/controllers/api/server/index.ts b/server/controllers/api/server/index.ts
index de09588df..6b8793a19 100644
--- a/server/controllers/api/server/index.ts
+++ b/server/controllers/api/server/index.ts
@@ -5,6 +5,7 @@ import { serverRedundancyRouter } from './redundancy'
5import { serverBlocklistRouter } from './server-blocklist' 5import { serverBlocklistRouter } from './server-blocklist'
6import { contactRouter } from './contact' 6import { contactRouter } from './contact'
7import { logsRouter } from './logs' 7import { logsRouter } from './logs'
8import { debugRouter } from './debug'
8 9
9const serverRouter = express.Router() 10const serverRouter = express.Router()
10 11
@@ -14,6 +15,7 @@ serverRouter.use('/', statsRouter)
14serverRouter.use('/', serverBlocklistRouter) 15serverRouter.use('/', serverBlocklistRouter)
15serverRouter.use('/', contactRouter) 16serverRouter.use('/', contactRouter)
16serverRouter.use('/', logsRouter) 17serverRouter.use('/', logsRouter)
18serverRouter.use('/', debugRouter)
17 19
18// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
19 21
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
new file mode 100644
index 000000000..9bf664657
--- /dev/null
+++ b/server/tests/api/check-params/debug.ts
@@ -0,0 +1,78 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 runServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin
13} from '../../../../shared/utils'
14import { makeGetRequest } from '../../../../shared/utils/requests/requests'
15
16describe('Test debug API validators', function () {
17 const path = '/api/v1/server/debug'
18 let server: ServerInfo
19 let userAccessToken = ''
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(120000)
25
26 await flushTests()
27
28 server = await runServer(1)
29
30 await setAccessTokensToServers([ server ])
31
32 const user = {
33 username: 'user1',
34 password: 'my super password'
35 }
36 await createUser(server.url, server.accessToken, user.username, user.password)
37 userAccessToken = await userLogin(server, user)
38 })
39
40 describe('When getting debug endpoint', function () {
41
42 it('Should fail with a non authenticated user', async function () {
43 await makeGetRequest({
44 url: server.url,
45 path,
46 statusCodeExpected: 401
47 })
48 })
49
50 it('Should fail with a non admin user', async function () {
51 await makeGetRequest({
52 url: server.url,
53 path,
54 token: userAccessToken,
55 statusCodeExpected: 403
56 })
57 })
58
59 it('Should succeed with the correct params', async function () {
60 await makeGetRequest({
61 url: server.url,
62 path,
63 token: server.accessToken,
64 query: { startDate: new Date().toISOString() },
65 statusCodeExpected: 200
66 })
67 })
68 })
69
70 after(async function () {
71 killallServers([ server ])
72
73 // Keep the logs if the test failed
74 if (this['ok']) {
75 await flushTests()
76 }
77 })
78})
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index bdac95025..844fa31c5 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -2,6 +2,7 @@ import './accounts'
2import './blocklist' 2import './blocklist'
3import './config' 3import './config'
4import './contact-form' 4import './contact-form'
5import './debug'
5import './follows' 6import './follows'
6import './jobs' 7import './jobs'
7import './logs' 8import './logs'