1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-10 14:16:00 +01:00

Improve shouldFailIfInitiatorCannotConnectToSocks5Proxy() unit test

If run in parallel with other unit tests, especially onces that open
up a proxy, this test could fail, because another unit test actually
had an proxy running on the very address this unit test assumes to be
no proxy running.

We now use an IP address from RFC 5737's TEST-NET-1 address block,
which should never be available.
This commit is contained in:
Florian Schmaus 2019-07-04 15:49:47 +02:00
parent 1b5a264d52
commit f3b856c80b

View file

@ -28,7 +28,6 @@ import static org.mockito.Mockito.mock;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.List;
@ -521,17 +520,24 @@ public class Socks5ByteStreamManagerTest {
* @throws InterruptedException
* @throws SmackException
* @throws XMPPException
* @throws XmppStringprepException
*/
@Test
public void shouldFailIfInitiatorCannotConnectToSocks5Proxy()
throws SmackException, InterruptedException, XMPPException {
throws SmackException, InterruptedException, XMPPException, XmppStringprepException {
final Protocol protocol = new Protocol();
final XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID);
final String sessionID = "session_id_shouldFailIfInitiatorCannotConnectToSocks5Proxy";
// TODO: The following two variables should be named initatorProxyJid and initiatorProxyAddress.
final DomainBareJid proxyJID = JidCreate.domainBareFrom("s5b-proxy.initiator.org");
// Use an TEST-NET-1 address from RFC 5737 to act as black hole.
final String proxyAddress = "192.0.2.1";
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
byteStreamManager.setAnnounceLocalStreamHost(false);
byteStreamManager.setProxyConnectionTimeout(3000);
/**
* create responses in the order they should be queried specified by the XEP-0065
@ -602,8 +608,9 @@ public class Socks5ByteStreamManagerTest {
// initiator can't connect to proxy because it is not running
protocol.verifyAll();
Throwable actualCause = e.getCause().getCause();
assertEquals("Unexpected throwable: " + actualCause + '.' + ExceptionUtil.getStackTrace(actualCause), ConnectException.class, actualCause.getClass());
Throwable actualCause = e.getCause();
assertEquals("Unexpected throwable: " + actualCause + '.' + ExceptionUtil.getStackTrace(actualCause),
TimeoutException.class, actualCause.getClass());
}
/**