minidom, tokio-xmpp: switch xml parsing to rxml
This commit is contained in:
parent
3901068717
commit
d4a5a8247b
33 changed files with 465 additions and 811 deletions
|
|
@ -265,8 +265,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_5_2() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='http://jabber.org/protocol/disco#info'
|
||||
let elem: Element = r#"<query xmlns='http://jabber.org/protocol/disco#info'
|
||||
node='http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w='>
|
||||
<identity category='client' name='Exodus 0.9.1' type='pc'/>
|
||||
<feature var='http://jabber.org/protocol/caps'/>
|
||||
|
|
@ -294,8 +293,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_5_3() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='http://jabber.org/protocol/disco#info'
|
||||
let elem: Element = r#"<query xmlns='http://jabber.org/protocol/disco#info'
|
||||
node='http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w='>
|
||||
<identity xml:lang='en' category='client' name='Psi 0.11' type='pc'/>
|
||||
<identity xml:lang='el' category='client' name='Ψ 0.11' type='pc'/>
|
||||
|
|
|
|||
|
|
@ -176,8 +176,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn list() {
|
||||
let elem: Element = r#"
|
||||
<items xmlns='urn:xmpp:saslcert:1'>
|
||||
let elem: Element = r#"<items xmlns='urn:xmpp:saslcert:1'>
|
||||
<item>
|
||||
<name>Mobile Client</name>
|
||||
<x509cert>AAAA</x509cert>
|
||||
|
|
|
|||
|
|
@ -236,8 +236,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_ex1() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns="http://jabber.org/protocol/disco#info">
|
||||
let elem: Element = r#"<query xmlns="http://jabber.org/protocol/disco#info">
|
||||
<identity category="client" name="BombusMod" type="mobile"/>
|
||||
<feature var="http://jabber.org/protocol/si"/>
|
||||
<feature var="http://jabber.org/protocol/bytestreams"/>
|
||||
|
|
@ -307,8 +306,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_ex2() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns="http://jabber.org/protocol/disco#info">
|
||||
let elem: Element = r#"<query xmlns="http://jabber.org/protocol/disco#info">
|
||||
<identity category="client" name="Tkabber" type="pc" xml:lang="en"/>
|
||||
<identity category="client" name="Ткаббер" type="pc" xml:lang="ru"/>
|
||||
<feature var="games:board"/>
|
||||
|
|
|
|||
|
|
@ -137,8 +137,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ex2() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='jabber:iq:register'>
|
||||
let elem: Element = r#"<query xmlns='jabber:iq:register'>
|
||||
<instructions>
|
||||
Choose a username and password for use with this service.
|
||||
Please also provide your email address.
|
||||
|
|
|
|||
|
|
@ -354,8 +354,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_description() {
|
||||
let elem: Element = r#"
|
||||
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
let elem: Element = r#"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
<file>
|
||||
<media-type>text/plain</media-type>
|
||||
<name>test.txt</name>
|
||||
|
|
@ -387,8 +386,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_request() {
|
||||
let elem: Element = r#"
|
||||
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
let elem: Element = r#"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
<file>
|
||||
<hash xmlns='urn:xmpp:hashes:2'
|
||||
algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>
|
||||
|
|
@ -413,8 +411,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_descs() {
|
||||
let elem: Element = r#"
|
||||
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
let elem: Element = r#"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
<file>
|
||||
<media-type>text/plain</media-type>
|
||||
<desc xml:lang='fr'>Fichier secret !</desc>
|
||||
|
|
@ -437,8 +434,7 @@ mod tests {
|
|||
Desc(String::from("Fichier secret !"))
|
||||
);
|
||||
|
||||
let elem: Element = r#"
|
||||
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
let elem: Element = r#"<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
||||
<file>
|
||||
<media-type>text/plain</media-type>
|
||||
<desc xml:lang='fr'>Fichier secret !</desc>
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn parse_group() {
|
||||
let elem: Element = "
|
||||
<group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
|
||||
let elem: Element = "<group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
|
||||
<content name='voice'/>
|
||||
<content name='webcam'/>
|
||||
</group>"
|
||||
|
|
|
|||
|
|
@ -134,8 +134,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_gajim() {
|
||||
let elem: Element = "
|
||||
<transport xmlns='urn:xmpp:jingle:transports:ice-udp:1' pwd='wakMJ8Ydd5rqnPaFerws5o' ufrag='aeXX'>
|
||||
let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:ice-udp:1' pwd='wakMJ8Ydd5rqnPaFerws5o' ufrag='aeXX'>
|
||||
<candidate xmlns='urn:xmpp:jingle:transports:ice-udp:1' component='2' foundation='1' generation='0' id='11b72719-6a1b-4c51-8ae6-9f1538047568' ip='192.168.0.12' network='0' port='56715' priority='1010828030' protocol='tcp' type='host'/>
|
||||
<candidate xmlns='urn:xmpp:jingle:transports:ice-udp:1' component='2' foundation='1' generation='0' id='7e07b22d-db50-4e17-9ed9-eafeb96f4f63' ip='192.168.0.12' network='0' port='0' priority='1015022334' protocol='tcp' type='host'/>
|
||||
<candidate xmlns='urn:xmpp:jingle:transports:ice-udp:1' component='2' foundation='1' generation='0' id='431de362-c45f-40a8-bf10-9ed898a71d86' ip='192.168.0.12' network='0' port='36480' priority='2013266428' protocol='udp' type='host'/>
|
||||
|
|
@ -164,8 +163,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_jitsi_meet() {
|
||||
let elem: Element = "
|
||||
<transport ufrag='2acq51d4p07v2m' pwd='7lk9uul39gckit6t02oavv2r9j' xmlns='urn:xmpp:jingle:transports:ice-udp:1'>
|
||||
let elem: Element = "<transport ufrag='2acq51d4p07v2m' pwd='7lk9uul39gckit6t02oavv2r9j' xmlns='urn:xmpp:jingle:transports:ice-udp:1'>
|
||||
<fingerprint hash='sha-1' setup='actpass' xmlns='urn:xmpp:jingle:apps:dtls:0'>97:F2:B5:BE:DB:A6:00:B1:3E:40:B2:41:3C:0D:FC:E0:BD:B2:A0:E8</fingerprint>
|
||||
<candidate type='host' protocol='udp' id='186cb069513c2bbe546192c93cc4ab3b05ab0d426' ip='2a05:d014:fc7:54a1:8bfc:7248:3d1c:51a4' component='1' port='10000' foundation='1' generation='0' priority='2130706431' network='0'/>
|
||||
<candidate type='host' protocol='udp' id='186cb069513c2bbe546192c93cc4ab3b063daeefd' ip='10.15.1.120' component='1' port='10000' foundation='2' generation='0' priority='2130706431' network='0'/>
|
||||
|
|
|
|||
|
|
@ -78,8 +78,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn example_1() {
|
||||
let elem: Element = "
|
||||
<transport xmlns='urn:xmpp:jingle:transports:raw-udp:1'>
|
||||
let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:raw-udp:1'>
|
||||
<candidate component='1'
|
||||
generation='0'
|
||||
id='a9j3mnbtu1'
|
||||
|
|
|
|||
|
|
@ -175,8 +175,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let elem: Element = "
|
||||
<description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
|
||||
let elem: Element = "<description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
|
||||
<payload-type xmlns='urn:xmpp:jingle:apps:rtp:1' channels='2' clockrate='48000' id='96' name='OPUS'/>
|
||||
<payload-type xmlns='urn:xmpp:jingle:apps:rtp:1' channels='1' clockrate='32000' id='105' name='SPEEX'/>
|
||||
<payload-type xmlns='urn:xmpp:jingle:apps:rtp:1' channels='1' clockrate='8000' id='9' name='G722'/>
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn parse_exthdr() {
|
||||
let elem: Element = "
|
||||
<rtp-hdrext xmlns='urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
|
||||
let elem: Element = "<rtp-hdrext xmlns='urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
|
||||
uri='urn:ietf:params:rtp-hdrext:toffset'
|
||||
id='1'/>"
|
||||
.parse()
|
||||
|
|
|
|||
|
|
@ -101,8 +101,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn parse_source() {
|
||||
let elem: Element = "
|
||||
<source ssrc='1656081975' xmlns='urn:xmpp:jingle:apps:rtp:ssma:0'>
|
||||
let elem: Element = "<source ssrc='1656081975' xmlns='urn:xmpp:jingle:apps:rtp:ssma:0'>
|
||||
<parameter name='cname' value='Yv/wvbCdsDW2Prgd'/>
|
||||
<parameter name='msid' value='MLTJKIHilGn71fNQoszkQ4jlPTuS5vJyKVIv MLTJKIHilGn71fNQoszkQ4jlPTuS5vJyKVIva0'/>
|
||||
</source>"
|
||||
|
|
@ -124,8 +123,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn parse_source_group() {
|
||||
let elem: Element = "
|
||||
<ssrc-group semantics='FID' xmlns='urn:xmpp:jingle:apps:rtp:ssma:0'>
|
||||
let elem: Element = "<ssrc-group semantics='FID' xmlns='urn:xmpp:jingle:apps:rtp:ssma:0'>
|
||||
<source ssrc='2301230316'/>
|
||||
<source ssrc='386328120'/>
|
||||
</ssrc-group>"
|
||||
|
|
|
|||
|
|
@ -186,8 +186,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn parse_bundle() {
|
||||
let elem: Element = r#"
|
||||
<bundle xmlns="eu.siacs.conversations.axolotl">
|
||||
let elem: Element = r#"<bundle xmlns="eu.siacs.conversations.axolotl">
|
||||
<signedPreKeyPublic signedPreKeyId="1">BYAbACA15bPn95p7RGC2XbgQyly8aRKS4BaJ+hD8Ybhe</signedPreKeyPublic>
|
||||
<signedPreKeySignature>sIJVNDZi/NgFsry4OBdM+adyGttLEXbUh/h/5dVOZveMgyVoIdgwBUzq8Wgd2xYTQMioNzwYebTX+9p0h9eujA==</signedPreKeySignature>
|
||||
<identityKey>BQFd2p/Oq97vAAdLKA09DlcSg0x1xWn260p1jaeyIhAZ</identityKey>
|
||||
|
|
@ -254,8 +253,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn parse_device_list() {
|
||||
let elem: Element = r#"
|
||||
<list xmlns="eu.siacs.conversations.axolotl">
|
||||
let elem: Element = r#"<list xmlns="eu.siacs.conversations.axolotl">
|
||||
<device id="1164059891" />
|
||||
<device id="26052318" />
|
||||
<device id="564866972" />
|
||||
|
|
@ -275,8 +273,7 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn parse_encrypted() {
|
||||
let elem: Element = r#"
|
||||
<encrypted xmlns="eu.siacs.conversations.axolotl">
|
||||
let elem: Element = r#"<encrypted xmlns="eu.siacs.conversations.axolotl">
|
||||
<header sid="564866972">
|
||||
<key prekey="true" rid="1236">Mwjp9AESIQVylscLPpj/HlowaTiIsaBj73HCVEllXpVTtMG9EYwRexohBQFd2p/Oq97vAAdLKA09DlcSg0x1xWn260p1jaeyIhAZImIzCiEFhaQ4I+DuQgo6vCLCjHu4uewDZmWHuBl8uJw1IkyZxhUQABgAIjCoEVgVThWlaIlnN3V5Bg1hQX7OD1cvstLD5lH3zZMadL3KeONELESlBbeKmNgcYC/e3HZnbgWzBiic36yNAjAW</key>
|
||||
<key rid="26052318">MwohBTV6dpumL1OxA9MdIFmu2E19+cIWDHWYfhdubvo0hmh6EAAYHCIwNc9/59eeYi8pVZQhMJJMVkKUkFP/yrTfG3o1lfpHGseCqb/JTgtDytQPiYrTpHl2V/mdsM6IPig=</key>
|
||||
|
|
|
|||
|
|
@ -123,8 +123,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_result() {
|
||||
#[cfg(not(feature = "component"))]
|
||||
let elem: Element = r#"
|
||||
<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
||||
let elem: Element = r#"<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
||||
<forwarded xmlns='urn:xmpp:forward:0'>
|
||||
<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
|
||||
<message xmlns='jabber:client' from="witch@shakespeare.lit" to="macbeth@shakespeare.lit">
|
||||
|
|
@ -136,8 +135,7 @@ mod tests {
|
|||
.parse()
|
||||
.unwrap();
|
||||
#[cfg(feature = "component")]
|
||||
let elem: Element = r#"
|
||||
<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
||||
let elem: Element = r#"<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
|
||||
<forwarded xmlns='urn:xmpp:forward:0'>
|
||||
<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
|
||||
<message xmlns='jabber:component:accept' from="witch@shakespeare.lit" to="macbeth@shakespeare.lit">
|
||||
|
|
@ -151,8 +149,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_fin() {
|
||||
let elem: Element = r#"
|
||||
<fin xmlns='urn:xmpp:mam:2'>
|
||||
let elem: Element = r#"<fin xmlns='urn:xmpp:mam:2'>
|
||||
<set xmlns='http://jabber.org/protocol/rsm'>
|
||||
<first index='0'>28482-98726-73623</first>
|
||||
<last>09af3-cc343-b409f</last>
|
||||
|
|
@ -166,8 +163,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_query_x() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='urn:xmpp:mam:2'>
|
||||
let elem: Element = r#"<query xmlns='urn:xmpp:mam:2'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:2</value>
|
||||
|
|
@ -185,8 +181,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_query_x_set() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='urn:xmpp:mam:2'>
|
||||
let elem: Element = r#"<query xmlns='urn:xmpp:mam:2'>
|
||||
<x xmlns='jabber:x:data' type='submit'>
|
||||
<field var='FORM_TYPE' type='hidden'>
|
||||
<value>urn:xmpp:mam:2</value>
|
||||
|
|
|
|||
|
|
@ -134,8 +134,7 @@ mod tests {
|
|||
assert!(prefs.always.is_empty());
|
||||
assert!(prefs.never.is_empty());
|
||||
|
||||
let elem: Element = r#"
|
||||
<prefs xmlns='urn:xmpp:mam:2' default='roster'>
|
||||
let elem: Element = r#"<prefs xmlns='urn:xmpp:mam:2' default='roster'>
|
||||
<always/>
|
||||
<never/>
|
||||
</prefs>
|
||||
|
|
@ -149,8 +148,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_prefs_result() {
|
||||
let elem: Element = r#"
|
||||
<prefs xmlns='urn:xmpp:mam:2' default='roster'>
|
||||
let elem: Element = r#"<prefs xmlns='urn:xmpp:mam:2' default='roster'>
|
||||
<always>
|
||||
<jid>romeo@montague.lit</jid>
|
||||
</always>
|
||||
|
|
|
|||
|
|
@ -174,8 +174,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_ex1() {
|
||||
let elem: Element = r#"
|
||||
<media xmlns='urn:xmpp:media-element'>
|
||||
let elem: Element = r#"<media xmlns='urn:xmpp:media-element'>
|
||||
<uri type='audio/x-wav'>
|
||||
http://victim.example.com/challenges/speech.wav?F3A6292C
|
||||
</uri>
|
||||
|
|
@ -211,8 +210,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_xep_ex2() {
|
||||
let elem: Element = r#"
|
||||
<x xmlns='jabber:x:data' type='form'>
|
||||
let elem: Element = r#"<x xmlns='jabber:x:data' type='form'>
|
||||
[ ... ]
|
||||
<field var='ocr'>
|
||||
<media xmlns='urn:xmpp:media-element'
|
||||
|
|
|
|||
|
|
@ -163,8 +163,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn history() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'>
|
||||
<history maxstanzas='0'/>
|
||||
</x>"
|
||||
.parse()
|
||||
|
|
@ -179,8 +178,7 @@ mod tests {
|
|||
assert_eq!(history.seconds, None);
|
||||
assert_eq!(history.since, None);
|
||||
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc'>
|
||||
<history since='1970-01-01T00:00:00Z'/>
|
||||
</x>"
|
||||
.parse()
|
||||
|
|
|
|||
|
|
@ -239,25 +239,21 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
MucUser::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn statuses_and_items() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<status code='101'/>
|
||||
<status code='102'/>
|
||||
<item affiliation='member' role='moderator'/>
|
||||
</x>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</x>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let muc_user = MucUser::try_from(elem).unwrap();
|
||||
assert_eq!(muc_user.status.len(), 2);
|
||||
assert_eq!(muc_user.status[0], Status::AffiliationChange);
|
||||
|
|
@ -269,13 +265,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_invalid_child() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<coucou/>
|
||||
</x>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</x>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = MucUser::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -286,11 +280,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_serialise() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let muc = MucUser {
|
||||
status: vec![],
|
||||
items: vec![],
|
||||
|
|
@ -302,11 +294,9 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_invalid_attribute() {
|
||||
let elem: Element = "
|
||||
<x xmlns='http://jabber.org/protocol/muc#user' coucou=''/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<x xmlns='http://jabber.org/protocol/muc#user' coucou=''/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = MucUser::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -317,21 +307,17 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_simple() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Status::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_invalid() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -343,13 +329,11 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_status_invalid_child() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='110'>
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='110'>
|
||||
<foo/>
|
||||
</status>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</status>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -360,22 +344,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_simple_code() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='307'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='307'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let status = Status::try_from(elem).unwrap();
|
||||
assert_eq!(status, Status::Kicked);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_status_invalid_code() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='666'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='666'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -386,11 +366,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_status_invalid_code2() {
|
||||
let elem: Element = "
|
||||
<status xmlns='http://jabber.org/protocol/muc#user' code='coucou'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<status xmlns='http://jabber.org/protocol/muc#user' code='coucou'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Status::try_from(elem).unwrap_err();
|
||||
let error = match error {
|
||||
Error::ParseIntError(error) => error,
|
||||
|
|
@ -401,11 +379,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_required_attributes() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Actor::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -416,13 +392,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_required_attributes2() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'
|
||||
nick='baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
nick='baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Actor::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -433,12 +407,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_jid() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user'
|
||||
jid='foo@bar/baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let actor = Actor::try_from(elem).unwrap();
|
||||
let jid = match actor {
|
||||
Actor::Jid(jid) => jid,
|
||||
|
|
@ -449,11 +421,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_actor_nick() {
|
||||
let elem: Element = "
|
||||
<actor xmlns='http://jabber.org/protocol/muc#user' nick='baz'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<actor xmlns='http://jabber.org/protocol/muc#user' nick='baz'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let actor = Actor::try_from(elem).unwrap();
|
||||
let nick = match actor {
|
||||
Actor::Nick(nick) => nick,
|
||||
|
|
@ -464,35 +434,29 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_continue_simple() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Continue::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continue_thread_attribute() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'
|
||||
thread='foo'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'
|
||||
thread='foo'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let continue_ = Continue::try_from(elem).unwrap();
|
||||
assert_eq!(continue_.thread, Some("foo".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_continue_invalid() {
|
||||
let elem: Element = "
|
||||
<continue xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<continue xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<foobar/>
|
||||
</continue>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</continue>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let continue_ = Continue::try_from(elem).unwrap_err();
|
||||
let message = match continue_ {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -503,8 +467,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reason_simple() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user'>Reason</reason>"
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>Reason</reason>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem2 = elem.clone();
|
||||
|
|
@ -518,11 +481,9 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_reason_invalid_attribute() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user' foo='bar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user' foo='bar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Reason::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -534,13 +495,11 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_reason_invalid() {
|
||||
let elem: Element = "
|
||||
<reason xmlns='http://jabber.org/protocol/muc#user'>
|
||||
let elem: Element = "<reason xmlns='http://jabber.org/protocol/muc#user'>
|
||||
<foobar/>
|
||||
</reason>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</reason>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Reason::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -552,12 +511,10 @@ mod tests {
|
|||
#[cfg(not(feature = "disable-validation"))]
|
||||
#[test]
|
||||
fn test_item_invalid_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
foo='bar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
foo='bar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -568,24 +525,20 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
role='moderator'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
Item::try_from(elem).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_invalid_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -596,14 +549,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_nick_attr() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'
|
||||
nick='foobar'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
nick='foobar'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { nick, .. } => assert_eq!(nick, Some("foobar".to_owned())),
|
||||
|
|
@ -612,12 +563,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_affiliation_role_invalid_attr2() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
role='moderator'/>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
role='moderator'/>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let error = Item::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
|
|
@ -631,15 +580,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_actor_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<actor nick='foobar'/>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { actor, .. } => assert_eq!(actor, Some(Actor::Nick("foobar".to_owned()))),
|
||||
|
|
@ -648,15 +595,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_continue_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<continue thread='foobar'/>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
let continue_1 = Continue {
|
||||
thread: Some("foobar".to_owned()),
|
||||
|
|
@ -672,15 +617,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_item_role_reason_child() {
|
||||
let elem: Element = "
|
||||
<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
let elem: Element = "<item xmlns='http://jabber.org/protocol/muc#user'
|
||||
affiliation='member'
|
||||
role='moderator'>
|
||||
<reason>foobar</reason>
|
||||
</item>
|
||||
"
|
||||
.parse()
|
||||
.unwrap();
|
||||
</item>"
|
||||
.parse()
|
||||
.unwrap();
|
||||
let item = Item::try_from(elem).unwrap();
|
||||
match item {
|
||||
Item { reason, .. } => assert_eq!(reason, Some(Reason("foobar".to_owned()))),
|
||||
|
|
|
|||
|
|
@ -142,8 +142,7 @@ mod tests {
|
|||
assert_eq!(roster.ver, Some(String::from("ver9")));
|
||||
assert!(roster.items.is_empty());
|
||||
|
||||
let elem: Element = r#"
|
||||
<query xmlns='jabber:iq:roster' ver='ver11'>
|
||||
let elem: Element = r#"<query xmlns='jabber:iq:roster' ver='ver11'>
|
||||
<item jid='romeo@example.net'
|
||||
name='Romeo'
|
||||
subscription='both'>
|
||||
|
|
@ -215,16 +214,14 @@ mod tests {
|
|||
assert!(roster.ver.is_none());
|
||||
assert_eq!(roster.items.len(), 1);
|
||||
|
||||
let elem: Element = r#"
|
||||
<query xmlns='jabber:iq:roster'>
|
||||
let elem: Element = r#"<query xmlns='jabber:iq:roster'>
|
||||
<item jid='nurse@example.com'
|
||||
name='Nurse'>
|
||||
<group>Servants</group>
|
||||
</item>
|
||||
</query>
|
||||
"#
|
||||
.parse()
|
||||
.unwrap();
|
||||
</query>"#
|
||||
.parse()
|
||||
.unwrap();
|
||||
let roster = Roster::try_from(elem).unwrap();
|
||||
assert!(roster.ver.is_none());
|
||||
assert_eq!(roster.items.len(), 1);
|
||||
|
|
@ -236,14 +233,12 @@ mod tests {
|
|||
Group::from_str("Servants").unwrap()
|
||||
);
|
||||
|
||||
let elem: Element = r#"
|
||||
<query xmlns='jabber:iq:roster'>
|
||||
let elem: Element = r#"<query xmlns='jabber:iq:roster'>
|
||||
<item jid='nurse@example.com'
|
||||
subscription='remove'/>
|
||||
</query>
|
||||
"#
|
||||
.parse()
|
||||
.unwrap();
|
||||
</query>"#
|
||||
.parse()
|
||||
.unwrap();
|
||||
let roster = Roster::try_from(elem).unwrap();
|
||||
assert!(roster.ver.is_none());
|
||||
assert_eq!(roster.items.len(), 1);
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn a() {
|
||||
let elem: Element = "<a xmlns='urn:xmpp:sm:3' h='5'".parse().unwrap();
|
||||
let elem: Element = "<a xmlns='urn:xmpp:sm:3' h='5'/>".parse().unwrap();
|
||||
let a = A::try_from(elem).unwrap();
|
||||
assert_eq!(a.h, 5);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ impl TryFrom<Element> for TimeResult {
|
|||
check_no_children!(child, "tzo");
|
||||
check_no_attributes!(child, "tzo");
|
||||
// TODO: Add a FromStr implementation to FixedOffset to avoid this hack.
|
||||
let fake_date = String::from("2019-04-22T11:38:00") + &child.text();
|
||||
let fake_date = format!("{}{}", "2019-04-22T11:38:00", child.text());
|
||||
let date_time = DateTime::from_str(&fake_date)?;
|
||||
tzo = Some(date_time.timezone());
|
||||
} else if child.is("utc", ns::TIME) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue