This repository has been archived on 2020-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
libricochet-go/ricochet_test.go

66 lines
1.5 KiB
Go
Raw Normal View History

2017-05-02 23:33:51 +00:00
package goricochet
import (
"git.openprivacy.ca/openprivacy/connectivity"
"net"
"testing"
"time"
2017-05-02 23:33:51 +00:00
)
func SimpleServer() {
ln, _ := net.Listen("tcp", "127.0.0.1:11000")
conn, _ := ln.Accept()
b := make([]byte, 4)
n, err := conn.Read(b)
if n == 4 && err == nil {
conn.Write([]byte{0x03})
}
conn.Close()
2017-05-02 23:33:51 +00:00
}
func TestRicochetOpen(t *testing.T) {
acn := connectivity.NewLocalACN()
go SimpleServer()
// Wait for Server to Initialize
time.Sleep(time.Second)
2017-05-02 23:33:51 +00:00
rc, err := Open(acn, "127.0.0.1:11000|abcdefghijklmno.onion")
if err == nil {
if rc.IsInbound {
t.Errorf("RicochetConnection declares itself as an Inbound connection after an Outbound attempt...that shouldn't happen")
}
return
}
t.Errorf("RicochetProtocol: Open Failed: %v", err)
2017-05-02 23:33:51 +00:00
}
func BadServer() {
ln, _ := net.Listen("tcp", "127.0.0.1:11001")
conn, _ := ln.Accept()
b := make([]byte, 4)
n, err := conn.Read(b)
if n == 4 && err == nil {
conn.Write([]byte{0xFF})
}
conn.Close()
}
func TestRicochetOpenWithError(t *testing.T) {
acn := connectivity.NewLocalACN()
go BadServer()
// Wait for Server to Initialize
time.Sleep(time.Second)
_, err := Open(acn, "127.0.0.1:11001|abcdefghijklmno.onion")
if err == nil {
t.Errorf("Open should have failed because of bad version negotiation.")
}
2017-05-02 23:33:51 +00:00
}
2018-01-03 18:20:53 +00:00
func TestRicochetOpenWithNoServer(t *testing.T) {
acn := connectivity.NewLocalACN()
_, err := Open(acn, "127.0.0.1:11002|abcdefghijklmno.onion")
2018-01-03 18:20:53 +00:00
if err == nil {
t.Errorf("Open should have failed because of bad version negotiation.")
}
}