use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ByteStreamManagerTest 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);
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ByteStreamRequestTest 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, targetJID, xmppServer);
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class InBandBytestreamSessionTest method setup.
/**
* Initialize fields used in the tests.
* @throws XMPPException if an XMPP protocol error was received.
* @throws SmackException if Smack detected an exceptional situation.
* @throws InterruptedException if the calling thread was interrupted.
*/
@BeforeEach
public void setup() throws XMPPException, SmackException, InterruptedException {
// build protocol verifier
protocol = new Protocol();
// create mocked XMPP connection
connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
// create a In-Band Bytestream open packet
initBytestream = new Open(sessionID, blockSize);
initBytestream.setFrom(initiatorJID);
initBytestream.setTo(targetJID);
incrementingSequence = new Verification<Data, IQ>() {
int lastSeq = 0;
@Override
public void verify(Data request, IQ response) {
assertEquals(lastSeq++, request.getDataPacketExtension().getSeq().intValue());
}
};
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ByteStreamManagerTest method shouldFailIfTargetDoesNotSupportSocks5.
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid)} should throw an exception
* if the given target does not support SOCKS5 Bytestream.
* @throws XMPPException if an XMPP protocol error was received.
* @throws InterruptedException if the calling thread was interrupted.
* @throws SmackException if Smack detected an exceptional situation.
* @throws IOException if an I/O error occurred.
*/
@Test
public void shouldFailIfTargetDoesNotSupportSocks5() throws XMPPException, SmackException, InterruptedException, IOException {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
FeatureNotSupportedException e = assertThrows(FeatureNotSupportedException.class, () -> {
// build empty discover info as reply if targets features are queried
DiscoverInfo discoverInfo = DiscoverInfo.builder("disco-1").build();
protocol.addResponse(discoverInfo);
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID);
});
assertTrue(e.getFeature().equals("SOCKS5 Bytestream"));
assertTrue(e.getJid().equals(targetJID));
}
use of org.jivesoftware.util.Protocol in project Smack by igniterealtime.
the class Socks5ByteStreamManagerTest method shouldFailIfNoSocks5ProxyFound2.
/**
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
* proxy is a SOCKS5 proxy.
*
* @throws InterruptedException if the calling thread was interrupted.
* @throws SmackException if Smack detected an exceptional situation.
* @throws XMPPException if an XMPP protocol error was received.
* @throws IOException if an I/O error occurred.
*/
@Test
public void shouldFailIfNoSocks5ProxyFound2() throws SmackException, InterruptedException, IOException, XMPPException {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
final String sessionID = "session_id_shouldFailIfNoSocks5ProxyFound2";
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
byteStreamManager.setAnnounceLocalStreamHost(false);
/**
* create responses in the order they should be queried specified by the XEP-0065
* specification
*/
// build discover info that supports the SOCKS5 feature
DiscoverInfoBuilder discoverInfo = Socks5PacketUtils.createDiscoverInfo(targetJID, initiatorJID);
discoverInfo.addFeature(Bytestream.NAMESPACE);
// return that SOCKS5 is supported if target is queried
protocol.addResponse(discoverInfo.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build discover items containing a proxy item
DiscoverItems discoverItems = Socks5PacketUtils.createDiscoverItems(xmppServer, initiatorJID);
Item item = new Item(proxyJID);
discoverItems.addItem(item);
// return the proxy item if XMPP server is queried
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver, Verification.requestTypeGET);
// build discover info for proxy containing information about NOT being a Socks5
// proxy
DiscoverInfoBuilder proxyInfo = Socks5PacketUtils.createDiscoverInfo(proxyJID, initiatorJID);
Identity identity = new Identity("noproxy", proxyJID.toString(), "bytestreams");
proxyInfo.addIdentity(identity);
// return the proxy identity if proxy is queried
protocol.addResponse(proxyInfo.build(), Verification.correspondingSenderReceiver, Verification.requestTypeGET);
SmackException e = assertThrows(SmackException.class, () -> {
// start SOCKS5 Bytestream
byteStreamManager.establishSession(targetJID, sessionID);
});
protocol.verifyAll();
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
}
Aggregations