use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.
the class Socks5ByteStreamRequestTest method shouldNotBlacklistInvalidProxy.
/**
* Target should not not blacklist any SOCKS5 proxies regardless of failing connections.
*
* @throws Exception should not happen
*/
@Test
public void shouldNotBlacklistInvalidProxy() throws Exception {
// disable blacklisting
Socks5BytestreamRequest.setConnectFailureThreshold(0);
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(initiatorJID, targetJID, sessionID);
bytestreamInitialization.addStreamHost(JidCreate.from("invalid." + proxyJID), "127.0.0.2", 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
// try to connect several times
for (int i = 0; i < 10; i++) {
try {
// build SOCKS5 Bytestream request with the bytestream initialization
Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(byteStreamManager, bytestreamInitialization);
// set timeouts
byteStreamRequest.setTotalConnectTimeout(600);
byteStreamRequest.setMinimumConnectTimeout(300);
// accept the stream (this is the call that is tested here)
byteStreamRequest.accept();
fail("exception should be thrown");
} catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
}
// verify targets response
assertEquals(1, protocol.getRequests().size());
Stanza targetResponse = protocol.getRequests().remove(0);
assertTrue(IQ.class.isInstance(targetResponse));
assertEquals(initiatorJID, targetResponse.getTo());
assertEquals(IQ.Type.error, ((IQ) targetResponse).getType());
assertEquals(XMPPError.Condition.item_not_found, ((IQ) targetResponse).getError().getCondition());
}
// enable blacklisting
Socks5BytestreamRequest.setConnectFailureThreshold(2);
}
use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.
the class Socks5ByteStreamRequestTest method shouldFailIfRequestHasInvalidStreamHosts.
/**
* Accepting a SOCKS5 Bytestream request should fail if target is not able to connect to any of
* the provided SOCKS5 proxies.
*
* @throws Exception
*/
@Test
public void shouldFailIfRequestHasInvalidStreamHosts() throws Exception {
try {
// build SOCKS5 Bytestream initialization request
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(initiatorJID, targetJID, sessionID);
// add proxy that is not running
bytestreamInitialization.addStreamHost(proxyJID, proxyAddress, 7778);
// get SOCKS5 Bytestream manager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
// build SOCKS5 Bytestream request with the bytestream initialization
Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(byteStreamManager, bytestreamInitialization);
// accept the stream (this is the call that is tested here)
byteStreamRequest.accept();
fail("exception should be thrown");
} catch (XMPPErrorException e) {
assertTrue(e.getXMPPError().getDescriptiveText("en").contains("Could not establish socket with any provided host"));
}
// verify targets response
assertEquals(1, protocol.getRequests().size());
Stanza targetResponse = protocol.getRequests().remove(0);
assertTrue(IQ.class.isInstance(targetResponse));
assertEquals(initiatorJID, targetResponse.getTo());
assertEquals(IQ.Type.error, ((IQ) targetResponse).getType());
assertEquals(XMPPError.Condition.item_not_found, ((IQ) targetResponse).getError().getCondition());
}
use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.
the class Socks5ClientForInitiatorTest method shouldFailIfActivateSocks5ProxyFails.
/**
* If the initiator can connect to a SOCKS5 proxy but activating the stream fails an exception
* should be thrown.
*
* @throws Exception should not happen
*/
@Test
public void shouldFailIfActivateSocks5ProxyFails() throws Exception {
// build error response as reply to the stream activation
IQ error = new ErrorIQ(XMPPError.getBuilder(XMPPError.Condition.internal_server_error));
error.setFrom(proxyJID);
error.setTo(initiatorJID);
protocol.addResponse(error, Verification.correspondingSenderReceiver, Verification.requestTypeSET);
// start a local SOCKS5 proxy
Socks5TestProxy socks5Proxy = Socks5TestProxy.getProxy(proxyPort);
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID, loopbackAddress, socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(streamHost, digest, connection, sessionID, targetJID);
try {
socks5Client.getSocket(10000);
fail("exception should be thrown");
} catch (XMPPErrorException e) {
assertTrue(XMPPError.Condition.internal_server_error.equals(e.getXMPPError().getCondition()));
protocol.verifyAll();
}
socks5Proxy.stop();
}
use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project Smack by igniterealtime.
the class InBandBytestreamManagerTest method shouldFailIfTargetDoesNotSupportIBB.
/**
* Invoking {@link InBandBytestreamManager#establishSession(org.jxmpp.jid.Jid)} should
* throw an exception if the given target does not support in-band
* bytestream.
* @throws SmackException
* @throws XMPPException
* @throws InterruptedException
*/
@Test
public void shouldFailIfTargetDoesNotSupportIBB() throws SmackException, XMPPException, InterruptedException {
InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
try {
IQ errorIQ = IBBPacketUtils.createErrorIQ(targetJID, initiatorJID, XMPPError.Condition.feature_not_implemented);
protocol.addResponse(errorIQ);
// start In-Band Bytestream
byteStreamManager.establishSession(targetJID);
fail("exception should be thrown");
} catch (XMPPErrorException e) {
assertEquals(XMPPError.Condition.feature_not_implemented, e.getXMPPError().getCondition());
}
}
use of org.jivesoftware.smack.XMPPException.XMPPErrorException in project camel by apache.
the class XmppEndpoint method resolveRoom.
/*
* If there is no "@" symbol in the room, find the chat service JID and
* return fully qualified JID for the room as room@conference.server.domain
*/
public String resolveRoom(XMPPConnection connection) throws XMPPException, SmackException {
ObjectHelper.notEmpty(room, "room");
if (room.indexOf('@', 0) != -1) {
return room;
}
Iterator<String> iterator = MultiUserChat.getServiceNames(connection).iterator();
if (!iterator.hasNext()) {
throw new XMPPErrorException("Cannot find Multi User Chat service", new XMPPError(new XMPPError.Condition("Cannot find Multi User Chat service on connection: " + getConnectionMessage(connection))));
}
String chatServer = iterator.next();
LOG.debug("Detected chat server: {}", chatServer);
return room + "@" + chatServer;
}
Aggregations