Stubbing OutboundVersionNegotiationTest
Actually committing enable features work!
This commit is contained in:
parent
6d449e230f
commit
049a0ea15f
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/s-rah/go-ricochet/identity"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RicochetApplication bundles many useful constructs that are
|
||||
|
@ -145,7 +145,7 @@ func (rai *RicochetApplicationInstance) OnClosed(err error) {
|
|||
|
||||
func (ra *RicochetApplication) Broadcast(message string) {
|
||||
ra.lock.Lock()
|
||||
for _,rai := range ra.instances {
|
||||
for _, rai := range ra.instances {
|
||||
rai.SendChatMessage(message)
|
||||
}
|
||||
ra.lock.Unlock()
|
||||
|
|
|
@ -36,7 +36,7 @@ func (ach *AutoConnectionHandler) OnClosed(err error) {
|
|||
|
||||
func (ach *AutoConnectionHandler) GetSupportedChannelTypes() []string {
|
||||
supported := []string{}
|
||||
for k,_ := range ach.handlerMap {
|
||||
for k := range ach.handlerMap {
|
||||
supported = append(supported, k)
|
||||
}
|
||||
return supported
|
||||
|
|
|
@ -463,8 +463,8 @@ func (rc *Connection) controlPacket(handler Handler, res *Protocol_Data_Control.
|
|||
featuresToEnable := res.GetEnableFeatures().GetFeature()
|
||||
supportChannels := handler.GetSupportedChannelTypes()
|
||||
result := []string{}
|
||||
for _,v := range featuresToEnable {
|
||||
for _,s := range supportChannels {
|
||||
for _, v := range featuresToEnable {
|
||||
for _, s := range supportChannels {
|
||||
if v == s {
|
||||
result = append(result, v)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package goricochet
|
||||
|
||||
import (
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
)
|
||||
|
||||
func TestBadProtcolLength(t *testing.T) {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package goricochet
|
||||
|
||||
import (
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInvalidResponse(t *testing.T) {
|
||||
go func() {
|
||||
ln, _ := net.Listen("tcp", "127.0.0.1:12000")
|
||||
conn, _ := ln.Accept()
|
||||
b := make([]byte, 4)
|
||||
n, err := conn.Read(b)
|
||||
if n == 4 && err == nil {
|
||||
conn.Write([]byte{0xFF})
|
||||
}
|
||||
conn.Close()
|
||||
}()
|
||||
time.Sleep(time.Second * 1)
|
||||
conn, err := net.Dial("tcp", ":12000")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
_, err = NegotiateVersionOutbound(conn, "")
|
||||
if err != utils.VersionNegotiationFailed {
|
||||
t.Errorf("Expected VersionNegotiationFailed got %v", err)
|
||||
}
|
||||
}
|
16
testing.md
16
testing.md
|
@ -10,7 +10,7 @@ other for outbound connections.
|
|||
|
||||
## Version Negotiation
|
||||
|
||||
File: [ricochet_test.go](./inbound_version_negotiation_test.go)
|
||||
File: [inbound_version_negotiation_test.go](./inbound_version_negotiation_test.go)
|
||||
|
||||
### Invalid Protocol
|
||||
|
||||
|
@ -33,3 +33,17 @@ Assuming the inbound listener receives a valid protocol message, and that messag
|
|||
contains a known supported version. Then the connection should remain open.
|
||||
|
||||
# Outbound
|
||||
|
||||
File: [outbound_version_negotiation_test.go](./outbound_version_negotiation_test.go)
|
||||
|
||||
### No Compatible Version Found
|
||||
|
||||
If the outbound connection receives a response that does not match one of the versions
|
||||
they sent out in their supporting list. Then then must close the connection `TestInvalidResponse`
|
||||
|
||||
|
||||
### Successful Version Negotiation
|
||||
|
||||
Assuming the outbound connection receives a valid protocol message, and that message
|
||||
contains a known supported version. Then the connection should remain open.
|
||||
|
||||
|
|
Reference in New Issue