Close on version mismatch

This commit is contained in:
Jakob Borg 2013-12-21 08:06:54 +01:00
parent f5987fba32
commit 8d3aa97047
2 changed files with 26 additions and 0 deletions

View File

@ -192,6 +192,10 @@ func (c *Connection) readerLoop() {
c.close()
break
}
if hdr.version != 0 {
c.close()
break
}
c.wLock.Lock()
c.lastReceive = time.Now()

View File

@ -135,3 +135,25 @@ func TestRequestResponseErr(t *testing.T) {
t.Error("Never passed")
}
}
func TestVersionErr(t *testing.T) {
m0 := &TestModel{}
m1 := &TestModel{}
ar, aw := io.Pipe()
br, bw := io.Pipe()
c0 := NewConnection("c0", ar, bw, m0)
NewConnection("c1", br, aw, m1)
c0.mwriter.writeHeader(header{
version: 2,
msgID: 0,
msgType: 0,
})
c0.flush()
if !m1.closed {
t.Error("Connection should close due to unknown version")
}
}