Fix jwt-token
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
const { describe, it, beforeEach, afterEach, before, after } = require('mocha');
|
||||
const { expect } = require('chai');
|
||||
const sinon = require('sinon');
|
||||
const { checkIPRestriction } = require('../../middleware/ip-restriction');
|
||||
const IPRestrictionMiddleware = require('../../middleware/ip-restriction');
|
||||
const { setupTestEnvironment, teardownTestEnvironment, cleanDatabase, mockRequest, mockResponse, mockNext, createTestUser, createTestTenant } = require('../setup');
|
||||
|
||||
describe('IP Restriction Middleware', () => {
|
||||
let models, sequelize;
|
||||
let models, sequelize, ipRestriction;
|
||||
|
||||
before(async () => {
|
||||
({ models, sequelize } = await setupTestEnvironment());
|
||||
ipRestriction = new IPRestrictionMiddleware();
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
@@ -34,7 +35,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -53,7 +54,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -72,7 +73,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(403);
|
||||
expect(res.data).to.deep.equal({
|
||||
@@ -90,7 +91,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -110,7 +111,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -130,7 +131,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -149,7 +150,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(next.errors).to.have.length(0);
|
||||
});
|
||||
@@ -168,7 +169,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(403);
|
||||
});
|
||||
@@ -190,7 +191,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
expect(next.errors).to.have.length(0);
|
||||
}
|
||||
});
|
||||
@@ -217,7 +218,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
expect(next.errors).to.have.length(0);
|
||||
}
|
||||
});
|
||||
@@ -236,7 +237,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(403);
|
||||
});
|
||||
@@ -255,7 +256,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(403);
|
||||
});
|
||||
@@ -276,7 +277,7 @@ describe('IP Restriction Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await checkIPRestriction(req, res, next);
|
||||
await ipRestriction.checkIPRestriction(req, res, next);
|
||||
|
||||
expect(consoleLogSpy.calledWith(sinon.match(/🚫.*IP restriction/))).to.be.true;
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('Multi-Tenant Authentication Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await multiAuth.middleware(req, res, next);
|
||||
await multiAuth.authenticate(req, res, next);
|
||||
|
||||
expect(req.tenant).to.equal(tenant.slug);
|
||||
expect(next.errors).to.have.length(0);
|
||||
@@ -116,7 +116,7 @@ describe('Multi-Tenant Authentication Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await multiAuth.middleware(req, res, next);
|
||||
await multiAuth.authenticate(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(400);
|
||||
expect(res.data).to.deep.equal({
|
||||
@@ -132,7 +132,7 @@ describe('Multi-Tenant Authentication Middleware', () => {
|
||||
const res = mockResponse();
|
||||
const next = mockNext();
|
||||
|
||||
await multiAuth.middleware(req, res, next);
|
||||
await multiAuth.authenticate(req, res, next);
|
||||
|
||||
expect(res.statusCode).to.equal(404);
|
||||
expect(res.data).to.deep.equal({
|
||||
|
||||
Reference in New Issue
Block a user