From bb94b1c405e47ef958a19c2ad285dae6db4f756a Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 5 Mar 2020 18:48:39 +0100 Subject: [PATCH] fix sesamefilter default --- package.json | 2 +- src/Backend.ts | 9 +++++++-- test/Test.ts | 49 ++++++++++++------------------------------------- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 971767b..df1c49f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rpclibrary", - "version": "1.9.1", + "version": "1.9.2", "description": "rpclibrary is a websocket on steroids!", "main": "./js/Index.js", "repository": { diff --git a/src/Backend.ts b/src/Backend.ts index b707258..6a68842 100644 --- a/src/Backend.ts +++ b/src/Backend.ts @@ -38,14 +38,19 @@ export class RPCServer< private exporters: Exporters = [], conf: T.ServerConf = {} ){ - if(!conf.visibility) this.visibility = "127.0.0.1" + if(!conf.visibility) this.visibility = "0.0.0.0" - this.accessFilter = conf.accessFilter || (async () => true) if(conf.sesame){ this.sesame = U.makeSesameFunction(conf.sesame) } + this.accessFilter = conf.accessFilter || (async (sesame) => { + if(!this.sesame) return true + return this.sesame!(sesame!) + }) + + this.errorHandler = (socket:I.Socket) => (error:any, rpcName:string, args: any[]) => { if(conf.errorHandler) conf.errorHandler(socket, error, rpcName, args) else throw error diff --git a/test/Test.ts b/test/Test.ts index c51984c..0a201fd 100644 --- a/test/Test.ts +++ b/test/Test.ts @@ -316,30 +316,26 @@ describe('Sesame should unlock the socket', () => { it('should not work without sesame', (done) => { const sock = new RPCSocket(21004, "localhost") sock.connect( /* no sesame */).then(async (cli) => { - cli.test.checkCandy().then(d => { - done(d) - }).catch(e => { - //console.log("EXPECTED CLIENT EXCEPTION", String(e)); + if(!cli.test) done() - }).finally(() => { - cli.destroy() - sock.destroy() - }) + else{ + done(new Error("Function supposed to be removed without sesame")) + } + cli.destroy() + sock.destroy() }) }) it('should fail with wrong sesame', (done) => { const sock = new RPCSocket(21004, "localhost") sock.connect('abasd').then(async (cli) => { - cli.test.checkCandy().then(d => { - done("should not be able to get candy") - }).catch(e => { - //console.log("EXPECTED CLIENT EXCEPTION", String(e)); + if(!cli.test) done() - }).finally(() => { - sock.destroy() - cli.destroy() - }) + else{ + done(new Error("Function supposed to be removed without sesame")) + } + cli.destroy() + sock.destroy() }) }) @@ -355,27 +351,6 @@ describe('Sesame should unlock the socket', () => { client.test.checkCandy() }) }) - - it('callback should not work without sesame', (done) => { - const sock = new RPCSocket(21004, "localhost") - sock.connect( /* no sesame */).then(async (cli) => { - cli.test.subscribe((c) => { - console.log("CALLBACK TRIGGERED UNEXPECTED"); - - if(c === candy) - done("super not") - }).then(async d => { - await client.test.checkCandy() - if(d == null){ - done() - - }else - done('unexpected valid response '+(d) ) - }).finally(() => { - sock.destroy() - }) - }) - }) })