aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/logs.ts59
1 files changed, 58 insertions, 1 deletions
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 970671c15..fa67408b7 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -1,8 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
6 7
7describe('Test logs API validators', function () { 8describe('Test logs API validators', function () {
8 const path = '/api/v1/server/logs' 9 const path = '/api/v1/server/logs'
@@ -95,6 +96,62 @@ describe('Test logs API validators', function () {
95 }) 96 })
96 }) 97 })
97 98
99 describe('When creating client logs', function () {
100 const base = {
101 level: 'warn' as 'warn',
102 message: 'my super message',
103 url: 'https://example.com/toto'
104 }
105 const expectedStatus = HttpStatusCode.BAD_REQUEST_400
106
107 it('Should fail with an invalid level', async function () {
108 await server.logs.createLogClient({ payload: { ...base, level: '' as any }, expectedStatus })
109 await server.logs.createLogClient({ payload: { ...base, level: undefined }, expectedStatus })
110 await server.logs.createLogClient({ payload: { ...base, level: 'toto' as any }, expectedStatus })
111 })
112
113 it('Should fail with an invalid message', async function () {
114 await server.logs.createLogClient({ payload: { ...base, message: undefined }, expectedStatus })
115 await server.logs.createLogClient({ payload: { ...base, message: '' }, expectedStatus })
116 await server.logs.createLogClient({ payload: { ...base, message: 'm'.repeat(2500) }, expectedStatus })
117 })
118
119 it('Should fail with an invalid url', async function () {
120 await server.logs.createLogClient({ payload: { ...base, url: undefined }, expectedStatus })
121 await server.logs.createLogClient({ payload: { ...base, url: 'toto' }, expectedStatus })
122 })
123
124 it('Should fail with an invalid stackTrace', async function () {
125 await server.logs.createLogClient({ payload: { ...base, stackTrace: 's'.repeat(10000) }, expectedStatus })
126 })
127
128 it('Should fail with an invalid userAgent', async function () {
129 await server.logs.createLogClient({ payload: { ...base, userAgent: 's'.repeat(500) }, expectedStatus })
130 })
131
132 it('Should fail with an invalid meta', async function () {
133 await server.logs.createLogClient({ payload: { ...base, meta: 's'.repeat(10000) }, expectedStatus })
134 })
135
136 it('Should succeed with the correct params', async function () {
137 await server.logs.createLogClient({ payload: { ...base, stackTrace: 'stackTrace', meta: '{toto}', userAgent: 'userAgent' } })
138 })
139
140 it('Should rate limit log creation', async function () {
141 let fail = false
142
143 for (let i = 0; i < 10; i++) {
144 try {
145 await server.logs.createLogClient({ token: null, payload: base })
146 } catch {
147 fail = true
148 }
149 }
150
151 expect(fail).to.be.true
152 })
153 })
154
98 after(async function () { 155 after(async function () {
99 await cleanupTests([ server ]) 156 await cleanupTests([ server ])
100 }) 157 })