mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 01:59:38 +02:00
Use Jid (and subclasses) from jxmpp-jid
Fixes SMACK-634
This commit is contained in:
parent
0ee2d9ed1e
commit
5bb4727c57
180 changed files with 1510 additions and 1032 deletions
|
@ -27,6 +27,10 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.PlainStreamElement;
|
||||
import org.jivesoftware.smack.packet.TopLevelStreamElement;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
* A dummy implementation of {@link XMPPConnection}, intended to be used during
|
||||
|
@ -51,7 +55,7 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
private final BlockingQueue<TopLevelStreamElement> queue = new LinkedBlockingQueue<TopLevelStreamElement>();
|
||||
|
||||
public static ConnectionConfiguration.Builder<?,?> getDummyConfigurationBuilder() {
|
||||
return DummyConnectionConfiguration.builder().setServiceName("example.org").setUsernameAndPassword("dummy",
|
||||
return DummyConnectionConfiguration.builder().setServiceName(JidTestUtil.EXAMPLE_ORG).setUsernameAndPassword("dummy",
|
||||
"dummypass");
|
||||
}
|
||||
|
||||
|
@ -59,17 +63,26 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
this(getDummyConfigurationBuilder().build());
|
||||
}
|
||||
|
||||
private FullJid getUserJid() {
|
||||
try {
|
||||
return JidCreate.fullFrom(config.getUsername()
|
||||
+ "@"
|
||||
+ config.getServiceName()
|
||||
+ "/"
|
||||
+ (config.getResource() != null ? config.getResource() : "Test"));
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public DummyConnection(ConnectionConfiguration configuration) {
|
||||
super(configuration);
|
||||
|
||||
for (ConnectionCreationListener listener : XMPPConnectionRegistry.getConnectionCreationListeners()) {
|
||||
listener.connectionCreated(this);
|
||||
}
|
||||
user = config.getUsername()
|
||||
+ "@"
|
||||
+ config.getServiceName()
|
||||
+ "/"
|
||||
+ (config.getResource() != null ? config.getResource() : "Test");
|
||||
user = getUserJid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,11 +117,7 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
@Override
|
||||
protected void loginNonAnonymously(String username, String password, String resource)
|
||||
throws XMPPException {
|
||||
user = username
|
||||
+ "@"
|
||||
+ config.getServiceName()
|
||||
+ "/"
|
||||
+ (resource != null ? resource : "Test");
|
||||
user = getUserJid();
|
||||
authenticated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ import static org.junit.Assert.assertFalse;
|
|||
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -29,16 +32,16 @@ import org.junit.Test;
|
|||
*
|
||||
*/
|
||||
public class FromMatchesFilterTest {
|
||||
private static final String BASE_JID1 = "ss@muc.myserver.com";
|
||||
private static final String FULL_JID1_R1 = BASE_JID1 + "/resource";
|
||||
private static final String FULL_JID1_R2 = BASE_JID1 + "/resource2";
|
||||
private static final String BASE_JID2 = "sss@muc.myserver.com";
|
||||
private static final String FULL_JID2 = BASE_JID2 + "/resource";
|
||||
private static final Jid BASE_JID1 = JidTestUtil.BARE_JID_1;
|
||||
private static final FullJid FULL_JID1_R1 = JidTestUtil.FULL_JID_1_RESOURCE_1;
|
||||
private static final FullJid FULL_JID1_R2 = JidTestUtil.FULL_JID_1_RESOURCE_2;
|
||||
private static final Jid BASE_JID2 = JidTestUtil.BARE_JID_2;
|
||||
private static final Jid FULL_JID2 = JidTestUtil.FULL_JID_2_RESOURCE_1;
|
||||
|
||||
private static final String BASE_JID3 = "ss@muc.myserver.comm.net";
|
||||
private static final Jid BASE_JID3 = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
|
||||
private static final String SERVICE_JID1 = "muc.myserver.com";
|
||||
private static final String SERVICE_JID2 = "pubsub.myserver.com";
|
||||
private static final Jid SERVICE_JID1 = JidTestUtil.MUC_EXAMPLE_ORG;
|
||||
private static final Jid SERVICE_JID2 = JidTestUtil.PUBSUB_EXAMPLE_ORG;
|
||||
|
||||
@Test
|
||||
public void autoCompareMatchingFullJid()
|
||||
|
|
|
@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
* Tests that verifies the correct behavior of creating result and error IQ packets.
|
||||
|
@ -36,12 +38,13 @@ public class IQResponseTest {
|
|||
|
||||
/**
|
||||
* Test creating a simple and empty IQ response.
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void testGeneratingSimpleResponse() {
|
||||
public void testGeneratingSimpleResponse() throws XmppStringprepException {
|
||||
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||
request.setFrom("sender@test/Smack");
|
||||
request.setTo("receiver@test/Smack");
|
||||
request.setFrom(JidCreate.from("sender@test/Smack"));
|
||||
request.setTo(JidCreate.from("receiver@test/Smack"));
|
||||
|
||||
final IQ result = IQ.createResultIQ(request);
|
||||
|
||||
|
@ -55,15 +58,16 @@ public class IQResponseTest {
|
|||
|
||||
/**
|
||||
* Test creating a error response based on an IQ request.
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void testGeneratingValidErrorResponse() {
|
||||
public void testGeneratingValidErrorResponse() throws XmppStringprepException {
|
||||
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
||||
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||
|
||||
request.setType(IQ.Type.set);
|
||||
request.setFrom("sender@test/Smack");
|
||||
request.setTo("receiver@test/Smack");
|
||||
request.setFrom(JidCreate.from("sender@test/Smack"));
|
||||
request.setTo(JidCreate.from("receiver@test/Smack"));
|
||||
|
||||
final IQ result = IQ.createErrorResponse(request, error);
|
||||
|
||||
|
@ -79,14 +83,15 @@ public class IQResponseTest {
|
|||
/**
|
||||
* According to <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq"
|
||||
* >RFC3920: IQ Semantics</a> we shouldn't respond to an IQ of type result.
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void testGeneratingResponseBasedOnResult() {
|
||||
public void testGeneratingResponseBasedOnResult() throws XmppStringprepException {
|
||||
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||
|
||||
request.setType(IQ.Type.result);
|
||||
request.setFrom("sender@test/Smack");
|
||||
request.setTo("receiver@test/Smack");
|
||||
request.setFrom(JidCreate.from("sender@test/Smack"));
|
||||
request.setTo(JidCreate.from("receiver@test/Smack"));
|
||||
|
||||
try {
|
||||
IQ.createResultIQ(request);
|
||||
|
@ -101,15 +106,16 @@ public class IQResponseTest {
|
|||
/**
|
||||
* According to <a href="http://xmpp.org/rfcs/rfc3920.html#stanzas-semantics-iq"
|
||||
* >RFC3920: IQ Semantics</a> we shouldn't respond to an IQ of type error.
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test
|
||||
public void testGeneratingErrorBasedOnError() {
|
||||
public void testGeneratingErrorBasedOnError() throws XmppStringprepException {
|
||||
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
|
||||
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
|
||||
|
||||
request.setType(IQ.Type.error);
|
||||
request.setFrom("sender@test/Smack");
|
||||
request.setTo("receiver@test/Smack");
|
||||
request.setFrom(JidCreate.from("sender@test/Smack"));
|
||||
request.setTo(JidCreate.from("receiver@test/Smack"));
|
||||
request.setError(error);
|
||||
|
||||
try {
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Map;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public class DigestMd5SaslTest extends AbstractSaslTest {
|
||||
|
||||
|
@ -35,8 +37,8 @@ public class DigestMd5SaslTest extends AbstractSaslTest {
|
|||
super(saslMechanism);
|
||||
}
|
||||
|
||||
protected void runTest() throws NotConnectedException, SmackException, InterruptedException {
|
||||
saslMechanism.authenticate("florian", "irrelevant", "xmpp.org", "secret");
|
||||
protected void runTest() throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException {
|
||||
saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret");
|
||||
|
||||
byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
|
||||
String responseString = new String(response);
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jivesoftware.smack.test.util.SmackTestSuite;
|
|||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
public class SCRAMSHA1MechanismTest {
|
||||
|
||||
|
@ -53,7 +54,7 @@ public class SCRAMSHA1MechanismTest {
|
|||
}
|
||||
};
|
||||
|
||||
mech.authenticate(USERNAME, "unusedFoo", "unusedBar", PASSWORD);
|
||||
mech.authenticate(USERNAME, "unusedFoo", JidTestUtil.DOMAIN_BARE_JID_1, PASSWORD);
|
||||
AuthMechanism authMechanism = con.getSentPacket();
|
||||
assertEquals(SCRAMSHA1Mechanism.NAME, authMechanism.getMechanism());
|
||||
assertEquals(CLIENT_FIRST_MESSAGE, saslLayerString(authMechanism.getAuthenticationText()));
|
||||
|
|
|
@ -43,7 +43,7 @@ public class WaitForPacketListener implements PacketListener {
|
|||
|
||||
public void waitUntilInvocationOrTimeout() {
|
||||
try {
|
||||
boolean res = latch.await(30, TimeUnit.SECONDS);
|
||||
boolean res = latch.await(300, TimeUnit.SECONDS);
|
||||
if (!res) {
|
||||
throw new IllegalStateException("Latch timed out before it reached zero");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue