From 62b36ab859d4ac30721cdf8edd090247c1460bdc Mon Sep 17 00:00:00 2001 From: PhilKunz Date: Mon, 5 Sep 2016 00:34:09 +0200 Subject: [PATCH] fix scoping of socket roles --- dist/smartsocket.classes.smartsocket.d.ts | 6 +++ dist/smartsocket.classes.smartsocket.js | 16 +++++++- dist/smartsocket.classes.smartsocketclient.js | 3 +- .../smartsocket.classes.socketconnection.d.ts | 3 ++ dist/smartsocket.classes.socketconnection.js | 7 ++-- dist/smartsocket.classes.socketrole.d.ts | 1 - dist/smartsocket.classes.socketrole.js | 4 +- dist/smartsocket.helpers.d.ts | 5 ++- dist/smartsocket.helpers.js | 11 +++--- package.json | 2 +- test/test.d.ts | 1 - test/test.js | 15 ++++--- test/test.ts | 39 ++++++++++--------- ts/smartsocket.classes.smartsocket.ts | 15 ++++++- ts/smartsocket.classes.smartsocketclient.ts | 1 + ts/smartsocket.classes.socketconnection.ts | 8 +++- ts/smartsocket.classes.socketrole.ts | 4 -- ts/smartsocket.helpers.ts | 10 ++--- 18 files changed, 96 insertions(+), 55 deletions(-) diff --git a/dist/smartsocket.classes.smartsocket.d.ts b/dist/smartsocket.classes.smartsocket.d.ts index c7dfa95..0184773 100644 --- a/dist/smartsocket.classes.smartsocket.d.ts +++ b/dist/smartsocket.classes.smartsocket.d.ts @@ -3,6 +3,7 @@ import * as plugins from "./smartsocket.plugins"; import { Objectmap } from "lik"; import { SocketConnection } from "./smartsocket.classes.socketconnection"; +import { SocketRole } from "./smartsocket.classes.socketrole"; export interface ISmartsocketConstructorOptions { port: number; } @@ -10,6 +11,7 @@ export declare class Smartsocket { options: ISmartsocketConstructorOptions; io: SocketIO.Server; openSockets: Objectmap; + socketRoles: Objectmap; constructor(optionsArg: ISmartsocketConstructorOptions); /** * the standard handler for new socket connections @@ -24,4 +26,8 @@ export declare class Smartsocket { * allows call to specific client. */ clientCall(functionNameArg: string, dataArg: any, targetSocketConnectionArg: SocketConnection): plugins.q.Promise<{}>; + /** + * adds socketRoles + */ + addSocketRoles(socketRolesArray: SocketRole[]): void; } diff --git a/dist/smartsocket.classes.smartsocket.js b/dist/smartsocket.classes.smartsocket.js index f3fb1cc..47ef04f 100644 --- a/dist/smartsocket.classes.smartsocket.js +++ b/dist/smartsocket.classes.smartsocket.js @@ -8,6 +8,7 @@ const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socke class Smartsocket { constructor(optionsArg) { this.openSockets = new lik_1.Objectmap(); + this.socketRoles = new lik_1.Objectmap(); /** * starts listening to incling sockets: */ @@ -37,6 +38,7 @@ class Smartsocket { authenticated: false, role: undefined, side: "server", + smartsocketHost: this, socket: socketArg }); plugins.beautylog.log("Socket connected. Trying to authenticate..."); @@ -71,6 +73,18 @@ class Smartsocket { }); return done.promise; } + ; + /** + * adds socketRoles + */ + addSocketRoles(socketRolesArray) { + for (let socketRole of socketRolesArray) { + this.socketRoles.add(socketRole); + } + ; + return; + } + ; } exports.Smartsocket = Smartsocket; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFHakQsVUFBVTtBQUNWLHNCQUEwQixLQUFLLENBQUMsQ0FBQTtBQUVoQyx1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUMxRSxvREFBOEIscUNBQXFDLENBQUMsQ0FBQTtBQUtuRSxDQUFDO0FBRUY7SUFJSSxZQUFZLFVBQTBDO1FBRHRELGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW9CLENBQUM7UUEyQmhEOztXQUVHO1FBRUgsZ0JBQVcsR0FBRztZQUNWLElBQUksQ0FBQyx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EI7O09BRUc7SUFDSCxVQUFVLENBQUMsZUFBc0IsRUFBQyxPQUFXLEVBQUMseUJBQTBDO1FBQ3BGLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDN0IsSUFBSSxhQUFhLEdBQUcsSUFBSSxpREFBYSxDQUFDO1lBQ2xDLElBQUksRUFBQyxZQUFZO1lBQ2pCLHNCQUFzQixFQUFDLHlCQUF5QjtZQUNoRCxPQUFPLEVBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxRQUFRLEVBQUU7WUFDbEMsWUFBWSxFQUFDO2dCQUNULFFBQVEsRUFBRSxlQUFlO2dCQUN6QixXQUFXLEVBQUMsT0FBTzthQUN0QjtTQUNKLENBQUMsQ0FBQztRQUNILGFBQWEsQ0FBQyxRQUFRLEVBQUU7YUFDbkIsSUFBSSxDQUFDLENBQUMsT0FBMkI7WUFDOUIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLENBQUM7UUFDdEMsQ0FBQyxDQUFDLENBQUM7UUFDUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztJQUVEOztPQUVHO0lBQ0gsY0FBYyxDQUFDLGdCQUE2QjtRQUN4QyxHQUFHLENBQUEsQ0FBQyxJQUFJLFVBQVUsSUFBSSxnQkFBZ0IsQ0FBQyxDQUFBLENBQUM7WUFDcEMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLENBQUM7UUFDckMsQ0FBQztRQUFBLENBQUM7UUFDRixNQUFNLENBQUM7SUFDWCxDQUFDOztBQUVMLENBQUM7QUFuRlksbUJBQVcsY0FtRnZCLENBQUEifQ== \ No newline at end of file diff --git a/dist/smartsocket.classes.smartsocketclient.js b/dist/smartsocket.classes.smartsocketclient.js index d641454..e8fa414 100644 --- a/dist/smartsocket.classes.smartsocketclient.js +++ b/dist/smartsocket.classes.smartsocketclient.js @@ -24,6 +24,7 @@ class SmartsocketClient { authenticated: false, role: undefined, side: "client", + smartsocketHost: null, socket: plugins.socketIoClient(socketUrl, { multiplex: false }) }); this.socketConnection.socket.on("requestAuth", () => { @@ -71,4 +72,4 @@ class SmartsocketClient { ; } exports.SmartsocketClient = SmartsocketClient; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zbWFydHNvY2tldGNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmNsYXNzZXMuc21hcnRzb2NrZXRjbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUl6QixDQUFDLENBSitDO0FBT2hELGlCQUFpQjtBQUNqQix1REFBaUMsd0NBQXdDLENBQUMsQ0FBQTtBQUUxRSxvREFBOEIscUNBQXFDLENBQUMsQ0FBQTtBQVlwRTtJQU9JLFlBQVksVUFBb0M7UUFDNUMsSUFBSSxDQUFDLEtBQUssR0FBRyxVQUFVLENBQUMsS0FBSyxDQUFDO1FBQzlCLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBVSxDQUFDLElBQUksQ0FBQztRQUM1QixJQUFJLENBQUMsU0FBUyxHQUFHLFVBQVUsQ0FBQyxHQUFHLENBQUE7UUFDL0IsSUFBSSxDQUFDLFVBQVUsR0FBRyxVQUFVLENBQUMsSUFBSSxDQUFDO1FBQ2xDLElBQUksQ0FBQyxjQUFjLEdBQUcsVUFBVSxDQUFDLFFBQVEsQ0FBQTtJQUM3QyxDQUFDOztJQUVEOztPQUVHO0lBQ0gsT0FBTztRQUNILElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7UUFDN0IsT0FBTyxDQUFDLFNBQVMsQ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thQUNuQixJQUFJLENBQUMsQ0FBQyxPQUEyQjtZQUM5QixJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUN0QyxDQUFDLENBQUMsQ0FBQztRQUNQLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3hCLENBQUM7O0FBRUwsQ0FBQztBQXhFWSx5QkFBaUIsb0JBd0U3QixDQUFBIn0= \ No newline at end of file diff --git a/dist/smartsocket.classes.socketconnection.d.ts b/dist/smartsocket.classes.socketconnection.d.ts index af46e80..11ba497 100644 --- a/dist/smartsocket.classes.socketconnection.d.ts +++ b/dist/smartsocket.classes.socketconnection.d.ts @@ -3,6 +3,7 @@ /// import * as plugins from "./smartsocket.plugins"; import { Objectmap } from "lik"; +import { Smartsocket } from "./smartsocket.classes.smartsocket"; import { SocketRole } from "./smartsocket.classes.socketrole"; /** * defines is a SocketConnection is server or client side. Important for mesh setups. @@ -16,6 +17,7 @@ export interface ISocketConnectionConstructorOptions { authenticated: boolean; role: SocketRole; side: TSocketConnectionSide; + smartsocketHost: Smartsocket; socket: SocketIO.Socket | SocketIOClient.Socket; } /** @@ -35,6 +37,7 @@ export declare class SocketConnection { side: TSocketConnectionSide; authenticated: boolean; role: SocketRole; + smartsocketHost: Smartsocket; socket: SocketIO.Socket | SocketIOClient.Socket; constructor(optionsArg: ISocketConnectionConstructorOptions); /** diff --git a/dist/smartsocket.classes.socketconnection.js b/dist/smartsocket.classes.socketconnection.js index 6ff7fe6..3dc270c 100644 --- a/dist/smartsocket.classes.socketconnection.js +++ b/dist/smartsocket.classes.socketconnection.js @@ -17,6 +17,7 @@ class SocketConnection { this.authenticated = optionsArg.authenticated; this.role = optionsArg.role; this.side = optionsArg.side; + this.smartsocketHost = optionsArg.smartsocketHost; this.socket = optionsArg.socket; // standard behaviour that is always true exports.allSocketConnections.add(this); @@ -35,10 +36,10 @@ class SocketConnection { this.socket.on("dataAuth", (dataArg) => { plugins.beautylog.log("received authentication data. now hashing and comparing..."); this.socket.removeListener("dataAuth", () => { }); - if (helpers.checkPasswordForRole(dataArg)) { + if (helpers.checkPasswordForRole(dataArg, this.smartsocketHost)) { this.alias = dataArg.alias; this.authenticated = true; - this.role = helpers.getSocketRoleByName(dataArg.role); + this.role = helpers.getSocketRoleByName(dataArg.role, this.smartsocketHost); this.socket.emit("authenticated"); plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`); done.resolve(this); @@ -102,4 +103,4 @@ class SocketConnection { } exports.SocketConnection = SocketConnection; ; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRjb25uZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSx1QkFBdUIsQ0FBQyxDQUFBO0FBQ2pELE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFFakQsc0JBQXdCLEtBQUssQ0FBQyxDQUFBO0FBSTlCLG9EQUEyRSxxQ0FBcUMsQ0FBQyxDQUFBO0FBbUJoSCxDQUFDO0FBU0QsQ0FBQztBQUVGLGlCQUFpQjtBQUNOLDRCQUFvQixHQUFHLElBQUksZUFBUyxFQUFvQixDQUFDO0FBRXBFOztHQUVHO0FBQ0g7SUFNSSxZQUFZLFVBQStDO1FBSDNELGtCQUFhLEdBQVksS0FBSyxDQUFDO1FBSTNCLElBQUksQ0FBQyxLQUFLLEdBQUcsVUFBVSxDQUFDLEtBQUssQ0FBQztRQUM5QixJQUFJLENBQUMsYUFBYSxHQUFHLFVBQVUsQ0FBQyxhQUFhLENBQUM7UUFDOUMsSUFBSSxDQUFDLElBQUksR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LENBQUMsQ0FBQztZQUNwQyxJQUFJLENBQUMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxDQUFDO1FBQzVCLENBQUM7UUFBQSxDQUFDO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFJTCxDQUFDO0FBOUZZLHdCQUFnQixtQkE4RjVCLENBQUE7QUFBQSxDQUFDIn0= \ No newline at end of file diff --git a/dist/smartsocket.classes.socketrole.d.ts b/dist/smartsocket.classes.socketrole.d.ts index b87dbcd..f810fb9 100644 --- a/dist/smartsocket.classes.socketrole.d.ts +++ b/dist/smartsocket.classes.socketrole.d.ts @@ -1,6 +1,5 @@ import { Objectmap } from "lik"; import { SocketFunction } from "./smartsocket.classes.socketfunction"; -export declare let allSocketRoles: Objectmap; /** * interface for class SocketRole */ diff --git a/dist/smartsocket.classes.socketrole.js b/dist/smartsocket.classes.socketrole.js index dbdc6e3..eacf188 100644 --- a/dist/smartsocket.classes.socketrole.js +++ b/dist/smartsocket.classes.socketrole.js @@ -1,7 +1,6 @@ "use strict"; // import classes const lik_1 = require("lik"); -exports.allSocketRoles = new lik_1.Objectmap(); /** * A socketrole defines access to certain routines. */ @@ -10,7 +9,6 @@ class SocketRole { this.allowedFunctions = new lik_1.Objectmap(); this.name = optionsArg.name; this.passwordHash = optionsArg.passwordHash; - exports.allSocketRoles.add(this); } ; addSocketFunction(socketFunctionArg) { @@ -18,4 +16,4 @@ class SocketRole { } } exports.SocketRole = SocketRole; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzb2NrZXQuY2xhc3Nlcy5zb2NrZXRyb2xlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFFQSxpQkFBaUI7QUFDakIsc0J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Qzs7SUFDRCxpQkFBaUIsQ0FBQyxpQkFBZ0M7UUFDOUMsSUFBSSxDQUFDLGdCQUFnQixDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsQ0FBQyxDQUFDO0lBQ2pELENBQUM7QUFDTCxDQUFDO0FBWFksa0JBQVUsYUFXdEIsQ0FBQSJ9 \ No newline at end of file diff --git a/dist/smartsocket.helpers.d.ts b/dist/smartsocket.helpers.d.ts index c6d8863..2cbbc32 100644 --- a/dist/smartsocket.helpers.d.ts +++ b/dist/smartsocket.helpers.d.ts @@ -1,8 +1,9 @@ +import { Smartsocket } from "./smartsocket.classes.smartsocket"; import { SocketFunction } from "./smartsocket.classes.socketfunction"; import { ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection"; import { SocketRequest, TSocketRequestSide } from "./smartsocket.classes.socketrequest"; import { SocketRole } from "./smartsocket.classes.socketrole"; -export declare let checkPasswordForRole: (dataArg: ISocketConnectionAuthenticationObject) => boolean; +export declare let checkPasswordForRole: (dataArg: ISocketConnectionAuthenticationObject, referenceSmartsocket: Smartsocket) => boolean; export declare let getSocketFunctionByName: (functionNameArg: string) => SocketFunction; /** * get corresponding Socketrequest instance by shortId @@ -11,4 +12,4 @@ export declare let getSocketRequestById: (shortIdArg: string, requestSide?: TSoc /** * get corresponding SocketRole instance by name */ -export declare let getSocketRoleByName: (socketRoleNameArg: string) => SocketRole; +export declare let getSocketRoleByName: (socketRoleNameArg: string, referenceSmartsocket: Smartsocket) => SocketRole; diff --git a/dist/smartsocket.helpers.js b/dist/smartsocket.helpers.js index 6d890b0..e0362db 100644 --- a/dist/smartsocket.helpers.js +++ b/dist/smartsocket.helpers.js @@ -2,10 +2,9 @@ const plugins = require("./smartsocket.plugins"); const smartsocket_classes_socketfunction_1 = require("./smartsocket.classes.socketfunction"); const smartsocket_classes_socketrequest_1 = require("./smartsocket.classes.socketrequest"); -const smartsocket_classes_socketrole_1 = require("./smartsocket.classes.socketrole"); // SocketConnection helpers -exports.checkPasswordForRole = (dataArg) => { - let targetPasswordHash = exports.getSocketRoleByName(dataArg.role).passwordHash; +exports.checkPasswordForRole = (dataArg, referenceSmartsocket) => { + let targetPasswordHash = exports.getSocketRoleByName(dataArg.role, referenceSmartsocket).passwordHash; let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password); return targetPasswordHash === computedCompareHash; }; @@ -24,7 +23,7 @@ exports.getSocketRequestById = (shortIdArg, requestSide) => { /** * get corresponding SocketRole instance by name */ -exports.getSocketRoleByName = (socketRoleNameArg) => { - return smartsocket_classes_socketrole_1.allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg; }); +exports.getSocketRoleByName = (socketRoleNameArg, referenceSmartsocket) => { + return referenceSmartsocket.socketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg; }); }; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFJakQscURBQW1ELHNDQUFzQyxDQUFDLENBQUE7QUFFMUYsb0RBQXFFLHFDQUFxQyxDQUFDLENBQUE7QUFDM0csaURBQTJDLGtDQUFrQyxDQUFDLENBQUE7QUFFOUUsMkJBQTJCO0FBQ2hCLDRCQUFvQixHQUFHLENBQUMsT0FBOEM7SUFDN0UsSUFBSSxrQkFBa0IsR0FBRywyQkFBbUIsQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUMsWUFBWSxDQUFDO0lBQ3hFLElBQUksbUJBQW1CLEdBQUcsT0FBTyxDQUFDLFFBQVEsQ0FBQyxvQkFBb0IsQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7SU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E1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLENBQUMsYUFBYSxPQUFPLE1BQU0sQ0FBQyxhQUFhLENBQUMsSUFBSSxLQUFLLGlCQUFpQixDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUE7QUFDeEgsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/package.json b/package.json index f7954e0..8087d99 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ "devDependencies": { "npmts-g": "^5.2.8", "should": "^11.1.0", - "typings-test": "^1.0.2" + "typings-test": "^1.0.3" } } diff --git a/test/test.d.ts b/test/test.d.ts index b973566..e7cc8ee 100644 --- a/test/test.d.ts +++ b/test/test.d.ts @@ -1,2 +1 @@ import "typings-test"; -import "should"; diff --git a/test/test.js b/test/test.js index dfa8a32..b74bb20 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,6 @@ "use strict"; require("typings-test"); -require("should"); +const should = require("should"); const smartsocket = require("../dist/index"); const q = require("q"); const nodehash = require("nodehash"); @@ -15,16 +15,19 @@ describe("smartsocket", function () { describe("class Smartsocket", function () { it("should create a new smartsocket", function () { testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port }); - testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket); + should(testSmartsocket).be.instanceOf(smartsocket.Smartsocket); }); it("should start listening when .started is called", function () { testSmartsocket.startServer(); }); }); describe("class SocketRole", function () { - testSocketRole1 = new smartsocket.SocketRole({ - name: "testRole1", - passwordHash: nodehash.sha256FromStringSync("testPassword") + it("should add a socketrole", function () { + testSocketRole1 = new smartsocket.SocketRole({ + name: "testRole1", + passwordHash: nodehash.sha256FromStringSync("testPassword") + }); + testSmartsocket.addSocketRoles([testSocketRole1]); }); }); describe("class SocketFunction", function () { @@ -102,4 +105,4 @@ describe("smartsocket", function () { }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIs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 No newline at end of file diff --git a/test/test.ts b/test/test.ts index 3b833be..57af7e1 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,5 +1,5 @@ import "typings-test"; -import "should"; +import should = require("should"); import socketIoClient = require("socket.io-client"); import smartsocket = require("../dist/index"); import q = require("q"); @@ -8,7 +8,7 @@ import nodehash = require("nodehash"); let testSmartsocket: smartsocket.Smartsocket; let testSmartsocketClient: smartsocket.SmartsocketClient; let testSocketRole1: smartsocket.SocketRole; -let testSocketFunction1:smartsocket.SocketFunction; +let testSocketFunction1: smartsocket.SocketFunction; let testConfig = { port: 3000 @@ -18,28 +18,31 @@ describe("smartsocket", function () { describe("class Smartsocket", function () { it("should create a new smartsocket", function () { testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port }); - testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket); + should(testSmartsocket).be.instanceOf(smartsocket.Smartsocket); }); it("should start listening when .started is called", function () { testSmartsocket.startServer(); }); }); - describe("class SocketRole", function(){ - testSocketRole1 = new smartsocket.SocketRole({ - name:"testRole1", - passwordHash:nodehash.sha256FromStringSync("testPassword") - }) + describe("class SocketRole", function () { + it("should add a socketrole", function () { + testSocketRole1 = new smartsocket.SocketRole({ + name: "testRole1", + passwordHash: nodehash.sha256FromStringSync("testPassword") + }); + testSmartsocket.addSocketRoles([testSocketRole1]); + }); }) describe("class SocketFunction", function () { it("should register a new Function", function () { testSocketFunction1 = new smartsocket.SocketFunction({ - funcName:"testFunction1", + funcName: "testFunction1", funcDef: (dataArg) => { let done = q.defer(); done.resolve(dataArg); return done.promise; }, - allowedRoles:[testSocketRole1] + allowedRoles: [testSocketRole1] }); }); }); @@ -76,25 +79,25 @@ describe("smartsocket", function () { it("2 clients should connect in parallel", function () { }); - it("should be able to make a functionCall from client to server",function(done){ + it("should be able to make a functionCall from client to server", function (done) { this.timeout(5000); - testSmartsocketClient.serverCall("testFunction1",{ - value1:"hello" + testSmartsocketClient.serverCall("testFunction1", { + value1: "hello" }).then((dataArg) => { console.log(dataArg); done(); }); }); - it("should be able to make a functionCall from server to client",function(done){ + it("should be able to make a functionCall from server to client", function (done) { this.timeout(5000); let targetSocket = (() => { - return smartsocket.allSocketConnections.find((socketConnectionArg)=>{ + return smartsocket.allSocketConnections.find((socketConnectionArg) => { return socketConnectionArg.alias === "testClient1"; }); })(); - testSmartsocket.clientCall("testFunction1",{ - value1:"helloFromServer" - },targetSocket).then((dataArg) => { + testSmartsocket.clientCall("testFunction1", { + value1: "helloFromServer" + }, targetSocket).then((dataArg) => { console.log(dataArg); done(); }); diff --git a/ts/smartsocket.classes.smartsocket.ts b/ts/smartsocket.classes.smartsocket.ts index 5769d01..8254a2b 100644 --- a/ts/smartsocket.classes.smartsocket.ts +++ b/ts/smartsocket.classes.smartsocket.ts @@ -16,6 +16,7 @@ export class Smartsocket { options: ISmartsocketConstructorOptions io: SocketIO.Server; openSockets = new Objectmap(); + socketRoles = new Objectmap(); constructor(optionsArg: ISmartsocketConstructorOptions) { this.options = optionsArg; }; @@ -29,6 +30,7 @@ export class Smartsocket { authenticated:false, role:undefined, side:"server", + smartsocketHost: this, socket:socketArg }); plugins.beautylog.log("Socket connected. Trying to authenticate...") @@ -81,5 +83,16 @@ export class Smartsocket { done.resolve(dataArg.funcDataArg); }); return done.promise; - } + }; + + /** + * adds socketRoles + */ + addSocketRoles(socketRolesArray:SocketRole[]):void{ + for(let socketRole of socketRolesArray){ + this.socketRoles.add(socketRole); + }; + return; + }; + } \ No newline at end of file diff --git a/ts/smartsocket.classes.smartsocketclient.ts b/ts/smartsocket.classes.smartsocketclient.ts index 0c941bf..76d6cb7 100644 --- a/ts/smartsocket.classes.smartsocketclient.ts +++ b/ts/smartsocket.classes.smartsocketclient.ts @@ -47,6 +47,7 @@ export class SmartsocketClient { authenticated:false, role:undefined, side:"client", + smartsocketHost: null, socket: plugins.socketIoClient(socketUrl,{multiplex:false}) }); this.socketConnection.socket.on("requestAuth", () => { diff --git a/ts/smartsocket.classes.socketconnection.ts b/ts/smartsocket.classes.socketconnection.ts index f5789ea..8581a89 100644 --- a/ts/smartsocket.classes.socketconnection.ts +++ b/ts/smartsocket.classes.socketconnection.ts @@ -4,6 +4,7 @@ import * as helpers from "./smartsocket.helpers"; import {Objectmap} from "lik"; // import classes +import { Smartsocket } from "./smartsocket.classes.smartsocket" import { SocketFunction } from "./smartsocket.classes.socketfunction"; import { SocketRequest, ISocketRequestDataObject, allSocketRequests } from "./smartsocket.classes.socketrequest"; import { SocketRole } from "./smartsocket.classes.socketrole"; @@ -23,6 +24,7 @@ export interface ISocketConnectionConstructorOptions { authenticated: boolean; role: SocketRole; side: TSocketConnectionSide; + smartsocketHost: Smartsocket; socket: SocketIO.Socket | SocketIOClient.Socket; }; @@ -46,12 +48,14 @@ export class SocketConnection { side:TSocketConnectionSide; authenticated: boolean = false; role: SocketRole; + smartsocketHost:Smartsocket; socket: SocketIO.Socket | SocketIOClient.Socket; constructor(optionsArg: ISocketConnectionConstructorOptions) { this.alias = optionsArg.alias; this.authenticated = optionsArg.authenticated; this.role = optionsArg.role; this.side = optionsArg.side; + this.smartsocketHost = optionsArg.smartsocketHost; this.socket = optionsArg.socket; // standard behaviour that is always true @@ -72,10 +76,10 @@ export class SocketConnection { this.socket.on("dataAuth", (dataArg:ISocketConnectionAuthenticationObject) => { plugins.beautylog.log("received authentication data. now hashing and comparing..."); this.socket.removeListener("dataAuth", () => { }); - if (helpers.checkPasswordForRole(dataArg)) { // TODO: authenticate password + if (helpers.checkPasswordForRole(dataArg,this.smartsocketHost)) { // TODO: authenticate password this.alias = dataArg.alias this.authenticated = true; - this.role = helpers.getSocketRoleByName(dataArg.role); + this.role = helpers.getSocketRoleByName(dataArg.role,this.smartsocketHost); this.socket.emit("authenticated"); plugins.beautylog.ok(`socket with >>alias ${this.alias} >>role ${this.role} is authenticated!`); done.resolve(this); diff --git a/ts/smartsocket.classes.socketrole.ts b/ts/smartsocket.classes.socketrole.ts index 442ba03..0fb1f4b 100644 --- a/ts/smartsocket.classes.socketrole.ts +++ b/ts/smartsocket.classes.socketrole.ts @@ -5,9 +5,6 @@ import { Objectmap } from "lik"; import { SocketFunction } from "./smartsocket.classes.socketfunction"; -export let allSocketRoles = new Objectmap(); - - /** * interface for class SocketRole */ @@ -26,7 +23,6 @@ export class SocketRole { constructor(optionsArg: SocketRoleOptions) { this.name = optionsArg.name; this.passwordHash = optionsArg.passwordHash; - allSocketRoles.add(this); }; addSocketFunction(socketFunctionArg:SocketFunction){ this.allowedFunctions.add(socketFunctionArg); diff --git a/ts/smartsocket.helpers.ts b/ts/smartsocket.helpers.ts index 1825d18..6557454 100644 --- a/ts/smartsocket.helpers.ts +++ b/ts/smartsocket.helpers.ts @@ -5,11 +5,11 @@ import { Smartsocket } from "./smartsocket.classes.smartsocket"; import { SocketFunction, allSocketFunctions } from "./smartsocket.classes.socketfunction"; import { SocketConnection, ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection"; import { SocketRequest, allSocketRequests, TSocketRequestSide } from "./smartsocket.classes.socketrequest"; -import { SocketRole, allSocketRoles } from "./smartsocket.classes.socketrole"; +import { SocketRole } from "./smartsocket.classes.socketrole"; // SocketConnection helpers -export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject): boolean => { - let targetPasswordHash = getSocketRoleByName(dataArg.role).passwordHash; +export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject, referenceSmartsocket:Smartsocket): boolean => { + let targetPasswordHash = getSocketRoleByName(dataArg.role,referenceSmartsocket).passwordHash; let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password); return targetPasswordHash === computedCompareHash; } @@ -34,7 +34,7 @@ export let getSocketRequestById = (shortIdArg: string, requestSide?: TSocketRequ /** * get corresponding SocketRole instance by name */ -export let getSocketRoleByName = (socketRoleNameArg: string): SocketRole => { - return allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg }) +export let getSocketRoleByName = (socketRoleNameArg: string,referenceSmartsocket:Smartsocket): SocketRole => { + return referenceSmartsocket.socketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg }) };