diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-15 15:30:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-18 11:37:18 +0200 |
commit | 42b40636991b97fe818007fab19091764fc5db73 (patch) | |
tree | db431787c06ce898d22e91ff771f795219274fc6 /server/tests/api/check-params/logs.ts | |
parent | 654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff) | |
download | PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.gz PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.zst PeerTube-42b40636991b97fe818007fab19091764fc5db73.zip |
Add ability for client to create server logs
Diffstat (limited to 'server/tests/api/check-params/logs.ts')
-rw-r--r-- | server/tests/api/check-params/logs.ts | 59 |
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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 4 | import { expect } from 'chai' |
5 | import { HttpStatusCode } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/models' |
6 | import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
6 | 7 | ||
7 | describe('Test logs API validators', function () { | 8 | describe('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 | }) |