mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
[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.
This commit is contained in:
parent
95adfb3cdf
commit
a1e85d644f
1 changed files with 70 additions and 0 deletions
|
@ -47,6 +47,41 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
|||
|
||||
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 @@ public class EntityCapsManagerTest extends SmackTestSuite {
|
|||
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:admin@example.org");
|
||||
ff.addValue("mailto:admin@example.com");
|
||||
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("benvolio@capulet.lit/230193"));
|
||||
|
|
Loading…
Reference in a new issue