2019-06-18 07:28:30 -07:00
|
|
|
package xmpp
|
2017-10-04 16:27:35 -07:00
|
|
|
|
|
|
|
import (
|
2019-12-05 09:12:00 -08:00
|
|
|
"context"
|
2017-10-04 16:27:35 -07:00
|
|
|
"encoding/xml"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2017-10-20 07:53:15 -07:00
|
|
|
"time"
|
2019-06-26 08:14:52 -07:00
|
|
|
|
|
|
|
"gosrc.io/xmpp/stanza"
|
2017-10-04 16:27:35 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Default port is not standard XMPP port to avoid interfering
|
|
|
|
// with local running XMPP server
|
2019-12-05 09:12:00 -08:00
|
|
|
testXMPPAddress = "localhost:15222"
|
|
|
|
testClientDomain = "localhost"
|
2017-10-04 16:27:35 -07:00
|
|
|
)
|
|
|
|
|
2019-12-09 03:30:37 -08:00
|
|
|
func TestEventManager(t *testing.T) {
|
|
|
|
mgr := EventManager{}
|
|
|
|
mgr.updateState(StateConnected)
|
|
|
|
if mgr.CurrentState != StateConnected {
|
|
|
|
t.Fatal("CurrentState not updated by updateState()")
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr.disconnected(SMState{})
|
|
|
|
if mgr.CurrentState != StateDisconnected {
|
|
|
|
t.Fatalf("CurrentState not reset by disconnected()")
|
|
|
|
}
|
|
|
|
|
|
|
|
mgr.streamError(ErrTLSNotSupported.Error(), "")
|
|
|
|
if mgr.CurrentState != StateStreamError {
|
|
|
|
t.Fatalf("CurrentState not set by streamError()")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-04 16:27:35 -07:00
|
|
|
func TestClient_Connect(t *testing.T) {
|
|
|
|
// Setup Mock server
|
2017-10-05 17:11:28 -07:00
|
|
|
mock := ServerMock{}
|
2019-12-05 09:12:00 -08:00
|
|
|
mock.Start(t, testXMPPAddress, handlerClientConnectSuccess)
|
2017-10-04 16:27:35 -07:00
|
|
|
|
|
|
|
// Test / Check result
|
2019-10-10 21:41:15 -07:00
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testXMPPAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
Insecure: true}
|
2017-10-04 16:27:35 -07:00
|
|
|
|
|
|
|
var client *Client
|
|
|
|
var err error
|
2019-06-18 03:41:58 -07:00
|
|
|
router := NewRouter()
|
2019-12-05 09:12:00 -08:00
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
2017-10-04 16:27:35 -07:00
|
|
|
t.Errorf("connect create XMPP client: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-06-08 09:09:22 -07:00
|
|
|
if err = client.Connect(); err != nil {
|
2017-10-04 16:27:35 -07:00
|
|
|
t.Errorf("XMPP connection failed: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mock.Stop()
|
|
|
|
}
|
|
|
|
|
2017-10-21 05:49:25 -07:00
|
|
|
func TestClient_NoInsecure(t *testing.T) {
|
|
|
|
// Setup Mock server
|
|
|
|
mock := ServerMock{}
|
2017-10-21 06:14:13 -07:00
|
|
|
mock.Start(t, testXMPPAddress, handlerAbortTLS)
|
2017-10-21 05:49:25 -07:00
|
|
|
|
|
|
|
// Test / Check result
|
2019-10-10 21:41:15 -07:00
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testXMPPAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
}
|
2017-10-21 05:49:25 -07:00
|
|
|
|
|
|
|
var client *Client
|
|
|
|
var err error
|
2019-06-18 03:41:58 -07:00
|
|
|
router := NewRouter()
|
2019-12-05 09:12:00 -08:00
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
2017-10-21 05:49:25 -07:00
|
|
|
t.Errorf("cannot create XMPP client: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-06-08 09:09:22 -07:00
|
|
|
if err = client.Connect(); err == nil {
|
2017-10-21 05:49:25 -07:00
|
|
|
// When insecure is not allowed:
|
|
|
|
t.Errorf("should fail as insecure connection is not allowed and server does not support TLS")
|
|
|
|
}
|
|
|
|
|
|
|
|
mock.Stop()
|
|
|
|
}
|
|
|
|
|
2019-06-10 07:27:52 -07:00
|
|
|
// Check that the client is properly tracking features, as session negotiation progresses.
|
|
|
|
func TestClient_FeaturesTracking(t *testing.T) {
|
|
|
|
// Setup Mock server
|
|
|
|
mock := ServerMock{}
|
|
|
|
mock.Start(t, testXMPPAddress, handlerAbortTLS)
|
|
|
|
|
|
|
|
// Test / Check result
|
2019-10-10 21:41:15 -07:00
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testXMPPAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
}
|
2019-06-10 07:27:52 -07:00
|
|
|
|
|
|
|
var client *Client
|
|
|
|
var err error
|
2019-06-18 03:41:58 -07:00
|
|
|
router := NewRouter()
|
2019-12-05 09:12:00 -08:00
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
2019-06-10 07:27:52 -07:00
|
|
|
t.Errorf("cannot create XMPP client: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = client.Connect(); err == nil {
|
|
|
|
// When insecure is not allowed:
|
|
|
|
t.Errorf("should fail as insecure connection is not allowed and server does not support TLS")
|
|
|
|
}
|
|
|
|
|
|
|
|
mock.Stop()
|
2019-06-29 08:39:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_RFC3921Session(t *testing.T) {
|
|
|
|
// Setup Mock server
|
|
|
|
mock := ServerMock{}
|
2019-12-05 09:12:00 -08:00
|
|
|
mock.Start(t, testXMPPAddress, handlerClientConnectWithSession)
|
2019-06-29 08:39:19 -07:00
|
|
|
|
|
|
|
// Test / Check result
|
2019-10-10 21:41:15 -07:00
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testXMPPAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
Insecure: true,
|
|
|
|
}
|
2019-06-29 08:39:19 -07:00
|
|
|
|
|
|
|
var client *Client
|
|
|
|
var err error
|
|
|
|
router := NewRouter()
|
2019-12-05 09:12:00 -08:00
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
2019-06-29 08:39:19 -07:00
|
|
|
t.Errorf("connect create XMPP client: %s", err)
|
|
|
|
}
|
2019-06-10 07:27:52 -07:00
|
|
|
|
2019-06-29 08:39:19 -07:00
|
|
|
if err = client.Connect(); err != nil {
|
|
|
|
t.Errorf("XMPP connection failed: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mock.Stop()
|
2019-06-10 07:27:52 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
// Testing sending an IQ to the mock server and reading its response.
|
|
|
|
func TestClient_SendIQ(t *testing.T) {
|
|
|
|
done := make(chan struct{})
|
|
|
|
// Handler for Mock server
|
2019-12-10 08:15:16 -08:00
|
|
|
h := func(t *testing.T, sc *ServerConn) {
|
|
|
|
handlerClientConnectSuccess(t, sc)
|
|
|
|
discardPresence(t, sc)
|
|
|
|
respondToIQ(t, sc)
|
2019-12-05 09:12:00 -08:00
|
|
|
done <- struct{}{}
|
|
|
|
}
|
|
|
|
client, mock := mockClientConnection(t, h, testClientIqPort)
|
|
|
|
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
iqReq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeGet, From: "test1@localhost/mremond-mbp", To: defaultServerName, Id: defaultStreamID, Lang: "en"})
|
|
|
|
disco := iqReq.DiscoInfo()
|
|
|
|
iqReq.Payload = disco
|
|
|
|
|
|
|
|
// Handle a possible error
|
|
|
|
errChan := make(chan error)
|
|
|
|
errorHandler := func(err error) {
|
|
|
|
errChan <- err
|
|
|
|
}
|
|
|
|
client.ErrorHandler = errorHandler
|
|
|
|
res, err := client.SendIQ(ctx, iqReq)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case <-res: // If the server responds with an IQ, we pass the test
|
|
|
|
case err := <-errChan: // If the server sends an error, or there is a connection error
|
2019-12-10 05:30:15 -08:00
|
|
|
t.Fatal(err.Error())
|
2019-12-05 09:12:00 -08:00
|
|
|
case <-time.After(defaultChannelTimeout): // If we timeout
|
2019-12-10 05:30:15 -08:00
|
|
|
t.Fatal("Failed to receive response, to sent IQ, from mock server")
|
2019-12-05 09:12:00 -08:00
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
mock.Stop()
|
|
|
|
case <-time.After(defaultChannelTimeout):
|
2019-12-10 05:30:15 -08:00
|
|
|
t.Fatal("The mock server failed to finish its job !")
|
2019-12-05 09:12:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_SendIQFail(t *testing.T) {
|
|
|
|
done := make(chan struct{})
|
|
|
|
// Handler for Mock server
|
2019-12-10 08:15:16 -08:00
|
|
|
h := func(t *testing.T, sc *ServerConn) {
|
|
|
|
handlerClientConnectSuccess(t, sc)
|
|
|
|
discardPresence(t, sc)
|
|
|
|
respondToIQ(t, sc)
|
2019-12-05 09:12:00 -08:00
|
|
|
done <- struct{}{}
|
|
|
|
}
|
|
|
|
client, mock := mockClientConnection(t, h, testClientIqFailPort)
|
|
|
|
|
|
|
|
//==================
|
|
|
|
// Create an IQ to send
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
iqReq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeGet, From: "test1@localhost/mremond-mbp", To: defaultServerName, Id: defaultStreamID, Lang: "en"})
|
|
|
|
disco := iqReq.DiscoInfo()
|
|
|
|
iqReq.Payload = disco
|
|
|
|
// Removing the id to make the stanza invalid. The IQ constructor makes a random one if none is specified
|
|
|
|
// so we need to overwrite it.
|
|
|
|
iqReq.Id = ""
|
|
|
|
|
|
|
|
// Handle a possible error
|
|
|
|
errChan := make(chan error)
|
|
|
|
errorHandler := func(err error) {
|
|
|
|
errChan <- err
|
|
|
|
}
|
|
|
|
client.ErrorHandler = errorHandler
|
|
|
|
res, _ := client.SendIQ(ctx, iqReq)
|
|
|
|
|
|
|
|
// Test
|
|
|
|
select {
|
|
|
|
case <-res: // If the server responds with an IQ
|
|
|
|
t.Errorf("Server should not respond with an IQ since the request is expected to be invalid !")
|
|
|
|
case <-errChan: // If the server sends an error, the test passes
|
|
|
|
case <-time.After(defaultChannelTimeout): // If we timeout
|
|
|
|
t.Errorf("Failed to receive response, to sent IQ, from mock server")
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
mock.Stop()
|
|
|
|
case <-time.After(defaultChannelTimeout):
|
|
|
|
t.Errorf("The mock server failed to finish its job !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_SendRaw(t *testing.T) {
|
|
|
|
done := make(chan struct{})
|
|
|
|
// Handler for Mock server
|
2019-12-10 08:15:16 -08:00
|
|
|
h := func(t *testing.T, sc *ServerConn) {
|
|
|
|
handlerClientConnectSuccess(t, sc)
|
|
|
|
discardPresence(t, sc)
|
|
|
|
respondToIQ(t, sc)
|
2019-12-05 09:12:00 -08:00
|
|
|
done <- struct{}{}
|
|
|
|
}
|
|
|
|
type testCase struct {
|
|
|
|
req string
|
|
|
|
shouldErr bool
|
|
|
|
port int
|
|
|
|
}
|
|
|
|
testRequests := make(map[string]testCase)
|
|
|
|
// Sending a correct IQ of type get. Not supposed to err
|
|
|
|
testRequests["Correct IQ"] = testCase{
|
|
|
|
req: `<iq type="get" id="91bd0bba-012f-4d92-bb17-5fc41e6fe545" from="test1@localhost/mremond-mbp" to="testServer" lang="en"><query xmlns="http://jabber.org/protocol/disco#info"></query></iq>`,
|
|
|
|
shouldErr: false,
|
|
|
|
port: testClientRawPort + 100,
|
|
|
|
}
|
|
|
|
// Sending an IQ with a missing ID. Should err
|
|
|
|
testRequests["IQ with missing ID"] = testCase{
|
|
|
|
req: `<iq type="get" from="test1@localhost/mremond-mbp" to="testServer" lang="en"><query xmlns="http://jabber.org/protocol/disco#info"></query></iq>`,
|
|
|
|
shouldErr: true,
|
|
|
|
port: testClientRawPort,
|
|
|
|
}
|
|
|
|
|
|
|
|
// A handler for the client.
|
|
|
|
// In the failing test, the server returns a stream error, which triggers this handler, client side.
|
|
|
|
errChan := make(chan error)
|
|
|
|
errHandler := func(err error) {
|
|
|
|
errChan <- err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for all the IQs
|
|
|
|
for name, tcase := range testRequests {
|
|
|
|
t.Run(name, func(st *testing.T) {
|
|
|
|
//Connecting to a mock server, initialized with given port and handler function
|
|
|
|
c, m := mockClientConnection(t, h, tcase.port)
|
|
|
|
c.ErrorHandler = errHandler
|
|
|
|
// Sending raw xml from test case
|
|
|
|
err := c.SendRaw(tcase.req)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error sending Raw string")
|
|
|
|
}
|
|
|
|
// Just wait a little so the message has time to arrive
|
|
|
|
select {
|
|
|
|
// We don't use the default "long" timeout here because waiting it out means passing the test.
|
|
|
|
case <-time.After(100 * time.Millisecond):
|
|
|
|
case err = <-errChan:
|
|
|
|
if err == nil && tcase.shouldErr {
|
|
|
|
t.Errorf("Failed to get closing stream err")
|
|
|
|
} else if err != nil && !tcase.shouldErr {
|
|
|
|
t.Errorf("This test is not supposed to err !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.transport.Close()
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
m.Stop()
|
|
|
|
case <-time.After(defaultChannelTimeout):
|
|
|
|
t.Errorf("The mock server failed to finish its job !")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_Disconnect(t *testing.T) {
|
|
|
|
c, m := mockClientConnection(t, handlerClientConnectSuccess, testClientBasePort)
|
|
|
|
err := c.transport.Ping()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Could not ping but not disconnected yet")
|
|
|
|
}
|
|
|
|
c.Disconnect()
|
|
|
|
err = c.transport.Ping()
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Did not disconnect properly")
|
|
|
|
}
|
|
|
|
m.Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClient_DisconnectStreamManager(t *testing.T) {
|
|
|
|
// Init mock server
|
|
|
|
// Setup Mock server
|
|
|
|
mock := ServerMock{}
|
|
|
|
mock.Start(t, testXMPPAddress, handlerAbortTLS)
|
|
|
|
|
|
|
|
// Test / Check result
|
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testXMPPAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
}
|
|
|
|
|
|
|
|
var client *Client
|
|
|
|
var err error
|
|
|
|
router := NewRouter()
|
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
|
|
|
t.Errorf("cannot create XMPP client: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sman := NewStreamManager(client, nil)
|
|
|
|
errChan := make(chan error)
|
|
|
|
runSMan := func(errChan chan error) {
|
|
|
|
errChan <- sman.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
go runSMan(errChan)
|
|
|
|
select {
|
|
|
|
case <-errChan:
|
|
|
|
case <-time.After(defaultChannelTimeout):
|
|
|
|
// When insecure is not allowed:
|
|
|
|
t.Errorf("should fail as insecure connection is not allowed and server does not support TLS")
|
|
|
|
}
|
|
|
|
mock.Stop()
|
|
|
|
}
|
|
|
|
|
2017-10-04 16:27:35 -07:00
|
|
|
//=============================================================================
|
|
|
|
// Basic XMPP Server Mock Handlers.
|
|
|
|
|
2019-06-29 08:39:19 -07:00
|
|
|
// Test connection with a basic straightforward workflow
|
2019-12-10 08:15:16 -08:00
|
|
|
func handlerClientConnectSuccess(t *testing.T, sc *ServerConn) {
|
|
|
|
checkClientOpenStream(t, sc)
|
|
|
|
sendStreamFeatures(t, sc) // Send initial features
|
|
|
|
readAuth(t, sc.decoder)
|
|
|
|
fmt.Fprintln(sc.connection, "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>")
|
|
|
|
|
|
|
|
checkClientOpenStream(t, sc) // Reset stream
|
|
|
|
sendBindFeature(t, sc) // Send post auth features
|
|
|
|
bind(t, sc)
|
2017-10-04 16:27:35 -07:00
|
|
|
}
|
|
|
|
|
2017-10-21 06:14:13 -07:00
|
|
|
// We expect client will abort on TLS
|
2019-12-10 08:15:16 -08:00
|
|
|
func handlerAbortTLS(t *testing.T, sc *ServerConn) {
|
|
|
|
checkClientOpenStream(t, sc)
|
|
|
|
sendStreamFeatures(t, sc) // Send initial features
|
2017-10-21 06:14:13 -07:00
|
|
|
}
|
|
|
|
|
2019-06-29 08:39:19 -07:00
|
|
|
// Test connection with mandatory session (RFC-3921)
|
2019-12-10 08:15:16 -08:00
|
|
|
func handlerClientConnectWithSession(t *testing.T, sc *ServerConn) {
|
|
|
|
checkClientOpenStream(t, sc)
|
|
|
|
|
|
|
|
sendStreamFeatures(t, sc) // Send initial features
|
|
|
|
readAuth(t, sc.decoder)
|
|
|
|
fmt.Fprintln(sc.connection, "<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"/>")
|
|
|
|
|
|
|
|
checkClientOpenStream(t, sc) // Reset stream
|
|
|
|
sendRFC3921Feature(t, sc) // Send post auth features
|
|
|
|
bind(t, sc)
|
|
|
|
session(t, sc)
|
2019-06-29 08:39:19 -07:00
|
|
|
}
|
|
|
|
|
2019-12-10 08:15:16 -08:00
|
|
|
func checkClientOpenStream(t *testing.T, sc *ServerConn) {
|
|
|
|
sc.connection.SetDeadline(time.Now().Add(defaultTimeout))
|
|
|
|
defer sc.connection.SetDeadline(time.Time{})
|
2017-10-20 07:53:15 -07:00
|
|
|
|
|
|
|
for { // TODO clean up. That for loop is not elegant and I prefer bounded recursion.
|
2017-10-04 16:27:35 -07:00
|
|
|
var token xml.Token
|
2019-12-10 08:15:16 -08:00
|
|
|
token, err := sc.decoder.Token()
|
2017-10-04 16:27:35 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("cannot read next token: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch elem := token.(type) {
|
|
|
|
// Wait for first startElement
|
|
|
|
case xml.StartElement:
|
2019-06-26 08:14:52 -07:00
|
|
|
if elem.Name.Space != stanza.NSStream || elem.Name.Local != "stream" {
|
2017-10-04 16:27:35 -07:00
|
|
|
err = errors.New("xmpp: expected <stream> but got <" + elem.Name.Local + "> in " + elem.Name.Space)
|
2017-10-05 17:11:28 -07:00
|
|
|
return
|
|
|
|
}
|
2019-12-10 08:15:16 -08:00
|
|
|
if _, err := fmt.Fprintf(sc.connection, serverStreamOpen, "localhost", "streamid1", stanza.NSClient, stanza.NSStream); err != nil {
|
2017-10-05 17:11:28 -07:00
|
|
|
t.Errorf("cannot write server stream open: %s", err)
|
2017-10-04 16:27:35 -07:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 08:15:16 -08:00
|
|
|
func mockClientConnection(t *testing.T, serverHandler func(*testing.T, *ServerConn), port int) (*Client, *ServerMock) {
|
|
|
|
mock := &ServerMock{}
|
2019-12-05 09:12:00 -08:00
|
|
|
testServerAddress := fmt.Sprintf("%s:%d", testClientDomain, port)
|
2017-10-04 16:27:35 -07:00
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
mock.Start(t, testServerAddress, serverHandler)
|
2017-10-04 16:27:35 -07:00
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
config := Config{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testServerAddress,
|
|
|
|
},
|
|
|
|
Jid: "test@localhost",
|
|
|
|
Credential: Password("test"),
|
|
|
|
Insecure: true}
|
2019-06-29 08:39:19 -07:00
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
var client *Client
|
|
|
|
var err error
|
|
|
|
router := NewRouter()
|
|
|
|
if client, err = NewClient(config, router, clientDefaultErrorHandler); err != nil {
|
|
|
|
t.Errorf("connect create XMPP client: %s", err)
|
2017-10-04 16:27:35 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
if err = client.Connect(); err != nil {
|
|
|
|
t.Errorf("XMPP connection failed: %s", err)
|
2017-10-04 16:27:35 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
return client, mock
|
2017-10-04 16:27:35 -07:00
|
|
|
}
|
2019-06-29 08:39:19 -07:00
|
|
|
|
2019-12-05 09:12:00 -08:00
|
|
|
// This really should not be used as is.
|
|
|
|
// It's just meant to be a placeholder when error handling is not needed at this level
|
|
|
|
func clientDefaultErrorHandler(err error) {
|
2019-06-29 08:39:19 -07:00
|
|
|
}
|