Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix and add skipping ping log tests

Chocobozzz78d62f4d182b
diff --git a/server.ts b/server.ts
index f844c9564b..e3cddfd33a 100644
--- a/server.ts
+++ b/server.ts
@@ -159,9 +159,7 @@ morgan.token('user-agent', (req: express.Request) => {
})
app.use(morgan('combined', {
stream: { write: logger.info.bind(logger) },
- skip: function (req, res) {
- return (req.path === '/api/v1/ping' && CONFIG.LOG.LOG_PING_REQUESTS === false)
- },
+ skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
}))
// For body requests
diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts
index b8714c7a10..c458789b6c 100644
--- a/server/tests/api/server/logs.ts
+++ b/server/tests/api/server/logs.ts
@@ -2,7 +2,7 @@
import * as chai from 'chai'
import 'mocha'
-import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
+import { cleanupTests, flushAndRunServer, killallServers, makeGetRequest, makePingRequest, reRunServer, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
@@ -20,6 +20,7 @@ describe('Test logs', function () {
})
describe('With the standard log file', function () {
+
it('Should get logs with a start date', async function () {
this.timeout(10000)
@@ -84,6 +85,34 @@ describe('Test logs', function () {
expect(logsString.includes('video 6')).to.be.false
}
})
+
+ it('Should log ping requests', async function () {
+ const now = new Date()
+
+ await makePingRequest(server)
+
+ const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
+ const logsString = JSON.stringify(res.body)
+
+ expect(logsString.includes('/api/v1/ping')).to.be.true
+ })
+
+ it('Should not log ping requests', async function () {
+ this.timeout(30000)
+
+ killallServers([ server ])
+
+ await reRunServer(server, { log: { log_ping_requests: false } })
+
+ const now = new Date()
+
+ await makePingRequest(server)
+
+ const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
+ const logsString = JSON.stringify(res.body)
+
+ expect(logsString.includes('/api/v1/ping')).to.be.false
+ })
})
describe('With the audit log', function () {
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 5e1de6ece3..6ab7bee909 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -7,6 +7,7 @@ import { join } from 'path'
import { randomInt } from '../../core-utils/miscs/miscs'
import { VideoChannel } from '../../models/videos'
import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
+import { makeGetRequest } from '../requests/requests'
interface ServerInfo {
app: ChildProcess
@@ -347,6 +348,14 @@ async function getServerFileSize (server: ServerInfo, subPath: string) {
return getFileSize(path)
}
+function makePingRequest (server: ServerInfo) {
+ return makeGetRequest({
+ url: server.url,
+ path: '/api/v1/ping',
+ statusCodeExpected: 200
+ })
+}
+
// ---------------------------------------------------------------------------
export {
@@ -358,6 +367,7 @@ export {
cleanupTests,
flushAndRunMultipleServers,
flushTests,
+ makePingRequest,
flushAndRunServer,
killallServers,
reRunServer,