diff --git a/packages/server/jest.setup.js b/packages/server/jest.setup.js index ac7733a29..47829a53a 100644 --- a/packages/server/jest.setup.js +++ b/packages/server/jest.setup.js @@ -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'; diff --git a/packages/server/src/middleware/routeHandler.ts b/packages/server/src/middleware/routeHandler.ts index 402b59ab3..62867d98d 100644 --- a/packages/server/src/middleware/routeHandler.ts +++ b/packages/server/src/middleware/routeHandler.ts @@ -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; diff --git a/packages/server/src/utils/request/limiterLoginBruteForce.ts b/packages/server/src/utils/request/limiterLoginBruteForce.ts index ca4a870ab..d9c465edf 100644 --- a/packages/server/src/utils/request/limiterLoginBruteForce.ts +++ b/packages/server/src/utils/request/limiterLoginBruteForce.ts @@ -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) {