forked from igniterealtime/Smack
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[caps] Additional test that asserts CAPS dataform ordering
XEP-0115 defines that any dataforms in the disco#info stanza is ordered prior to the computation of the verification string. This commit adds a test that verifies that this is done by Smack. See SMACK-944.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,41 @@ | |
|
||
public class EntityCapsManagerTest extends SmackTestSuite { | ||
|
||
/** | ||
* <a href="https://xmpp.org/extensions/xep-0115.html#ver-gen-simple">XEP- | ||
* 0115 Simple Generation Example</a>. | ||
* @throws XmppStringprepException if the provided string is invalid. | ||
*/ | ||
@Test | ||
public void testSimpleGenerationExample() throws XmppStringprepException { | ||
DiscoverInfo di = createSimpleSamplePacket(); | ||
|
||
CapsVersionAndHash versionAndHash = EntityCapsManager.generateVerificationString(di, StringUtils.SHA1); | ||
assertEquals("QgayPKawpkPSDYmwT/WM94uAlu0=", versionAndHash.version); | ||
} | ||
|
||
/** | ||
* Asserts that the order in which data forms are present in the disco/info does not affect the calculated | ||
* verification string, as the XEP mandates that these are ordered by FORM_TYPE (i.e., by the XML character data of | ||
* the <value/> element). | ||
* @throws XmppStringprepException if the provided string is invalid. | ||
*/ | ||
@Test | ||
public void testReversedDataFormOrder() throws XmppStringprepException { | ||
final DiscoverInfoBuilder builderA = createSimpleSampleBuilder(); | ||
builderA.addExtension(createSampleServerInfoDataForm()); // This works, as the underlying MultiMap maintains insertion-order. | ||
builderA.addExtension(createSampleSoftwareInfoDataForm()); | ||
|
||
final DiscoverInfoBuilder builderB = createSimpleSampleBuilder(); | ||
builderB.addExtension(createSampleSoftwareInfoDataForm()); | ||
builderB.addExtension(createSampleServerInfoDataForm()); | ||
|
||
CapsVersionAndHash versionAndHashA = EntityCapsManager.generateVerificationString(builderA.build(), StringUtils.SHA1); | ||
CapsVersionAndHash versionAndHashB = EntityCapsManager.generateVerificationString(builderB.build(), StringUtils.SHA1); | ||
|
||
assertEquals(versionAndHashA.version, versionAndHashB.version); | ||
} | ||
|
||
/** | ||
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-gen-complex">XEP- | ||
* 0115 Complex Generation Example</a>. | ||
|
@@ -142,6 +177,41 @@ private static DataForm createSampleSoftwareInfoDataForm() { | |
return df.build(); | ||
} | ||
|
||
private static DataForm createSampleServerInfoDataForm() { | ||
DataForm.Builder df = DataForm.builder(DataForm.Type.result); | ||
|
||
{ | ||
TextMultiFormField.Builder ff = FormField.textMultiBuilder("admin-addresses"); | ||
ff.addValue("xmpp:[email protected]"); | ||
ff.addValue("mailto:[email protected]"); | ||
df.addField(ff.build()); | ||
} | ||
|
||
{ | ||
TextSingleFormField.Builder ff = FormField.hiddenBuilder("FORM_TYPE"); | ||
ff.setValue("http://jabber.org/network/serverinfo"); | ||
df.addField(ff.build()); | ||
} | ||
|
||
return df.build(); | ||
} | ||
|
||
private static DiscoverInfoBuilder createSimpleSampleBuilder() throws XmppStringprepException { | ||
DiscoverInfoBuilder di = DiscoverInfo.builder("disco1"); | ||
di.ofType(IQ.Type.result); | ||
|
||
di.addIdentity(new DiscoverInfo.Identity("client", "Exodus 0.9.1", "pc")); | ||
di.addFeature("http://jabber.org/protocol/disco#info"); | ||
di.addFeature("http://jabber.org/protocol/disco#items"); | ||
di.addFeature("http://jabber.org/protocol/muc"); | ||
di.addFeature("http://jabber.org/protocol/caps"); | ||
|
||
return di; | ||
} | ||
private static DiscoverInfo createSimpleSamplePacket() throws XmppStringprepException { | ||
return createSimpleSampleBuilder().build(); | ||
} | ||
|
||
private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException { | ||
DiscoverInfoBuilder di = DiscoverInfo.builder("disco1"); | ||
di.from(JidCreate.from("[email protected]/230193")); | ||
|