AllJS basically works
need to cleanup the assertion and shutdown but ping through the tunnel works
This commit is contained in:
parent
085aad6366
commit
20ed882f33
|
@ -3,6 +3,7 @@ package nodejs_test
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
|
@ -17,6 +18,57 @@ import (
|
|||
"go.cryptoscope.co/secretstream"
|
||||
)
|
||||
|
||||
// all js end-to-end test as a sanity check
|
||||
func TestAllJSEndToEnd(t *testing.T) {
|
||||
// defer leakcheck.Check(t)
|
||||
r := require.New(t)
|
||||
|
||||
ts := newRandomSession(t)
|
||||
// ts := newSession(t, nil)
|
||||
|
||||
// alice is the server now
|
||||
alice, port := ts.startJSBotAsServer("alice", "./testscripts/server.js")
|
||||
|
||||
aliceAddr := &net.TCPAddr{
|
||||
IP: net.ParseIP("127.0.0.1"),
|
||||
Port: port,
|
||||
}
|
||||
|
||||
bob := ts.startJSClient("bob", "./testscripts/simple_client.js",
|
||||
aliceAddr,
|
||||
*alice,
|
||||
)
|
||||
|
||||
// claire wants to connect to bob through alice
|
||||
|
||||
// nasty multiserver-addr hack
|
||||
var roomHandle bytes.Buffer
|
||||
roomHandle.WriteString("tunnel:")
|
||||
roomHandle.WriteString(alice.Ref())
|
||||
roomHandle.WriteString(":")
|
||||
roomHandle.WriteString(bob.Ref())
|
||||
roomHandle.WriteString("~shs:")
|
||||
roomHandle.WriteString(base64.StdEncoding.EncodeToString(bob.ID))
|
||||
|
||||
// write the handle to the testrun folder of the bot
|
||||
handleFile := filepath.Join("testrun", t.Name(), "claire", "endpoint_through_room.txt")
|
||||
os.MkdirAll(filepath.Dir(handleFile), 0700)
|
||||
err := ioutil.WriteFile(handleFile, roomHandle.Bytes(), 0700)
|
||||
r.NoError(err)
|
||||
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
|
||||
claire := ts.startJSClient("claire", "./testscripts/simple_client_opening_tunnel.js",
|
||||
aliceAddr,
|
||||
*alice,
|
||||
)
|
||||
t.Log("this is claire:", claire.Ref())
|
||||
|
||||
time.Sleep(20 * time.Second)
|
||||
|
||||
ts.wait()
|
||||
}
|
||||
|
||||
func TestJSClient(t *testing.T) {
|
||||
// defer leakcheck.Check(t)
|
||||
r := require.New(t)
|
||||
|
@ -37,9 +89,8 @@ func TestJSClient(t *testing.T) {
|
|||
roomHandle.WriteString(srv.Whoami().Ref())
|
||||
roomHandle.WriteString(":")
|
||||
roomHandle.WriteString(alice.Ref())
|
||||
// nasty tunnel~shs: hack
|
||||
// roomHandle.WriteString("~shs:")
|
||||
// roomHandle.WriteString(base64.StdEncoding.EncodeToString(srv.Whoami().ID))
|
||||
roomHandle.WriteString("~shs:")
|
||||
roomHandle.WriteString(base64.StdEncoding.EncodeToString(alice.ID))
|
||||
|
||||
// write the handle to the testrun folder of the bot
|
||||
handleFile := filepath.Join("testrun", t.Name(), "bob", "endpoint_through_room.txt")
|
||||
|
@ -88,9 +139,8 @@ func TestJSServer(t *testing.T) {
|
|||
roomHandle.WriteString(alice.Ref())
|
||||
roomHandle.WriteString(":")
|
||||
roomHandle.WriteString(client.Whoami().Ref())
|
||||
// nasty tunnel~shs: hack
|
||||
// roomHandle.WriteString("~shs:")
|
||||
// roomHandle.WriteString(base64.StdEncoding.EncodeToString(alice.ID))
|
||||
roomHandle.WriteString("~shs:")
|
||||
roomHandle.WriteString(base64.StdEncoding.EncodeToString(client.Whoami().ID))
|
||||
|
||||
// write the handle to the testrun folder of the bot
|
||||
handleFile := filepath.Join("testrun", t.Name(), "bob", "endpoint_through_room.txt")
|
||||
|
|
|
@ -13,8 +13,6 @@ if (testSHSappKey !== false) {
|
|||
|
||||
const createSbot = theStack({caps: {shs: testAppkey } })
|
||||
.use(require('ssb-db'))
|
||||
.use(require('ssb-gossip'))
|
||||
.use(require('ssb-replicate'))
|
||||
.use(require('ssb-conn'))
|
||||
.use(require('ssb-room/tunnel/client'))
|
||||
|
||||
|
@ -46,9 +44,10 @@ tape(testName, function (t) {
|
|||
}, timeoutLength*1.25)
|
||||
const to = `net:${testPeerAddr}~shs:${testPeerRef.substr(1).replace('.ed25519', '')}`
|
||||
t.comment('dialing:' + to)
|
||||
sbot.connect(to, (err) => {
|
||||
sbot.conn.connect(to, (err, rpc) => {
|
||||
t.error(err, 'connected')
|
||||
testSession.after(sbot, exit)
|
||||
t.comment('connected to: '+rpc.id)
|
||||
testSession.after(sbot, rpc, exit)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -153,7 +153,7 @@ func (ts *testSession) startJSClient(name, testScript string, peerAddr net.Addr,
|
|||
"TEST_PEERADDR=" + netwrap.GetAddr(peerAddr, "tcp").String(),
|
||||
"TEST_PEERREF=" + peerRef.Ref(),
|
||||
"TEST_SESSIONSCRIPT=" + testScript,
|
||||
"DEBUG=ssb:room:tunnel:*",
|
||||
// "DEBUG=ssb:room:tunnel:*",
|
||||
}
|
||||
|
||||
if ts.keySHS != nil {
|
||||
|
@ -208,7 +208,7 @@ func (ts *testSession) startJSBotAsServer(name, testScriptFileName string) (*ref
|
|||
"TEST_REPO=" + cmd.Dir,
|
||||
fmt.Sprintf("TEST_PORT=%d", port),
|
||||
"TEST_SESSIONSCRIPT=" + testScriptFileName,
|
||||
"DEBUG=ssb:room:tunnel:*",
|
||||
// "DEBUG=ssb:room:tunnel:*",
|
||||
}
|
||||
if ts.keySHS != nil {
|
||||
env = append(env, "TEST_APPKEY="+base64.StdEncoding.EncodeToString(ts.keySHS))
|
||||
|
|
|
@ -10,13 +10,12 @@ module.exports = {
|
|||
)
|
||||
|
||||
setTimeout(ready, 1000)
|
||||
// ready()
|
||||
},
|
||||
|
||||
after: (sbot, client, exit) => {
|
||||
// hrm.. this runs twice (for each connection)
|
||||
console.warn('server new connection:', client.id)
|
||||
|
||||
setTimeout(exit, 10000)
|
||||
setTimeout(exit, 30000)
|
||||
}
|
||||
}
|
|
@ -1,43 +1,47 @@
|
|||
const pull = require('pull-stream')
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
let newConnections = 0
|
||||
|
||||
module.exports = {
|
||||
before: (sbot, ready) => {
|
||||
sbot.on('rpc:connect', rpc => {
|
||||
// announce ourselves to the room/tunnel
|
||||
rpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
console.warn(ret)
|
||||
}).catch((err) => {
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
})
|
||||
ready()
|
||||
},
|
||||
|
||||
// log all new endpoints
|
||||
pull(
|
||||
rpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
after: (sbot, rpc, exit) => {
|
||||
sbot.on("rpc:connect", (remote, isClient) => {
|
||||
console.warn("tunneld connection to simple client!")
|
||||
|
||||
// leave after 5 seconds
|
||||
setTimeout(() => {
|
||||
rpc.tunnel.leave().then((ret) => {
|
||||
console.warn('left')
|
||||
console.warn(ret)
|
||||
console.warn('room left... exiting in 10s')
|
||||
setTimeout(exit, 10000)
|
||||
}).catch((err) => {
|
||||
console.warn('left failed')
|
||||
throw err
|
||||
})
|
||||
}, 9000)
|
||||
}, 5000)
|
||||
})
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (sbot, exit) => {
|
||||
// now connected to the room
|
||||
console.warn('after connect... exiting in 10s')
|
||||
setTimeout(exit, 10000)
|
||||
// announce ourselves to the room/tunnel
|
||||
rpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
console.warn(ret)
|
||||
}).catch((err) => {
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
})
|
||||
|
||||
// log all new endpoints
|
||||
pull(
|
||||
rpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,67 +1,82 @@
|
|||
const pull = require('pull-stream')
|
||||
const { readFileSync } = require('fs')
|
||||
|
||||
|
||||
let newConnections = 0
|
||||
|
||||
module.exports = {
|
||||
before: (sbot, ready) => {
|
||||
sbot.on('rpc:connect', rpc => {
|
||||
// log all new endpoints
|
||||
pull(
|
||||
rpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
before: (client, ready) => {
|
||||
// nothing to prepare (like publishes messages, or...)
|
||||
ready()
|
||||
|
||||
rpc.tunnel.isRoom().then((yes) => {
|
||||
if (!yes) throw new Error("expected isRoom to be true!")
|
||||
console.warn("peer is indeed a room!")
|
||||
// let msg = {
|
||||
// type: 'test',
|
||||
// }
|
||||
// client.publish(msg, (err) => {
|
||||
// if (err) throw err
|
||||
// })
|
||||
},
|
||||
|
||||
// announce ourselves to the room/tunnel
|
||||
rpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
console.warn(ret)
|
||||
|
||||
setTimeout(() => {
|
||||
// put there by the go test process
|
||||
let roomHandle = readFileSync('endpoint_through_room.txt').toString()
|
||||
console.warn("connecting to room handle:", roomHandle)
|
||||
after: (client, roomSrvRpc, exit) => {
|
||||
newConnections++
|
||||
console.warn('new connection!', roomSrvRpc.id, 'total:', newConnections)
|
||||
|
||||
sbot.connect(roomHandle, (err, tunneldRpc) => {
|
||||
if (err) throw err
|
||||
console.warn("got tunnel to:", tunneldRpc.id)
|
||||
})
|
||||
}, 5000)
|
||||
}).catch((err) => {
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
})
|
||||
|
||||
|
||||
if (newConnections > 1) {
|
||||
console.warn('after call 2 - not exiting')
|
||||
return
|
||||
}
|
||||
// now connected to the room server
|
||||
|
||||
// log all new endpoints
|
||||
pull(
|
||||
roomSrvRpc.tunnel.endpoints(),
|
||||
pull.drain(el => {
|
||||
console.warn("from roomsrv:",el)
|
||||
})
|
||||
)
|
||||
|
||||
roomSrvRpc.tunnel.isRoom().then((yes) => {
|
||||
if (!yes) throw new Error("expected isRoom to be true!")
|
||||
console.warn("peer is indeed a room!")
|
||||
|
||||
// announce ourselves to the room/tunnel
|
||||
roomSrvRpc.tunnel.announce().then((ret) => {
|
||||
console.warn('announced!')
|
||||
|
||||
// put there by the go test process
|
||||
let roomHandle = readFileSync('endpoint_through_room.txt').toString()
|
||||
console.warn("connecting to room handle:", roomHandle)
|
||||
|
||||
client.conn.connect(roomHandle, (err, tunneldRpc) => {
|
||||
if (err) throw err
|
||||
console.warn("got tunnel to:", tunneldRpc.id)
|
||||
|
||||
// check the tunnel connection works
|
||||
tunneldRpc.tunnel.ping((err, id) => {
|
||||
if (err) throw err
|
||||
console.warn("ping:", id)
|
||||
|
||||
// start leaving after 2s
|
||||
setTimeout(() => {
|
||||
roomSrvRpc.tunnel.leave().then((ret) => {
|
||||
console.warn('left room... exiting in 3s')
|
||||
setTimeout(exit, 3000)
|
||||
}).catch((err) => {
|
||||
console.warn('left failed')
|
||||
throw err
|
||||
})
|
||||
}, 2000)
|
||||
})
|
||||
})
|
||||
|
||||
}).catch((err) => {
|
||||
console.warn('isRoom failed')
|
||||
console.warn('announce failed')
|
||||
throw err
|
||||
})
|
||||
|
||||
|
||||
|
||||
// leave after 5 seconds
|
||||
setTimeout(() => {
|
||||
rpc.tunnel.leave().then((ret) => {
|
||||
console.warn('left')
|
||||
console.warn(ret)
|
||||
}).catch((err) => {
|
||||
console.warn('left failed')
|
||||
throw err
|
||||
})
|
||||
}, 9000)
|
||||
}).catch((err) => {
|
||||
console.warn('isRoom failed')
|
||||
throw err
|
||||
})
|
||||
ready()
|
||||
},
|
||||
|
||||
after: (sbot, exit) => {
|
||||
// now connected to the room
|
||||
console.warn('after connect... exiting in 10s')
|
||||
setTimeout(exit, 10000)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue