fix sesamefilter default
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rpclibrary",
|
"name": "rpclibrary",
|
||||||
"version": "1.9.1",
|
"version": "1.9.2",
|
||||||
"description": "rpclibrary is a websocket on steroids!",
|
"description": "rpclibrary is a websocket on steroids!",
|
||||||
"main": "./js/Index.js",
|
"main": "./js/Index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
+7
-2
@@ -38,14 +38,19 @@ export class RPCServer<
|
|||||||
private exporters: Exporters<InterfaceT, SubResType> = [],
|
private exporters: Exporters<InterfaceT, SubResType> = [],
|
||||||
conf: T.ServerConf<InterfaceT, SubResType> = {}
|
conf: T.ServerConf<InterfaceT, SubResType> = {}
|
||||||
){
|
){
|
||||||
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){
|
if(conf.sesame){
|
||||||
this.sesame = U.makeSesameFunction(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[]) => {
|
this.errorHandler = (socket:I.Socket) => (error:any, rpcName:string, args: any[]) => {
|
||||||
if(conf.errorHandler) conf.errorHandler(socket, error, rpcName, args)
|
if(conf.errorHandler) conf.errorHandler(socket, error, rpcName, args)
|
||||||
else throw error
|
else throw error
|
||||||
|
|||||||
+12
-37
@@ -316,30 +316,26 @@ describe('Sesame should unlock the socket', () => {
|
|||||||
it('should not work without sesame', (done) => {
|
it('should not work without sesame', (done) => {
|
||||||
const sock = new RPCSocket(21004, "localhost")
|
const sock = new RPCSocket(21004, "localhost")
|
||||||
sock.connect<SesameTestIfc>( /* no sesame */).then(async (cli) => {
|
sock.connect<SesameTestIfc>( /* no sesame */).then(async (cli) => {
|
||||||
cli.test.checkCandy().then(d => {
|
if(!cli.test)
|
||||||
done(d)
|
|
||||||
}).catch(e => {
|
|
||||||
//console.log("EXPECTED CLIENT EXCEPTION", String(e));
|
|
||||||
done()
|
done()
|
||||||
}).finally(() => {
|
else{
|
||||||
cli.destroy()
|
done(new Error("Function supposed to be removed without sesame"))
|
||||||
sock.destroy()
|
}
|
||||||
})
|
cli.destroy()
|
||||||
|
sock.destroy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should fail with wrong sesame', (done) => {
|
it('should fail with wrong sesame', (done) => {
|
||||||
const sock = new RPCSocket(21004, "localhost")
|
const sock = new RPCSocket(21004, "localhost")
|
||||||
sock.connect<SesameTestIfc>('abasd').then(async (cli) => {
|
sock.connect<SesameTestIfc>('abasd').then(async (cli) => {
|
||||||
cli.test.checkCandy().then(d => {
|
if(!cli.test)
|
||||||
done("should not be able to get candy")
|
|
||||||
}).catch(e => {
|
|
||||||
//console.log("EXPECTED CLIENT EXCEPTION", String(e));
|
|
||||||
done()
|
done()
|
||||||
}).finally(() => {
|
else{
|
||||||
sock.destroy()
|
done(new Error("Function supposed to be removed without sesame"))
|
||||||
cli.destroy()
|
}
|
||||||
})
|
cli.destroy()
|
||||||
|
sock.destroy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -355,27 +351,6 @@ describe('Sesame should unlock the socket', () => {
|
|||||||
client.test.checkCandy()
|
client.test.checkCandy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('callback should not work without sesame', (done) => {
|
|
||||||
const sock = new RPCSocket(21004, "localhost")
|
|
||||||
sock.connect<SesameTestIfc>( /* 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()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user