})
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
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'
})
describe('With the standard log file', function () {
+
it('Should get logs with a start date', async function () {
this.timeout(10000)
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 () {
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
return getFileSize(path)
}
+function makePingRequest (server: ServerInfo) {
+ return makeGetRequest({
+ url: server.url,
+ path: '/api/v1/ping',
+ statusCodeExpected: 200
+ })
+}
+
// ---------------------------------------------------------------------------
export {
cleanupTests,
flushAndRunMultipleServers,
flushTests,
+ makePingRequest,
flushAndRunServer,
killallServers,
reRunServer,