mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Use assertThrows() in Socks5ByteStreamManagerTest
This commit is contained in:
parent
839e347676
commit
58fc39714f
1 changed files with 41 additions and 61 deletions
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -140,21 +141,18 @@ public class Socks5ByteStreamManagerTest {
|
||||||
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
|
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
|
||||||
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
|
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
|
||||||
|
|
||||||
try {
|
FeatureNotSupportedException e = assertThrows(FeatureNotSupportedException.class, () -> {
|
||||||
// build empty discover info as reply if targets features are queried
|
// build empty discover info as reply if targets features are queried
|
||||||
DiscoverInfo discoverInfo = new DiscoverInfo();
|
DiscoverInfo discoverInfo = new DiscoverInfo();
|
||||||
protocol.addResponse(discoverInfo);
|
protocol.addResponse(discoverInfo);
|
||||||
|
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID);
|
byteStreamManager.establishSession(targetJID);
|
||||||
|
});
|
||||||
|
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (FeatureNotSupportedException e) {
|
|
||||||
assertTrue(e.getFeature().equals("SOCKS5 Bytestream"));
|
assertTrue(e.getFeature().equals("SOCKS5 Bytestream"));
|
||||||
assertTrue(e.getJid().equals(targetJID));
|
assertTrue(e.getJid().equals(targetJID));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if XMPP
|
||||||
|
@ -196,17 +194,16 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
|
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeGET);
|
Verification.requestTypeGET);
|
||||||
|
|
||||||
try {
|
SmackException e = assertThrows(SmackException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
|
||||||
fail("exception should be thrown");
|
fail("exception should be thrown");
|
||||||
}
|
});
|
||||||
catch (SmackException e) {
|
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
||||||
|
@ -261,17 +258,14 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
|
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeGET);
|
Verification.requestTypeGET);
|
||||||
|
|
||||||
try {
|
SmackException e = assertThrows(SmackException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
});
|
||||||
|
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (SmackException e) {
|
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if no
|
||||||
|
@ -325,16 +319,15 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
|
protocol.addResponse(proxyInfo, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeGET);
|
Verification.requestTypeGET);
|
||||||
|
|
||||||
try {
|
SmackException e = assertThrows(SmackException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
|
||||||
fail("exception should be thrown");
|
fail("exception should be thrown");
|
||||||
}
|
});
|
||||||
catch (SmackException e) {
|
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
||||||
}
|
|
||||||
|
|
||||||
/* retry to establish SOCKS5 Bytestream */
|
/* retry to establish SOCKS5 Bytestream */
|
||||||
|
|
||||||
|
@ -344,13 +337,10 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
|
protocol.addResponse(discoverItems, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeGET);
|
Verification.requestTypeGET);
|
||||||
|
|
||||||
try {
|
e = assertThrows(SmackException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
});
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (SmackException e) {
|
|
||||||
/*
|
/*
|
||||||
* #verifyAll() tests if the number of requests and responses corresponds and should
|
* #verifyAll() tests if the number of requests and responses corresponds and should
|
||||||
* fail if the invalid proxy is queried again
|
* fail if the invalid proxy is queried again
|
||||||
|
@ -358,7 +348,6 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
assertTrue(e.getMessage().contains("no SOCKS5 proxies available"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
||||||
|
@ -431,17 +420,14 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(rejectPacket, Verification.correspondingSenderReceiver,
|
protocol.addResponse(rejectPacket, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeSET);
|
Verification.requestTypeSET);
|
||||||
|
|
||||||
try {
|
XMPPErrorException e = assertThrows(XMPPErrorException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
});
|
||||||
|
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (XMPPErrorException e) {
|
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertEquals(rejectPacket.getError(), e.getStanzaError());
|
assertEquals(rejectPacket.getError(), e.getStanzaError());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if the
|
||||||
|
@ -516,17 +502,14 @@ public class Socks5ByteStreamManagerTest {
|
||||||
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
|
protocol.addResponse(streamHostUsedPacket, Verification.correspondingSenderReceiver,
|
||||||
Verification.requestTypeSET);
|
Verification.requestTypeSET);
|
||||||
|
|
||||||
try {
|
SmackException e = assertThrows(SmackException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
});
|
||||||
|
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (SmackException e) {
|
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
assertTrue(e.getMessage().contains("Remote user responded with unknown host"));
|
assertTrue(e.getMessage().contains("Remote user responded with unknown host"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should fail if
|
||||||
|
@ -609,19 +592,16 @@ public class Socks5ByteStreamManagerTest {
|
||||||
|
|
||||||
}, Verification.correspondingSenderReceiver, Verification.requestTypeSET);
|
}, Verification.correspondingSenderReceiver, Verification.requestTypeSET);
|
||||||
|
|
||||||
try {
|
IOException e = assertThrows(IOException.class, () -> {
|
||||||
// start SOCKS5 Bytestream
|
// start SOCKS5 Bytestream
|
||||||
byteStreamManager.establishSession(targetJID, sessionID);
|
byteStreamManager.establishSession(targetJID, sessionID);
|
||||||
|
});
|
||||||
|
|
||||||
fail("exception should be thrown");
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
// initiator can't connect to proxy because it is not running
|
// initiator can't connect to proxy because it is not running
|
||||||
protocol.verifyAll();
|
protocol.verifyAll();
|
||||||
Throwable actualCause = e.getCause().getCause();
|
Throwable actualCause = e.getCause().getCause();
|
||||||
assertEquals(ConnectException.class, actualCause.getClass());
|
assertEquals(ConnectException.class, actualCause.getClass());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully
|
* Invoking {@link Socks5BytestreamManager#establishSession(org.jxmpp.jid.Jid, String)} should successfully
|
||||||
|
|
Loading…
Reference in a new issue