aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-01-13 09:38:19 +0100
committerChocobozzz <me@florianbigard.com>2021-01-13 09:38:19 +0100
commit78d62f4d182be2f72f4901c38a0d10bb147896e8 (patch)
treed68b591387a526b235311fc5ec3a2d6f871a071b
parent9bb720f3f96d781d5e132220ace4515e779cea3c (diff)
downloadPeerTube-78d62f4d182be2f72f4901c38a0d10bb147896e8.tar.gz
PeerTube-78d62f4d182be2f72f4901c38a0d10bb147896e8.tar.zst
PeerTube-78d62f4d182be2f72f4901c38a0d10bb147896e8.zip
Fix and add skipping ping log tests
-rw-r--r--server.ts4
-rw-r--r--server/tests/api/server/logs.ts31
-rw-r--r--shared/extra-utils/server/servers.ts10
3 files changed, 41 insertions, 4 deletions
diff --git a/server.ts b/server.ts
index f844c9564..e3cddfd33 100644
--- a/server.ts
+++ b/server.ts
@@ -159,9 +159,7 @@ morgan.token('user-agent', (req: express.Request) => {
159}) 159})
160app.use(morgan('combined', { 160app.use(morgan('combined', {
161 stream: { write: logger.info.bind(logger) }, 161 stream: { write: logger.info.bind(logger) },
162 skip: function (req, res) { 162 skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
163 return (req.path === '/api/v1/ping' && CONFIG.LOG.LOG_PING_REQUESTS === false)
164 },
165})) 163}))
166 164
167// For body requests 165// For body requests
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
index b8714c7a1..c458789b6 100644
--- a/server/tests/api/server/logs.ts
+++ b/server/tests/api/server/logs.ts
@@ -2,7 +2,7 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' 5import { cleanupTests, flushAndRunServer, killallServers, makeGetRequest, makePingRequest, reRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
6import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 6import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
7import { uploadVideo } from '../../../../shared/extra-utils/videos/videos' 7import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
8import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs' 8import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
@@ -20,6 +20,7 @@ describe('Test logs', function () {
20 }) 20 })
21 21
22 describe('With the standard log file', function () { 22 describe('With the standard log file', function () {
23
23 it('Should get logs with a start date', async function () { 24 it('Should get logs with a start date', async function () {
24 this.timeout(10000) 25 this.timeout(10000)
25 26
@@ -84,6 +85,34 @@ describe('Test logs', function () {
84 expect(logsString.includes('video 6')).to.be.false 85 expect(logsString.includes('video 6')).to.be.false
85 } 86 }
86 }) 87 })
88
89 it('Should log ping requests', async function () {
90 const now = new Date()
91
92 await makePingRequest(server)
93
94 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
95 const logsString = JSON.stringify(res.body)
96
97 expect(logsString.includes('/api/v1/ping')).to.be.true
98 })
99
100 it('Should not log ping requests', async function () {
101 this.timeout(30000)
102
103 killallServers([ server ])
104
105 await reRunServer(server, { log: { log_ping_requests: false } })
106
107 const now = new Date()
108
109 await makePingRequest(server)
110
111 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
112 const logsString = JSON.stringify(res.body)
113
114 expect(logsString.includes('/api/v1/ping')).to.be.false
115 })
87 }) 116 })
88 117
89 describe('With the audit log', function () { 118 describe('With the audit log', function () {
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 5e1de6ece..6ab7bee90 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -7,6 +7,7 @@ import { join } from 'path'
7import { randomInt } from '../../core-utils/miscs/miscs' 7import { randomInt } from '../../core-utils/miscs/miscs'
8import { VideoChannel } from '../../models/videos' 8import { VideoChannel } from '../../models/videos'
9import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' 9import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
10import { makeGetRequest } from '../requests/requests'
10 11
11interface ServerInfo { 12interface ServerInfo {
12 app: ChildProcess 13 app: ChildProcess
@@ -347,6 +348,14 @@ async function getServerFileSize (server: ServerInfo, subPath: string) {
347 return getFileSize(path) 348 return getFileSize(path)
348} 349}
349 350
351function makePingRequest (server: ServerInfo) {
352 return makeGetRequest({
353 url: server.url,
354 path: '/api/v1/ping',
355 statusCodeExpected: 200
356 })
357}
358
350// --------------------------------------------------------------------------- 359// ---------------------------------------------------------------------------
351 360
352export { 361export {
@@ -358,6 +367,7 @@ export {
358 cleanupTests, 367 cleanupTests,
359 flushAndRunMultipleServers, 368 flushAndRunMultipleServers,
360 flushTests, 369 flushTests,
370 makePingRequest,
361 flushAndRunServer, 371 flushAndRunServer,
362 killallServers, 372 killallServers,
363 reRunServer, 373 reRunServer,