-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathsasl_auth_test.go
60 lines (48 loc) · 1.44 KB
/
sasl_auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package stanza_test
import (
"encoding/xml"
"testing"
"gosrc.io/xmpp/stanza"
)
// Check that we can detect optional session from advertised stream features
func TestSessionFeatures(t *testing.T) {
streamFeatures := stanza.StreamFeatures{Session: stanza.StreamSession{Optional: &struct{}{}}}
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 {
t.Errorf("Unmarshal(%s) returned error: %s", data, err)
}
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)
}
iq.Payload = &stanza.StreamSession{XMLName: xml.Name{Local: "session"}, Optional: &struct{}{}}
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() {
t.Error("Session should be optional")
}
}
// TODO Test Sasl mechanism