]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix and add skipping ping log tests
authorChocobozzz <me@florianbigard.com>
Wed, 13 Jan 2021 08:38:19 +0000 (09:38 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 13 Jan 2021 08:38:19 +0000 (09:38 +0100)
server.ts
server/tests/api/server/logs.ts
shared/extra-utils/server/servers.ts

index f844c9564b5dacc37ac58cbb8f7d323816650891..e3cddfd33a643a623cfa53932fc34adca138c673 100644 (file)
--- 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
index b8714c7a104df5a4c90790a591f4380fb72e4a0b..c458789b6c89e06249bf2f9d9d622e2e3fe14cf0 100644 (file)
@@ -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 () {
index 5e1de6ece33e3f4a19862cfe4019c5f8a823c072..6ab7bee9098e94b2e40db6ba789ee7c87fca5b8d 100644 (file)
@@ -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,