@igxjs/node-components 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -4
- package/components/http-handlers.js +6 -0
- package/components/jwt.js +89 -45
- package/components/session.js +571 -101
- package/index.d.ts +114 -44
- package/index.js +1 -1
- package/package.json +10 -3
- package/.github/workflows/node.js.yml +0 -31
- package/.github/workflows/npm-publish.yml +0 -33
- package/docs/README.md +0 -54
- package/docs/flex-router.md +0 -167
- package/docs/http-handlers.md +0 -302
- package/docs/jwt-manager.md +0 -124
- package/docs/redis-manager.md +0 -210
- package/docs/session-manager.md +0 -160
- package/tests/http-handlers.test.js +0 -21
- package/tests/jwt.test.js +0 -345
- package/tests/redis.test.js +0 -50
- package/tests/router.test.js +0 -50
- package/tests/session.test.js +0 -116
package/tests/session.test.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { describe, it, beforeEach, afterEach } from 'mocha';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import { SessionManager, SessionConfig } from '../components/session.js';
|
|
5
|
-
import { CustomError, httpCodes } from '../components/http-handlers.js';
|
|
6
|
-
|
|
7
|
-
describe('SessionManager', () => {
|
|
8
|
-
let sessionManager;
|
|
9
|
-
let clock;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
clock = sinon.useFakeTimers();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
clock.restore();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('SessionConfig', () => {
|
|
20
|
-
it('should create SessionConfig instance with properties', () => {
|
|
21
|
-
const config = new SessionConfig();
|
|
22
|
-
expect(config).to.be.instanceOf(SessionConfig);
|
|
23
|
-
expect(config).to.have.property('SSO_ENDPOINT_URL');
|
|
24
|
-
expect(config).to.have.property('SESSION_SECRET');
|
|
25
|
-
expect(config).to.have.property('REDIS_URL');
|
|
26
|
-
sessionManager = new SessionManager(config);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('Lock Management', () => {
|
|
31
|
-
describe('hasLock', () => {
|
|
32
|
-
it('should return false for email without lock', () => {
|
|
33
|
-
const result = sessionManager.hasLock('test@example.com');
|
|
34
|
-
expect(result).to.be.false;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return true for email with active lock', () => {
|
|
38
|
-
sessionManager.lock('test@example.com');
|
|
39
|
-
const result = sessionManager.hasLock('test@example.com');
|
|
40
|
-
expect(result).to.be.true;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return false for expired lock', () => {
|
|
44
|
-
sessionManager.lock('test@example.com');
|
|
45
|
-
clock.tick(61000);
|
|
46
|
-
const result = sessionManager.hasLock('test@example.com');
|
|
47
|
-
expect(result).to.be.false;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('lock', () => {
|
|
52
|
-
it('should create a lock for given email', () => {
|
|
53
|
-
sessionManager.lock('test@example.com');
|
|
54
|
-
expect(sessionManager.hasLock('test@example.com')).to.be.true;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should not create lock for empty email', () => {
|
|
58
|
-
sessionManager.lock('');
|
|
59
|
-
sessionManager.lock(null);
|
|
60
|
-
expect(sessionManager.hasLock('')).to.be.false;
|
|
61
|
-
expect(sessionManager.hasLock(null)).to.be.false;
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('authenticate', () => {
|
|
67
|
-
let req, res, next;
|
|
68
|
-
|
|
69
|
-
beforeEach(() => {
|
|
70
|
-
req = { user: null };
|
|
71
|
-
res = { redirect: sinon.stub() };
|
|
72
|
-
next = sinon.stub();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should call next() if user is authorized', () => {
|
|
76
|
-
req.user = { authorized: true };
|
|
77
|
-
const middleware = sessionManager.authenticate();
|
|
78
|
-
middleware(req, res, next);
|
|
79
|
-
expect(next.calledOnce).to.be.true;
|
|
80
|
-
expect(next.firstCall.args).to.be.empty;
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should call next with error if user is not authorized', () => {
|
|
84
|
-
req.user = { authorized: false };
|
|
85
|
-
const middleware = sessionManager.authenticate();
|
|
86
|
-
middleware(req, res, next);
|
|
87
|
-
expect(next.calledOnce).to.be.true;
|
|
88
|
-
const error = next.firstCall.args[0];
|
|
89
|
-
expect(error).to.be.instanceOf(CustomError);
|
|
90
|
-
expect(error.code).to.equal(httpCodes.UNAUTHORIZED);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should redirect if redirectUrl is provided', () => {
|
|
94
|
-
req.user = { authorized: false };
|
|
95
|
-
const middleware = sessionManager.authenticate(false, '/login');
|
|
96
|
-
middleware(req, res, next);
|
|
97
|
-
expect(res.redirect.calledWith('/login')).to.be.true;
|
|
98
|
-
expect(next.called).to.be.false;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should allow access in debug mode', () => {
|
|
102
|
-
req.user = null;
|
|
103
|
-
const middleware = sessionManager.authenticate(true);
|
|
104
|
-
middleware(req, res, next);
|
|
105
|
-
expect(next.calledOnce).to.be.true;
|
|
106
|
-
expect(next.firstCall.args).to.be.empty;
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('redisManager', () => {
|
|
111
|
-
it('should return null before initialization', () => {
|
|
112
|
-
const manager = sessionManager.redisManager();
|
|
113
|
-
expect(manager).to.be.null;
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|