UNPKG

2.38 kBJavaScriptView Raw
1
2
3var tape = require('tape')
4var mux = require('../')
5var pull = require('pull-stream')
6var pair = require('pull-pair')
7
8function 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 //root access!! this should never happen!
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
45tape('request which is not public', function (t) {
46
47 //create a client with a different manifest to the server.
48 //create a server that
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
60tape('sink which is not public', function (t) {
61
62 //create a client with a different manifest to the server.
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
74tape('source which is not public', function (t) {
75
76 //create a client with a different manifest to the server.
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
89tape('duplex which is not public', function (t) {
90
91 //create a client with a different manifest to the server.
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
104tape('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})