2019-06-18 14:28:30 +00:00
|
|
|
package xmpp
|
2018-01-12 17:01:27 +00:00
|
|
|
|
2019-06-17 09:59:39 +00:00
|
|
|
import (
|
2019-11-22 14:07:40 +00:00
|
|
|
"fmt"
|
2019-06-17 09:59:39 +00:00
|
|
|
"testing"
|
|
|
|
)
|
2018-01-12 17:01:27 +00:00
|
|
|
|
2019-11-22 14:07:40 +00:00
|
|
|
const testComponentDomain = "localhost"
|
|
|
|
const testComponentPort = "15222"
|
|
|
|
|
2018-01-12 17:01:27 +00:00
|
|
|
func TestHandshake(t *testing.T) {
|
2019-06-08 17:47:05 +00:00
|
|
|
opts := ComponentOptions{
|
|
|
|
Domain: "test.localhost",
|
2018-01-12 17:01:27 +00:00
|
|
|
Secret: "mypass",
|
|
|
|
}
|
2019-06-08 17:47:05 +00:00
|
|
|
c := Component{ComponentOptions: opts}
|
2018-01-12 17:01:27 +00:00
|
|
|
|
|
|
|
streamID := "1263952298440005243"
|
|
|
|
expected := "c77e2ef0109fbbc5161e83b51629cd1353495332"
|
|
|
|
|
2018-01-12 17:14:41 +00:00
|
|
|
result := c.handshake(streamID)
|
2018-01-12 17:01:27 +00:00
|
|
|
if result != expected {
|
|
|
|
t.Errorf("incorrect handshake calculation '%s' != '%s'", result, expected)
|
|
|
|
}
|
|
|
|
}
|
2018-01-25 22:16:55 +00:00
|
|
|
|
|
|
|
func TestGenerateHandshake(t *testing.T) {
|
|
|
|
// TODO
|
|
|
|
}
|
2019-08-08 15:46:02 +00:00
|
|
|
|
|
|
|
// Test that NewStreamManager can accept a Component.
|
|
|
|
//
|
|
|
|
// This validates that Component conforms to StreamClient interface.
|
|
|
|
func TestStreamManager(t *testing.T) {
|
|
|
|
NewStreamManager(&Component{}, nil)
|
|
|
|
}
|
2019-11-22 14:07:40 +00:00
|
|
|
|
|
|
|
// Tests that the decoder is properly initialized when connecting a component to a server.
|
|
|
|
// The decoder is expected to be built after a valid connection
|
|
|
|
// Based on the xmpp_component example.
|
|
|
|
func TestDecoder(t *testing.T) {
|
|
|
|
testComponentAddess := fmt.Sprintf("%s:%s", testComponentDomain, testComponentPort)
|
|
|
|
mock := ServerMock{}
|
|
|
|
mock.Start(t, testComponentAddess, handlerConnectSuccess)
|
|
|
|
|
|
|
|
opts := ComponentOptions{
|
|
|
|
TransportConfiguration: TransportConfiguration{
|
|
|
|
Address: testComponentAddess,
|
|
|
|
Domain: "localhost",
|
|
|
|
},
|
|
|
|
Domain: testComponentDomain,
|
|
|
|
Secret: "mypass",
|
|
|
|
Name: "Test Component",
|
|
|
|
Category: "gateway",
|
|
|
|
Type: "service",
|
|
|
|
}
|
|
|
|
router := NewRouter()
|
|
|
|
c, err := NewComponent(opts, router)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%+v", err)
|
|
|
|
}
|
|
|
|
c.transport, err = NewComponentTransport(c.ComponentOptions.TransportConfiguration)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%+v", err)
|
|
|
|
}
|
|
|
|
_, err = c.transport.Connect()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("%+v", err)
|
|
|
|
}
|
|
|
|
if c.transport.GetDecoder() == nil {
|
|
|
|
t.Errorf("Failed to initialize decoder. Decoder is nil.")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|