diff --git a/client/comm_test.go b/client/comm_test.go
index f6487cf..37e9b52 100644
--- a/client/comm_test.go
+++ b/client/comm_test.go
@@ -32,6 +32,56 @@ func TestRead(t *testing.T) {
assert.Error(err)
}
+func TestDecode(t *testing.T) {
+ assert := assert.New(t)
+
+ server, clientConn := net.Pipe()
+ client := &Client{
+ Logging: log.WithField("test", "decode"),
+ }
+ client.setConnection(clientConn)
+
+ go server.Write([]byte(``))
+
+ msg := &xmpp.MessageClient{}
+ err := client.ReadDecode(msg)
+ assert.NoError(err)
+ assert.Equal("a@example.com", msg.To.String())
+
+ go server.Write([]byte(``))
+
+ iq := &xmpp.IQClient{}
+ err = client.ReadDecode(iq)
+ assert.NoError(err)
+ assert.Equal("a@example.com", iq.To.String())
+ assert.Nil(iq.Ping)
+
+ go server.Write([]byte(``))
+
+ err = client.ReadDecode(iq)
+ assert.NoError(err)
+ assert.NotNil(iq.Ping)
+
+ wgWait := &sync.WaitGroup{}
+ go server.Write([]byte(``))
+ wgWait.Add(1)
+ go func() {
+ _, err := read(xml.NewDecoder(server))
+ assert.NoError(err)
+ wgWait.Done()
+ }()
+
+ err = client.ReadDecode(iq)
+ wgWait.Wait()
+ assert.NoError(err)
+
+ go server.Write([]byte(`<>`))
+
+ err = client.ReadDecode(msg)
+ assert.Error(err)
+
+}
+
func TestSend(t *testing.T) {
assert := assert.New(t)
diff --git a/client/start.go b/client/start.go
index fa7a9c3..9362077 100644
--- a/client/start.go
+++ b/client/start.go
@@ -46,7 +46,7 @@ func (client *Client) Start() error {
iq := &xmpp.IQClient{}
err = client.Decode(iq, element)
if err == nil {
- if iq.Ping != nil {
+ if iq.Ping != nil && iq.Type == xmpp.IQTypeGet {
client.Logging.Info("client.Start: answer ping")
iq.Type = xmpp.IQTypeResult
iq.To = iq.From