mirror of https://github.com/Chocobozzz/PeerTube
Fix and add skipping ping log tests
parent
9bb720f3f9
commit
78d62f4d18
|
@ -159,9 +159,7 @@ morgan.token('user-agent', (req: express.Request) => {
|
||||||
})
|
})
|
||||||
app.use(morgan('combined', {
|
app.use(morgan('combined', {
|
||||||
stream: { write: logger.info.bind(logger) },
|
stream: { write: logger.info.bind(logger) },
|
||||||
skip: function (req, res) {
|
skip: req => CONFIG.LOG.LOG_PING_REQUESTS === false && req.originalUrl === '/api/v1/ping'
|
||||||
return (req.path === '/api/v1/ping' && CONFIG.LOG.LOG_PING_REQUESTS === false)
|
|
||||||
},
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// For body requests
|
// For body requests
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
import 'mocha'
|
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 { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
||||||
import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
|
import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
|
||||||
import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
|
import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
|
||||||
|
@ -20,6 +20,7 @@ describe('Test logs', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('With the standard log file', function () {
|
describe('With the standard log file', function () {
|
||||||
|
|
||||||
it('Should get logs with a start date', async function () {
|
it('Should get logs with a start date', async function () {
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
|
|
||||||
|
@ -84,6 +85,34 @@ describe('Test logs', function () {
|
||||||
expect(logsString.includes('video 6')).to.be.false
|
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 () {
|
describe('With the audit log', function () {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { join } from 'path'
|
||||||
import { randomInt } from '../../core-utils/miscs/miscs'
|
import { randomInt } from '../../core-utils/miscs/miscs'
|
||||||
import { VideoChannel } from '../../models/videos'
|
import { VideoChannel } from '../../models/videos'
|
||||||
import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
|
import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs'
|
||||||
|
import { makeGetRequest } from '../requests/requests'
|
||||||
|
|
||||||
interface ServerInfo {
|
interface ServerInfo {
|
||||||
app: ChildProcess
|
app: ChildProcess
|
||||||
|
@ -347,6 +348,14 @@ async function getServerFileSize (server: ServerInfo, subPath: string) {
|
||||||
return getFileSize(path)
|
return getFileSize(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makePingRequest (server: ServerInfo) {
|
||||||
|
return makeGetRequest({
|
||||||
|
url: server.url,
|
||||||
|
path: '/api/v1/ping',
|
||||||
|
statusCodeExpected: 200
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -358,6 +367,7 @@ export {
|
||||||
cleanupTests,
|
cleanupTests,
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
flushTests,
|
flushTests,
|
||||||
|
makePingRequest,
|
||||||
flushAndRunServer,
|
flushAndRunServer,
|
||||||
killallServers,
|
killallServers,
|
||||||
reRunServer,
|
reRunServer,
|
||||||
|
|
Loading…
Reference in New Issue