mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2024-11-21 18:12:00 -08:00
Do not use log fatal error when reading from a closed XML stream
This commit is contained in:
parent
d5221f1a11
commit
1154df3f97
@ -41,7 +41,7 @@ func TestClient_Connect(t *testing.T) {
|
|||||||
func TestClient_NoInsecure(t *testing.T) {
|
func TestClient_NoInsecure(t *testing.T) {
|
||||||
// Setup Mock server
|
// Setup Mock server
|
||||||
mock := ServerMock{}
|
mock := ServerMock{}
|
||||||
mock.Start(t, testXMPPAddress, handlerConnectSuccess)
|
mock.Start(t, testXMPPAddress, handlerAbortTLS)
|
||||||
|
|
||||||
// Test / Check result
|
// Test / Check result
|
||||||
options := Options{Address: testXMPPAddress, Jid: "test@localhost", Password: "test"}
|
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)
|
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) {
|
func checkOpenStream(t *testing.T, c net.Conn, decoder *xml.Decoder) {
|
||||||
c.SetDeadline(time.Now().Add(defaultTimeout))
|
c.SetDeadline(time.Now().Add(defaultTimeout))
|
||||||
defer c.SetDeadline(time.Time{})
|
defer c.SetDeadline(time.Time{})
|
||||||
|
@ -3,8 +3,8 @@ package xmpp
|
|||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reads and checks the opening XMPP stream element.
|
// Reads and checks the opening XMPP stream element.
|
||||||
@ -49,7 +49,7 @@ func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
|||||||
return xml.StartElement{}, nil
|
return xml.StartElement{}, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("token:", err)
|
return xml.StartElement{}, fmt.Errorf("nextStart %s", err)
|
||||||
}
|
}
|
||||||
switch t := t.(type) {
|
switch t := t.(type) {
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
|
Loading…
Reference in New Issue
Block a user