Browse Source

fix sesamefilter default

master
peter 4 years ago
parent
commit
bb94b1c405
3 changed files with 20 additions and 40 deletions
  1. 1
    1
      package.json
  2. 7
    2
      src/Backend.ts
  3. 12
    37
      test/Test.ts

+ 1
- 1
package.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "rpclibrary",
3
-  "version": "1.9.1",
3
+  "version": "1.9.2",
4 4
   "description": "rpclibrary is a websocket on steroids!",
5 5
   "main": "./js/Index.js",
6 6
   "repository": {

+ 7
- 2
src/Backend.ts View File

@@ -38,14 +38,19 @@ export class RPCServer<
38 38
         private exporters: Exporters<InterfaceT, SubResType> = [],
39 39
         conf: T.ServerConf<InterfaceT, SubResType> =  {}
40 40
     ){
41
-        if(!conf.visibility) this.visibility = "127.0.0.1"        
41
+        if(!conf.visibility) this.visibility = "0.0.0.0"        
42 42
         
43
-        this.accessFilter = conf.accessFilter || (async () => true)
44 43
 
45 44
         if(conf.sesame){
46 45
             this.sesame = U.makeSesameFunction(conf.sesame)
47 46
         }
48 47
 
48
+        this.accessFilter = conf.accessFilter || (async (sesame) => {
49
+            if(!this.sesame) return true
50
+            return this.sesame!(sesame!)
51
+        })
52
+
53
+
49 54
         this.errorHandler = (socket:I.Socket) => (error:any, rpcName:string, args: any[]) => { 
50 55
             if(conf.errorHandler) conf.errorHandler(socket, error, rpcName, args)
51 56
             else throw error

+ 12
- 37
test/Test.ts View File

@@ -316,30 +316,26 @@ describe('Sesame should unlock the socket', () => {
316 316
     it('should not work without sesame', (done) => {
317 317
         const sock = new RPCSocket(21004, "localhost")
318 318
         sock.connect<SesameTestIfc>( /* no sesame */).then(async (cli) => {
319
-            cli.test.checkCandy().then(d => {
320
-                done(d)
321
-            }).catch(e => {
322
-                //console.log("EXPECTED CLIENT EXCEPTION", String(e));
319
+            if(!cli.test) 
323 320
                 done()
324
-            }).finally(() => {
325
-                cli.destroy()
326
-                sock.destroy()
327
-            })
321
+            else{
322
+                done(new Error("Function supposed to be removed without sesame"))
323
+            }
324
+            cli.destroy()
325
+            sock.destroy()
328 326
         })
329 327
     })
330 328
 
331 329
     it('should fail with wrong sesame', (done) => {
332 330
         const sock = new RPCSocket(21004, "localhost")
333 331
         sock.connect<SesameTestIfc>('abasd').then(async (cli) => {
334
-            cli.test.checkCandy().then(d => {
335
-                done("should not be able to get candy")
336
-            }).catch(e => {
337
-                //console.log("EXPECTED CLIENT EXCEPTION", String(e));
332
+            if(!cli.test) 
338 333
                 done()
339
-            }).finally(() => {
340
-                sock.destroy()
341
-                cli.destroy()
342
-            })
334
+            else{
335
+                done(new Error("Function supposed to be removed without sesame"))
336
+            }
337
+            cli.destroy()
338
+            sock.destroy()
343 339
         })
344 340
     })
345 341
 
@@ -355,27 +351,6 @@ describe('Sesame should unlock the socket', () => {
355 351
             client.test.checkCandy()
356 352
         })
357 353
     })
358
-
359
-    it('callback should not work without sesame', (done) => {
360
-        const sock = new RPCSocket(21004, "localhost")
361
-        sock.connect<SesameTestIfc>( /* no sesame */).then(async (cli) => {
362
-            cli.test.subscribe((c) => {
363
-                console.log("CALLBACK TRIGGERED UNEXPECTED");
364
-                
365
-                if(c === candy)
366
-                    done("super not")
367
-            }).then(async d => {
368
-                await client.test.checkCandy()
369
-                if(d == null){
370
-                    done()
371
-
372
-                }else
373
-                    done('unexpected valid response '+(d) )
374
-            }).finally(() => {
375
-                sock.destroy()
376
-            })
377
-        })
378
-    })
379 354
 })
380 355
 
381 356
 

Loading…
Cancel
Save