Skip to content

Commit c857eae

Browse files
committed
Fix interception issue
1 parent c68f642 commit c857eae

9 files changed

Lines changed: 51 additions & 14 deletions

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@securenative/sdk",
3-
"version": "0.0.0-development",
3+
"version": "1.9.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
1818
"build": "tsc",
1919
"debug-inspector": "node-debug index.ts --debug-brk",
2020
"coverage": "codecov",
21-
"test": "NODE_ENV=test nyc --reporter=lcov mocha -r ts-node/register src/**/*.spec.ts",
21+
"test": "NODE_ENV=test nyc --reporter=lcov mocha -r ts-node/register './src/**/*.spec.ts'",
2222
"publish": "npm publish --access public",
2323
"semantic-release": "semantic-release"
2424
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (!config.appName) {
2323
ConfigurationManager.setConfigKey('hostId', hostId);
2424

2525
const moduleManager = new ModuleManager(appPkg);
26-
const eventManager = new EventManager(fetch, this.options);
26+
const eventManager = new EventManager(fetch, config);
2727
const secureNative = new SecureNative(moduleManager, eventManager, config);
2828

2929
// init logger
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import chai from 'chai';
2+
import chaiAsPromised from 'chai-as-promised';
3+
import HttpServerInterceptor from './http-server-interceptor';
4+
import InterceptionModule from '../enums/interception-module';
5+
6+
chai.use(chaiAsPromised);
7+
const expect = chai.expect;
8+
9+
describe('HttpServerInterceptor', () => {
10+
it('Should export correct module', () => {
11+
const interceptor = new HttpServerInterceptor(null, null, null);
12+
expect(interceptor.getModule()).to.be.eql(InterceptionModule.Http)
13+
});
14+
});

src/interceptors/http-server-interceptor.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Logger } from '../logger';
77
import Hook from 'require-in-the-middle';
88
import { wrap } from 'shimmer';
99
import ActionsList from './../actions-list';
10-
import { clientIpFromRequest, contextFromRequest } from './../utils/utils';
10+
import { clientIpFromRequest, contextFromRequest, contextFromResponse } from './../utils/utils';
1111
import { SecureNativeOptions } from '../types/securenative-options';
1212
import { getDeviceFp } from './../utils/utils';
1313
import SetType from '../enums/set-type';
@@ -95,14 +95,23 @@ export default class HttpServerInterceptor extends Interceptor implements IInter
9595
const risk = this.apiManager.risk.bind(this);
9696

9797
return function () {
98-
if (!this && !this.sn_finished) {
99-
intercept(this.req && this.req.sn_uid, 'end');
100-
return original.apply(this, arguments);
98+
if (this && this.sn_finished) {
99+
SessionManager.cleanSession(this.req && this.req.sn_uid);
100+
return;
101101
}
102102

103-
const context = contextFromRequest(this.req);
104-
risk({ eventType: EventType.RISK, context: context });
105-
return SessionManager.cleanSession(this.req && this.req.sn_uid);
103+
intercept(this.req && this.req.sn_uid, 'end');
104+
const { req, res } = SessionManager.getSession(this.req?.sn_uid);
105+
if (req && res) {
106+
const reqContext = contextFromRequest(req);
107+
const resContext = contextFromResponse(res);
108+
109+
risk({ eventType: EventType.RISK, context: { reqContext, resContext } });
110+
}
111+
112+
SessionManager.cleanSession(this.req && this.req.sn_uid);
113+
114+
return original.apply(this, arguments);
106115
};
107116
});
108117

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import chai from 'chai';
2+
import chaiAsPromised from 'chai-as-promised';
3+
import InterceptionModule from '../enums/interception-module';
4+
import HttpsServerInterceptor from './https-server-interceptor';
5+
6+
chai.use(chaiAsPromised);
7+
const expect = chai.expect;
8+
9+
describe('HttpServerInterceptor', () => {
10+
it('Should export correct module', () => {
11+
const interceptor = new HttpsServerInterceptor(null, null, null);
12+
expect(interceptor.getModule()).to.be.eql(InterceptionModule.Https)
13+
});
14+
});

src/interceptors/https-server-interceptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class HttpsServerInterceptor extends Interceptor implements IInte
2222
}
2323

2424
getModule() {
25-
return InterceptionModule.Http;
25+
return InterceptionModule.Https;
2626
}
2727

2828
canExecute(): boolean {

src/session-manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('SessionManager', () => {
3434

3535
sessions.forEach((id) => {
3636
const session = SessionManager.getSession(id);
37-
expect(session).to.be.undefined;
37+
expect(session).to.be.eql({ req: null, res: null });
3838
});
3939
});
4040

src/session-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class SessionManager {
1414
}
1515

1616
static getSession(id: string): Session {
17-
return SessionManager.session.get(id);
17+
return SessionManager.session.get(id) || { req: null, res: null };
1818
}
1919

2020
static setSession(id: string, session: Session) {

0 commit comments

Comments
 (0)