I'm trying to write a test for my application, where by I've used express-brute to prevent brute force attacks.
I have the following test:
it('should return 429 status after 1000 attempts', function (done) {
this.timeout(5000);
var counter = 0;
var makeRequest = function (count, done) {
counter++;
request(app)
.post('/login')
.send({ username: 'a+' + count + '@b.com', password: 'wrong' + count })
.end(function (err, res) {
if (err) {
console.log('failed request #', counter);
return done(err);
}
if (counter < 1001) {
makeRequest(counter, done);
}
else {
res.header.location.should.equal('/account/login');
res.statusCode.should.equal(429);
done();
}
});
}
makeRequest(counter, done);
});
Which throws either error:
Error: socket hang up sometimes it is Error: read ECONNRESET
It's always around connection # 225
The same test (with only 20 or so requests) works fine (if i change my express-brute config)
What's causing it to error out?
Am I not closing / disposing the connections correctly?