sesame function
This commit is contained in:
@@ -223,4 +223,47 @@ describe('It should do unhook', () => {
|
||||
done(new Error("Results did not match: "+[r1,r2,r3,r4]))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
type SesameTestIfc = { test: { checkCandy: ()=>Promise<string>} }
|
||||
|
||||
describe('Sesame should unlock the socket', () => {
|
||||
let candy = "OK"
|
||||
let client: RPCSocket & SesameTestIfc
|
||||
let server: RPCServer<{topic: string}, SesameTestIfc>
|
||||
|
||||
before(async() => {
|
||||
server = new RPCServer<{ topic: string }, SesameTestIfc>(20004, [{
|
||||
name: "test",
|
||||
exportRPCs: () => [
|
||||
async function checkCandy():Promise<string> { return candy },
|
||||
]}
|
||||
],{
|
||||
sesame: (_sesame) => _sesame === 'sesame!'
|
||||
})
|
||||
const sock = new RPCSocket(20004, "localhost")
|
||||
client = await sock.connect<SesameTestIfc>('sesame!')
|
||||
})
|
||||
|
||||
after(() => {
|
||||
client.destroy()
|
||||
server.destroy()
|
||||
})
|
||||
|
||||
it('should not work without sesame', (done) => {
|
||||
const sock = new RPCSocket(20004, "localhost")
|
||||
sock.connect<SesameTestIfc>( /* no sesame */).then(async (c) => {
|
||||
c.test.checkCandy().then(d => {
|
||||
if(d === candy)
|
||||
done("should not be able to get candy")
|
||||
done()
|
||||
}).finally(() => {
|
||||
sock.destroy()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('should work with sesame', (done) => {
|
||||
client.test.checkCandy().then(c => done())
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user