go-xmpp/stanza/sasl_auth_test.go

61 lines
1.4 KiB
Go
Raw Permalink Normal View History

2019-06-29 07:49:54 -07:00
package stanza_test
import (
"encoding/xml"
"testing"
"gosrc.io/xmpp/stanza"
)
// Check that we can detect optional session from advertised stream features
2019-06-29 08:39:19 -07:00
func TestSessionFeatures(t *testing.T) {
2020-03-06 07:44:01 -08:00
streamFeatures := stanza.StreamFeatures{Session: stanza.StreamSession{Optional: &struct{}{}}}
2019-06-29 07:49:54 -07:00
data, err := xml.Marshal(streamFeatures)
if err != nil {
t.Errorf("cannot marshal xml structure: %s", err)
}
parsedStream := stanza.StreamFeatures{}
if err = xml.Unmarshal(data, &parsedStream); err != nil {
2019-06-29 08:39:19 -07:00
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
2019-06-29 07:49:54 -07:00
}
2019-06-29 08:39:19 -07:00
if !parsedStream.Session.IsOptional() {
t.Error("Session should be optional")
}
}
// Check that the Session tag can be used in IQ decoding
func TestSessionIQ(t *testing.T) {
iq, err := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeSet, Id: "session"})
if err != nil {
t.Fatalf("failed to create IQ: %v", err)
}
2020-03-06 07:44:01 -08:00
iq.Payload = &stanza.StreamSession{XMLName: xml.Name{Local: "session"}, Optional: &struct{}{}}
2019-06-29 08:39:19 -07:00
data, err := xml.Marshal(iq)
if err != nil {
t.Errorf("cannot marshal xml structure: %s", err)
return
}
parsedIQ := stanza.IQ{}
if err = xml.Unmarshal(data, &parsedIQ); err != nil {
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
return
}
session, ok := parsedIQ.Payload.(*stanza.StreamSession)
if !ok {
t.Error("Missing session payload")
return
}
if !session.IsOptional() {
2019-06-29 07:49:54 -07:00
t.Error("Session should be optional")
}
}
// TODO Test Sasl mechanism