1 |
|
2 |
|
3 | var tape = require('tape')
|
4 | var mux = require('../')
|
5 | var pull = require('pull-stream')
|
6 | var pair = require('pull-pair')
|
7 |
|
8 | function createClient (t) {
|
9 |
|
10 | var client = {
|
11 | get : 'async',
|
12 | read : 'source',
|
13 | write : 'sink',
|
14 | echo : 'duplex'
|
15 | }
|
16 |
|
17 | var A = mux(client, null) ()
|
18 |
|
19 | var B = mux(null, {}) ({
|
20 | get: function (a, cb) {
|
21 |
|
22 | t.ok(false, 'attacker got in')
|
23 | cb(null, "ACCESS GRANTED")
|
24 | },
|
25 | read: function () {
|
26 | t.ok(false, 'attacker got in')
|
27 | return pull.values(['ACCESS', 'GRANTED'])
|
28 | },
|
29 | write: function () {
|
30 | t.ok(false, 'attacker got in')
|
31 | return pull.drain()
|
32 | },
|
33 | echo: function () {
|
34 | t.ok(false, 'attacker got in')
|
35 | return pair()
|
36 | }
|
37 | })
|
38 |
|
39 | var s = A.createStream()
|
40 | pull(s, pull.through(console.log), B.createStream(), pull.through(console.log), s)
|
41 |
|
42 | return A
|
43 | }
|
44 |
|
45 | tape('request which is not public', function (t) {
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | A = createClient(t)
|
51 |
|
52 | A.get('foo', function (err, val) {
|
53 | t.ok(err)
|
54 | t.notEqual(val, "ACCESS GRANTED")
|
55 | t.end()
|
56 | })
|
57 |
|
58 | })
|
59 |
|
60 | tape('sink which is not public', function (t) {
|
61 |
|
62 |
|
63 | var A = createClient(t)
|
64 |
|
65 | pull(
|
66 | pull.values(["ACCESS", "GRANTED"]),
|
67 | A.write(null, function (err, ary) {
|
68 | t.ok(err)
|
69 | t.end()
|
70 | })
|
71 | )
|
72 | })
|
73 |
|
74 | tape('source which is not public', function (t) {
|
75 |
|
76 |
|
77 | var A = createClient(t)
|
78 |
|
79 | pull(
|
80 | A.read(),
|
81 | pull.collect(function (err, ary) {
|
82 | t.ok(err)
|
83 | t.notDeepEqual(ary, ["ACCESS", "GRANTED"])
|
84 | t.end()
|
85 | })
|
86 | )
|
87 | })
|
88 |
|
89 | tape('duplex which is not public', function (t) {
|
90 |
|
91 |
|
92 | var A = createClient(t)
|
93 |
|
94 | pull(
|
95 | A.read(),
|
96 | pull.collect(function (err, ary) {
|
97 | t.ok(err)
|
98 | t.notDeepEqual(ary, ["ACCESS", "GRANTED"])
|
99 | t.end()
|
100 | })
|
101 | )
|
102 | })
|
103 |
|
104 | tape('client and server manifest have different types', function (t) {
|
105 | var clientM = { foo: 'async' }
|
106 | var serverM = { foo: 'source' }
|
107 |
|
108 | var A = mux(clientM, null) ()
|
109 | var B = mux(null, serverM) ()
|
110 |
|
111 | var as = A.createStream()
|
112 | pull(as, B.createStream(), as)
|
113 |
|
114 | A.foo(function (err) {
|
115 | console.log(err)
|
116 | t.ok(err)
|
117 | t.end()
|
118 | })
|
119 | })
|