Fix parser bug around MSG protocol.

Make sure we do the right thing when no args are presented for an MSG, e.g. MSG <spc>.
Also do not parse at all of this is a client, only valid for routes.
This commit is contained in:
Derek Collison
2015-08-26 23:04:10 -07:00
parent a0ad3c7a8c
commit 8fb92dc7e2
4 changed files with 35 additions and 7 deletions

View File

@@ -11,6 +11,10 @@ func dummyClient() *client {
return &client{}
}
func dummyRouteClient() *client {
return &client{typ: ROUTER}
}
func TestParsePing(t *testing.T) {
c := dummyClient()
if c.state != OP_START {
@@ -233,7 +237,7 @@ func TestParsePubBadSize(t *testing.T) {
}
func TestParseMsg(t *testing.T) {
c := dummyClient()
c := dummyRouteClient()
pub := []byte("MSG foo RSID:1:2 5\r\nhello\r")
err := c.parse(pub)
@@ -310,6 +314,22 @@ func TestParseMsgArg(t *testing.T) {
testMsgArg(c, t)
}
func TestParseMsgSpace(t *testing.T) {
c := dummyRouteClient()
// Ivan bug he found
if err := c.parse([]byte("MSG \r\n")); err == nil {
t.Fatalf("Expected parse error for MSG <SPC>")
}
c = dummyClient()
// Anything with an M from a client should parse error
if err := c.parse([]byte("M")); err == nil {
t.Fatalf("Expected parse error for M* from a client")
}
}
func TestShouldFail(t *testing.T) {
c := dummyClient()