Merge pull request #182 from Permissionless-Software-Foundation/ct-unstable

fix(rate-limits): Further slowing down anon freeloaders
This commit is contained in:
Chris Troutner
2022-04-08 07:38:08 -07:00
committed by GitHub
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ const config = require('../../config')
// The amount of delay in milliseconds to add to anonymous requests, in order // The amount of delay in milliseconds to add to anonymous requests, in order
// to slow down freeloaders that are hitting the system too hard. // to slow down freeloaders that are hitting the system too hard.
const ANON_DELAY = 1000 const ANON_DELAY = 3000
let _this // Global pointer to instance of class, when 'this' context is lost. let _this // Global pointer to instance of class, when 'this' context is lost.
+9
View File
@@ -204,6 +204,9 @@ describe('#rate-routelimit', () => {
describe('#trackRateLimits', () => { describe('#trackRateLimits', () => {
it('should apply anonymous rate limits if no JWT token is provided', async () => { it('should apply anonymous rate limits if no JWT token is provided', async () => {
// Mock sleep function
sandbox.stub(uut, 'sleep').resolves()
req.ip = '127.0.0.1' req.ip = '127.0.0.1'
const result = await uut.trackRateLimits(req, res) const result = await uut.trackRateLimits(req, res)
@@ -278,6 +281,9 @@ describe('#rate-routelimit', () => {
}) })
it('should apply rate limits to anonymous users', async () => { it('should apply rate limits to anonymous users', async () => {
// Mock sleep function
sandbox.stub(uut, 'sleep').resolves()
req.ip = '123.456.7.8' req.ip = '123.456.7.8'
// console.log('next.callCount: ', next.callCount) // console.log('next.callCount: ', next.callCount)
@@ -302,6 +308,9 @@ describe('#rate-routelimit', () => {
}) })
it('should return 429 error when anonymous users exceed rate limit', async () => { it('should return 429 error when anonymous users exceed rate limit', async () => {
// Mock sleep function
sandbox.stub(uut, 'sleep').resolves()
req.ip = '123.456.7.8' req.ip = '123.456.7.8'
// force req.locals.jwtToken to be empty. // force req.locals.jwtToken to be empty.