1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Tools: Fixed tests

This commit is contained in:
Laurent Cozic 2021-08-15 00:53:44 +01:00
parent c7421dfbe1
commit e0971baec4
3 changed files with 7 additions and 2 deletions

View File

@ -1,3 +1,5 @@
// We don't want the tests to fail due to timeout, especially on CI, and certain
// tests can take more time since we do integration testing too.
jest.setTimeout(30 * 1000);
process.env.JOPLIN_IS_TESTING = '1';

View File

@ -38,7 +38,7 @@ export default async function(ctx: AppContext) {
const responseFormat = routeResponseFormat(ctx);
if (error.retryAfterMs) ctx.set('Retry-After', Math.ceil(error.retryAfterMs / 1000).toString());
if (error.retryAfterMs) ctx.response.set('Retry-After', Math.ceil(error.retryAfterMs / 1000).toString());
if (error.code === 'invalidOrigin') {
ctx.response.body = error.message;

View File

@ -2,11 +2,14 @@ import { RateLimiterMemory, RateLimiterRes } from 'rate-limiter-flexible';
import { ErrorTooManyRequests } from '../errors';
const limiterSlowBruteByIP = new RateLimiterMemory({
points: 3, // Up to 3 request per IP
points: 3, // Up to 3 requests per IP
duration: 30, // Per 30 seconds
});
export default async function(ip: string) {
// Tests need to make many requests quickly so we disable it in this case.
if (process.env.JOPLIN_IS_TESTING === '1') return;
try {
await limiterSlowBruteByIP.consume(ip);
} catch (error) {