Fix import and test

This commit is contained in:
Mickael Remond 2019-06-08 19:47:05 +02:00 committed by Mickaël Rémond
parent 2d95ca9384
commit 6fc12e9779
2 changed files with 14 additions and 15 deletions

View File

@ -9,8 +9,6 @@ import (
"io"
"net"
"time"
"gosrc.io/xmpp"
)
const componentStreamOpen = "<?xml version='1.0'?><stream:stream to='%s' xmlns='%s' xmlns:stream='%s'>"
@ -140,11 +138,11 @@ func (c *Component) recv() (err error) {
close(c.RecvChannel)
c.streamError(p.Error.Local, p.Text)
return errors.New("stream error: " + p.Error.Local)
case xmpp.IQ:
case IQ:
switch inner := p.Payload[0].(type) {
// Our component module handle disco info but can let component implementation
// handle disco items queries
case *xmpp.DiscoInfo:
case *DiscoInfo:
if p.Type == "get" {
c.discoResult(p.PacketAttrs, inner)
}
@ -223,25 +221,25 @@ func (handshakeDecoder) decode(p *xml.Decoder, se xml.StartElement) (Handshake,
// Service discovery
func (c *Component) discoResult(attrs xmpp.PacketAttrs, info *xmpp.DiscoInfo) {
iq := xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
var identity xmpp.Identity
func (c *Component) discoResult(attrs PacketAttrs, info *DiscoInfo) {
iq := NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
var identity Identity
if info.Node == "" {
identity = xmpp.Identity{
identity = Identity{
Name: c.Name,
Category: c.Category,
Type: c.Type,
}
}
payload := xmpp.DiscoInfo{
payload := DiscoInfo{
Identity: identity,
Features: []xmpp.Feature{
{Var: xmpp.NSDiscoInfo},
{Var: xmpp.NSDiscoItems},
Features: []Feature{
{Var: NSDiscoInfo},
{Var: NSDiscoItems},
},
}
iq.AddPayload(&payload)
_ = c.xmpp.Send(iq)
_ = c.Send(iq)
}

View File

@ -3,10 +3,11 @@ package xmpp // import "gosrc.io/xmpp"
import "testing"
func TestHandshake(t *testing.T) {
c := Component{
Host: "test.localhost",
opts := ComponentOptions{
Domain: "test.localhost",
Secret: "mypass",
}
c := Component{ComponentOptions: opts}
streamID := "1263952298440005243"
expected := "c77e2ef0109fbbc5161e83b51629cd1353495332"