mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-10-07 08:41:47 +00:00
139 lines
4.8 KiB
Go
139 lines
4.8 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gosrc.io/xmpp/stanza"
|
|
)
|
|
|
|
func testPresence(t *testing.T, presence stanza.Presence, reference string) {
|
|
byteXML, err := xml.Marshal(presence)
|
|
if err != nil {
|
|
t.Errorf("XML parse error: %v", err)
|
|
}
|
|
xmlText := string(byteXML)
|
|
if xmlText != reference {
|
|
t.Errorf("%v does not match %v", xmlText, reference)
|
|
}
|
|
}
|
|
|
|
func TestPresenceFrom(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPFrom("test"))
|
|
testPresence(t, presence, "<presence from=\"test@from@test\" to=\"to@test\"></presence>")
|
|
}
|
|
|
|
func TestPresenceNoFrom(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test")
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"></presence>")
|
|
}
|
|
|
|
func TestPresenceType(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPType("subscribe"))
|
|
testPresence(t, presence, "<presence type=\"subscribe\" from=\"from@test\" to=\"to@test\"></presence>")
|
|
}
|
|
|
|
func TestPresenceShow(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPShow("dnd"))
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><show>dnd</show></presence>")
|
|
}
|
|
|
|
func TestPresenceStatus(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPStatus("cooking"))
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><status>cooking</status></presence>")
|
|
}
|
|
|
|
func TestPresenceNickname(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPNickname("Ishmael"))
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><nick xmlns=\"http://jabber.org/protocol/nick\">Ishmael</nick></presence>")
|
|
}
|
|
|
|
func TestPresencePhoto(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPPhoto("01b87fcd030b72895ff8e88db57ec525450f000d"))
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><x xmlns=\"vcard-temp:x:update\"><photo>01b87fcd030b72895ff8e88db57ec525450f000d</photo></x></presence>")
|
|
}
|
|
|
|
func TestPresenceCaps(t *testing.T) {
|
|
presence := newPresence("from@test", "to@test", SPCaps("QgayPKawpkPSDYmwT/WM94uAlu0="))
|
|
testPresence(t, presence, "<presence from=\"from@test\" to=\"to@test\"><c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"https://dev.narayana.im/narayana/telegabber/\" ver=\"QgayPKawpkPSDYmwT/WM94uAlu0=\"></c></presence>")
|
|
}
|
|
|
|
// Canonical XEP-0115 S5.1 worked examples (Exodus, Psi, BombusMod).
|
|
|
|
func testDiscoVer(t *testing.T, disco *stanza.DiscoInfo, reference string) {
|
|
ver := DiscoVer(disco)
|
|
if ver != reference {
|
|
var sb strings.Builder
|
|
discoToCaps(disco, &sb)
|
|
t.Errorf("%v does not match %v\nRaw string: %v", ver, reference, sb.String())
|
|
}
|
|
}
|
|
|
|
func TestDiscoVerExodus(t *testing.T) {
|
|
disco := stanza.DiscoInfo{
|
|
Identity: []stanza.Identity{
|
|
{Name: "Exodus 0.9.1", Category: "client", Type: "pc"},
|
|
},
|
|
Features: []stanza.Feature{
|
|
{Var: "http://jabber.org/protocol/disco#info"},
|
|
{Var: "http://jabber.org/protocol/disco#items"},
|
|
{Var: "http://jabber.org/protocol/muc"},
|
|
{Var: "http://jabber.org/protocol/caps"},
|
|
},
|
|
}
|
|
testDiscoVer(t, &disco, "QgayPKawpkPSDYmwT/WM94uAlu0=")
|
|
}
|
|
|
|
func TestDiscoVerPsi(t *testing.T) {
|
|
disco := stanza.DiscoInfo{
|
|
Identity: []stanza.Identity{
|
|
{Name: "Psi 0.11", Category: "client", Type: "pc"},
|
|
{Name: "Ψ 0.11", Category: "client", Type: "pc"},
|
|
},
|
|
Features: []stanza.Feature{
|
|
{Var: "http://jabber.org/protocol/disco#info"},
|
|
{Var: "http://jabber.org/protocol/disco#items"},
|
|
{Var: "http://jabber.org/protocol/muc"},
|
|
{Var: "http://jabber.org/protocol/caps"},
|
|
},
|
|
Form: &stanza.Form{
|
|
Type: "result",
|
|
Fields: []*stanza.Field{
|
|
{Var: "FORM_TYPE", Type: "hidden", ValuesList: []string{"urn:xmpp:dataforms:softwareinfo"}},
|
|
{Var: "ip_version", Type: "text-multi", ValuesList: []string{"ipv4", "ipv6"}},
|
|
{Var: "os", ValuesList: []string{"Mac"}},
|
|
{Var: "os_version", ValuesList: []string{"10.5.1"}},
|
|
{Var: "software", ValuesList: []string{"Psi"}},
|
|
{Var: "software_version", ValuesList: []string{"0.11"}},
|
|
},
|
|
},
|
|
}
|
|
testDiscoVer(t, &disco, "MxdZjNKNku1+SiM9N92yqIK2HTQ=")
|
|
}
|
|
|
|
func TestDiscoVerBombusMod(t *testing.T) {
|
|
disco := stanza.DiscoInfo{
|
|
Identity: []stanza.Identity{
|
|
{Name: "BombusMod", Category: "client", Type: "mobile"},
|
|
},
|
|
Features: []stanza.Feature{
|
|
{Var: "http://jabber.org/protocol/activity"},
|
|
{Var: "http://jabber.org/protocol/activity+notify"},
|
|
{Var: "http://jabber.org/protocol/caps"},
|
|
{Var: "http://jabber.org/protocol/commands"},
|
|
{Var: "http://jabber.org/protocol/disco#info"},
|
|
{Var: "http://jabber.org/protocol/disco#items"},
|
|
{Var: "http://jabber.org/protocol/rosterx"},
|
|
{Var: "jabber:iq:last"},
|
|
{Var: "jabber:iq:privacy"},
|
|
{Var: "jabber:iq:roster"},
|
|
{Var: "jabber:iq:time"},
|
|
{Var: "jabber:iq:version"},
|
|
{Var: "jabber:x:oob"},
|
|
{Var: "urn:xmpp:ping"},
|
|
{Var: "urn:xmpp:time"},
|
|
},
|
|
}
|
|
testDiscoVer(t, &disco, "7Awj7pIUiI5UW/L2fdtzXZFQHsw=")
|
|
}
|