fix(core): update
This commit is contained in:
parent
6fdf0d9955
commit
489ad9284b
@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
@ -36,6 +39,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartsocket",
|
"gitrepo": "smartsocket",
|
||||||
"shortDescription": "easy and secure websocket communication",
|
"description": "easy and secure websocket communication",
|
||||||
"npmPackagename": "@pushrocks/smartsocket",
|
"npmPackagename": "@pushrocks/smartsocket",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
|
24
test/test.ts
24
test/test.ts
@ -105,12 +105,13 @@ tap.test('should be able to tag a connection from client', async (tools) => {
|
|||||||
|
|
||||||
tap.test('should be able to tag a connection from server', async (tools) => {
|
tap.test('should be able to tag a connection from server', async (tools) => {
|
||||||
await testSmartsocket.socketConnections
|
await testSmartsocket.socketConnections
|
||||||
.findSync((socketConnection) => {
|
.findSync((socketConnection) => {
|
||||||
return true;
|
return true;
|
||||||
}).addTag({
|
})
|
||||||
id: 'awesome2',
|
.addTag({
|
||||||
payload: 'absolutely',
|
id: 'awesome2',
|
||||||
});
|
payload: 'absolutely',
|
||||||
|
});
|
||||||
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
const tagOnClientSide = await testSmartsocketClient.socketConnection.getTagById('awesome2');
|
||||||
expect(tagOnClientSide.payload).to.equal('absolutely');
|
expect(tagOnClientSide.payload).to.equal('absolutely');
|
||||||
});
|
});
|
||||||
@ -143,10 +144,19 @@ tap.test('should be able to make a functionCall from server to client', async ()
|
|||||||
|
|
||||||
tap.test('client should disconnect and reconnect', async (tools) => {
|
tap.test('client should disconnect and reconnect', async (tools) => {
|
||||||
await testSmartsocketClient.disconnect();
|
await testSmartsocketClient.disconnect();
|
||||||
await tools.delayFor(100);
|
|
||||||
await testSmartsocketClient.connect();
|
await testSmartsocketClient.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should be able to locate a connection tag after reconnect', async (tools) => {
|
||||||
|
console.log(testSmartsocket.socketConnections.getArray().length);
|
||||||
|
const tagOnServerSide = await testSmartsocket.socketConnections
|
||||||
|
.findSync((socketConnection) => {
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.getTagById('awesome');
|
||||||
|
expect(tagOnServerSide.payload).to.equal('yes');
|
||||||
|
});
|
||||||
|
|
||||||
// terminate
|
// terminate
|
||||||
tap.test('should close the server', async () => {
|
tap.test('should close the server', async () => {
|
||||||
await testSmartsocket.stop();
|
await testSmartsocket.stop();
|
||||||
|
@ -61,8 +61,8 @@ export class Smartsocket {
|
|||||||
await plugins.smartdelay.delayFor(1000);
|
await plugins.smartdelay.delayFor(1000);
|
||||||
this.socketConnections.forEach((socketObjectArg: SocketConnection) => {
|
this.socketConnections.forEach((socketObjectArg: SocketConnection) => {
|
||||||
if (socketObjectArg) {
|
if (socketObjectArg) {
|
||||||
logger.log('info', `disconnect socket with >>alias ${socketObjectArg.alias}`);
|
logger.log('info', `disconnecting socket with >>alias ${socketObjectArg.alias} due to server stop...`);
|
||||||
socketObjectArg.socket.disconnect(true);
|
socketObjectArg.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.socketConnections.wipe();
|
this.socketConnections.wipe();
|
||||||
@ -124,13 +124,14 @@ export class Smartsocket {
|
|||||||
});
|
});
|
||||||
logger.log('info', 'Socket connected. Trying to authenticate...');
|
logger.log('info', 'Socket connected. Trying to authenticate...');
|
||||||
this.socketConnections.add(socketConnection);
|
this.socketConnections.add(socketConnection);
|
||||||
const disconnectSubscription = socketConnection.eventSubject.subscribe((eventArg) => {
|
const disconnectSubscription = socketConnection.eventSubject.subscribe((eventArg) => {
|
||||||
if (eventArg === 'disconnected') {
|
if (eventArg === 'disconnected') {
|
||||||
this.socketConnections.remove(socketConnection);
|
this.socketConnections.remove(socketConnection);
|
||||||
disconnectSubscription.unsubscribe();
|
disconnectSubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
await socketConnection.authenticate();
|
await socketConnection.authenticate();
|
||||||
await socketConnection.listenToFunctionRequests();
|
await socketConnection.listenToFunctionRequests();
|
||||||
|
await socketConnection.socket.emit('serverFullyReactive');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,11 +138,29 @@ export class SmartsocketClient {
|
|||||||
logger.log('info', 'server requested authentication');
|
logger.log('info', 'server requested authentication');
|
||||||
|
|
||||||
// lets register the authenticated event
|
// lets register the authenticated event
|
||||||
this.socketConnection.socket.on('authenticated', () => {
|
this.socketConnection.socket.on('authenticated', async () => {
|
||||||
this.remoteShortId = requestAuthPayload.serverShortId;
|
this.remoteShortId = requestAuthPayload.serverShortId;
|
||||||
logger.log('info', 'client is authenticated');
|
logger.log('info', 'client is authenticated');
|
||||||
this.socketConnection.authenticated = true;
|
this.socketConnection.authenticated = true;
|
||||||
this.socketConnection.listenToFunctionRequests();
|
await this.socketConnection.listenToFunctionRequests();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.socketConnection.socket.on('serverFullyReactive', async () => {
|
||||||
|
// lets take care of retagging
|
||||||
|
const oldTagStore = this.tagStore;
|
||||||
|
this.tagStoreSubscription?.unsubscribe();
|
||||||
|
for (const keyArg of Object.keys(this.tagStore)) {
|
||||||
|
this.socketConnection.addTag(this.tagStore[keyArg]);
|
||||||
|
}
|
||||||
|
this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(
|
||||||
|
(tagStoreArg) => {
|
||||||
|
this.tagStore = tagStoreArg;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const tag of Object.keys(oldTagStore)) {
|
||||||
|
await this.addTag(oldTagStore[tag]);
|
||||||
|
}
|
||||||
done.resolve();
|
done.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -163,16 +181,6 @@ export class SmartsocketClient {
|
|||||||
|
|
||||||
// handle connection
|
// handle connection
|
||||||
this.socketConnection.socket.on('connect', async () => {
|
this.socketConnection.socket.on('connect', async () => {
|
||||||
this.tagStoreSubscription?.unsubscribe();
|
|
||||||
for (const keyArg of Object.keys(this.tagStore)) {
|
|
||||||
this.socketConnection.addTag(this.tagStore[keyArg]);
|
|
||||||
}
|
|
||||||
this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(
|
|
||||||
(tagStoreArg) => {
|
|
||||||
this.tagStore = tagStoreArg;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.updateStatus('connected');
|
this.updateStatus('connected');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -194,6 +202,7 @@ export class SmartsocketClient {
|
|||||||
* disconnect from the server
|
* disconnect from the server
|
||||||
*/
|
*/
|
||||||
public async disconnect() {
|
public async disconnect() {
|
||||||
|
this.tagStoreSubscription?.unsubscribe();
|
||||||
if (this.socketConnection) {
|
if (this.socketConnection) {
|
||||||
await this.socketConnection.disconnect();
|
await this.socketConnection.disconnect();
|
||||||
this.socketConnection = undefined;
|
this.socketConnection = undefined;
|
||||||
|
@ -95,6 +95,9 @@ export class SocketConnection {
|
|||||||
this.tagStore[tagArg.id] = tagArg;
|
this.tagStore[tagArg.id] = tagArg;
|
||||||
this.tagStoreObservable.next(this.tagStore);
|
this.tagStoreObservable.next(this.tagStore);
|
||||||
const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => {
|
const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => {
|
||||||
|
if (!remoteTagStore[tagArg.id]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const localTagString = plugins.smartjson.stringify(tagArg);
|
const localTagString = plugins.smartjson.stringify(tagArg);
|
||||||
const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]);
|
const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]);
|
||||||
if (localTagString === remoteTagString) {
|
if (localTagString === remoteTagString) {
|
||||||
|
@ -32,8 +32,10 @@ export class SocketRole {
|
|||||||
dataArg: ISocketConnectionAuthenticationObject,
|
dataArg: ISocketConnectionAuthenticationObject,
|
||||||
referenceSmartsocket: Smartsocket | SmartsocketClient
|
referenceSmartsocket: Smartsocket | SmartsocketClient
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const targetPasswordHash = SocketRole.getSocketRoleByName(referenceSmartsocket, dataArg.role)
|
const targetPasswordHash = SocketRole.getSocketRoleByName(
|
||||||
.passwordHash;
|
referenceSmartsocket,
|
||||||
|
dataArg.role
|
||||||
|
).passwordHash;
|
||||||
const computedCompareHash = await plugins.isohash.sha256FromString(dataArg.password);
|
const computedCompareHash = await plugins.isohash.sha256FromString(dataArg.password);
|
||||||
return targetPasswordHash === computedCompareHash;
|
return targetPasswordHash === computedCompareHash;
|
||||||
}
|
}
|
||||||
|
@ -77,5 +77,9 @@ export class SocketServer {
|
|||||||
/**
|
/**
|
||||||
* closes the server
|
* closes the server
|
||||||
*/
|
*/
|
||||||
public async stop() {}
|
public async stop() {
|
||||||
|
if (this.httpServer) {
|
||||||
|
this.httpServer.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user