From 1154df3f971e16d0771e9c58f4267c6578b3a423 Mon Sep 17 00:00:00 2001 From: Mickael Remond Date: Sat, 21 Oct 2017 15:14:13 +0200 Subject: [PATCH] Do not use log fatal error when reading from a closed XML stream --- xmpp/client_test.go | 12 +++++++++++- xmpp/parser.go | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xmpp/client_test.go b/xmpp/client_test.go index 66c0045..704bfcf 100644 --- a/xmpp/client_test.go +++ b/xmpp/client_test.go @@ -41,7 +41,7 @@ func TestClient_Connect(t *testing.T) { func TestClient_NoInsecure(t *testing.T) { // Setup Mock server mock := ServerMock{} - mock.Start(t, testXMPPAddress, handlerConnectSuccess) + mock.Start(t, testXMPPAddress, handlerAbortTLS) // Test / Check result options := Options{Address: testXMPPAddress, Jid: "test@localhost", Password: "test"} @@ -78,6 +78,16 @@ func handlerConnectSuccess(t *testing.T, c net.Conn) { bind(t, c, decoder) } +// We expect client will abort on TLS +func handlerAbortTLS(t *testing.T, c net.Conn) { + decoder := xml.NewDecoder(c) + + checkOpenStream(t, c, decoder) + + sendStreamFeatures(t, c, decoder) // Send initial features + readAuth(t, decoder) +} + func checkOpenStream(t *testing.T, c net.Conn, decoder *xml.Decoder) { c.SetDeadline(time.Now().Add(defaultTimeout)) defer c.SetDeadline(time.Time{}) diff --git a/xmpp/parser.go b/xmpp/parser.go index 2346ed9..2b8bb19 100644 --- a/xmpp/parser.go +++ b/xmpp/parser.go @@ -3,8 +3,8 @@ package xmpp import ( "encoding/xml" "errors" + "fmt" "io" - "log" ) // Reads and checks the opening XMPP stream element. @@ -49,7 +49,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) { return xml.StartElement{}, nil } if err != nil { - log.Fatal("token:", err) + return xml.StartElement{}, fmt.Errorf("nextStart %s", err) } switch t := t.(type) { case xml.StartElement: