diff --git a/channels/v3/inbound/3dhauthchannel_test.go b/channels/v3/inbound/3dhauthchannel_test.go index 44f785b..4d49c9f 100644 --- a/channels/v3/inbound/3dhauthchannel_test.go +++ b/channels/v3/inbound/3dhauthchannel_test.go @@ -5,10 +5,10 @@ import ( "git.openprivacy.ca/openprivacy/libricochet-go/channels" "git.openprivacy.ca/openprivacy/libricochet-go/channels/v3/outbound" "git.openprivacy.ca/openprivacy/libricochet-go/identity" + "git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/wire/auth/3edh" "git.openprivacy.ca/openprivacy/libricochet-go/wire/control" "golang.org/x/crypto/ed25519" - "github.com/golang/protobuf/proto" "testing" ) @@ -17,11 +17,13 @@ func TestServer3DHAuthChannel(t *testing.T) { cc := new(channels.Channel) cc.ID = 1 - cc.CloseChannel = func() {} + closed := false + cc.CloseChannel = func() {closed=true} clientChannel := new(outbound.Client3DHAuthChannel) pub, priv, _ := ed25519.GenerateKey(rand.Reader) cid := identity.InitializeV3("", &priv, &pub) clientChannel.ClientIdentity = cid + ocb, _ := clientChannel.OpenOutbound(cc) packet := new(Protocol_Data_Control.Packet) @@ -31,7 +33,8 @@ func TestServer3DHAuthChannel(t *testing.T) { pub, priv, _ = ed25519.GenerateKey(rand.Reader) sid := identity.InitializeV3("", &priv, &pub) s3dhchannel.ServerIdentity = sid - cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel()) + clientChannel.ServerHostname = utils.GetTorV3Hostname(pub) + cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel()) proto.Unmarshal(cr, packet) if packet.GetChannelResult() != nil { @@ -39,14 +42,19 @@ func TestServer3DHAuthChannel(t *testing.T) { authPacket := new(Protocol_Data_Auth_TripleEDH.Packet) var lastMessage []byte cc.SendMessage = func(message []byte) { + t.Logf("Received: %x", message) proto.Unmarshal(message, authPacket) lastMessage = message } clientChannel.OpenOutboundResult(nil, packet.GetChannelResult()) - // TODO: broken test or implementation. please fix - /*if authPacket.Proof == nil { + + if closed == true { + t.Fatalf("Should not have closed channel!") + } + + if authPacket.Proof == nil { t.Errorf("Was expected a Proof Packet, instead %v", authPacket) - }*/ + } s3dhchannel.ServerAuthValid = func(hostname string, publicKey ed25519.PublicKey) (allowed, known bool) { if hostname != clientChannel.ClientIdentity.Hostname() { @@ -80,6 +88,7 @@ func TestServer3DHAuthChannelReject(t *testing.T) { pub, priv, _ = ed25519.GenerateKey(rand.Reader) sid := identity.InitializeV3("", &priv, &pub) s3dhchannel.ServerIdentity = sid + clientChannel.ServerHostname = utils.GetTorV3Hostname(pub) cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel()) proto.Unmarshal(cr, packet) @@ -96,12 +105,15 @@ func TestServer3DHAuthChannelReject(t *testing.T) { } } clientChannel.OpenOutboundResult(nil, packet.GetChannelResult()) - // TODO: broken test or implementation. please fix - /*if authPacket.Proof == nil { + + if authPacket.Proof == nil { t.Errorf("Was expected a Proof Packet, instead %v", authPacket) - }*/ + } s3dhchannel.ServerAuthInvalid = func(err error) { + if err == nil { + t.Fatal("Server Auth Should have been invalid!") + } } cc.DelegateAuthorization = func() {} s3dhchannel.Packet(lastMessage)