IP Blocking (#12015)

* start implementing an ip blocker

* fix comments and add to list of middlewares

* fix code, comment code and improve response

* wip tests

* fix order

* fixes and tests
This commit is contained in:
Matteo Pagliazzi
2020-03-28 15:44:54 +01:00
committed by GitHub
parent a00add46a7
commit 9ab9b0f553
8 changed files with 212 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import {
CustomError,
NotAuthorized,
BadRequest,
Forbidden,
InternalServerError,
NotFound,
NotificationNotFound,
@@ -113,6 +114,32 @@ describe('Custom Errors', () => {
});
});
describe('Forbidden', () => {
it('is an instance of CustomError', () => {
const forbiddenError = new Forbidden();
expect(forbiddenError).to.be.an.instanceOf(CustomError);
});
it('it returns an http code of 401', () => {
const forbiddenError = new Forbidden();
expect(forbiddenError.httpCode).to.eql(403);
});
it('returns a default message', () => {
const forbiddenError = new Forbidden();
expect(forbiddenError.message).to.eql('Access forbidden.');
});
it('allows a custom message', () => {
const forbiddenError = new Forbidden('Custom Error Message');
expect(forbiddenError.message).to.eql('Custom Error Message');
});
});
describe('InternalServerError', () => {
it('is an instance of CustomError', () => {
const internalServerError = new InternalServerError();