use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ByteStreamRequestTest method shouldFailIfRequestHasNoStreamHosts.
/**
* Accepting a SOCKS5 Bytestream request should fail if the request doesn't contain any Socks5
* proxies.
*
* @throws Exception should not happen
*/
@Test
public void shouldFailIfRequestHasNoStreamHosts() throws Exception {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, targetJID);
assertThrows(Socks5Exception.NoSocks5StreamHostsProvided.class, () -> {
// build SOCKS5 Bytestream initialization request with no SOCKS5 proxies
Bytestream bytestreamInitialization = Socks5PacketUtils.createBytestreamInitiation(initiatorJID, targetJID, sessionID);
// 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();
});
// 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(StanzaError.Condition.item_not_found, targetResponse.getError().getCondition());
}
use of org.jivesoftware.util.Protocol 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 {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, targetJID);
// 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++) {
assertThrows(Socks5Exception.CouldNotConnectToAnyProvidedSocks5Host.class, () -> {
// build SOCKS5 Bytestream request with the bytestream initialization
Socks5BytestreamRequest byteStreamRequest = new Socks5BytestreamRequest(byteStreamManager, bytestreamInitialization);
// set timeouts
byteStreamRequest.setTotalConnectTimeout(600);
byteStreamRequest.setMinimumConnectTimeout(300);
byteStreamRequest.setConnectFailureThreshold(0);
// accept the stream (this is the call that is tested here)
byteStreamRequest.accept();
});
// 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(StanzaError.Condition.item_not_found, targetResponse.getError().getCondition());
}
}
use of org.jivesoftware.util.Protocol 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 if an exception occurs.
*/
@Test
public void shouldFailIfRequestHasInvalidStreamHosts() throws Exception {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, targetJID);
assertThrows(Socks5Exception.CouldNotConnectToAnyProvidedSocks5Host.class, () -> {
// 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();
});
// 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(StanzaError.Condition.item_not_found, targetResponse.getError().getCondition());
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class SoftwareInfoManagerTest method setup.
@BeforeEach
public void setup() throws XMPPException, SmackException, InterruptedException {
protocol = new Protocol();
connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ClientForInitiatorTest method setup.
/**
* Initialize fields used in the tests.
* @throws XMPPException
* @throws SmackException
* @throws InterruptedException
*/
@Before
public void setup() throws XMPPException, SmackException, InterruptedException {
// build protocol verifier
protocol = new Protocol();
// create mocked XMPP connection
connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);
}
Aggregations