From f3b856c80bd04bc088d91d369be89e0ef964cad8 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 4 Jul 2019 15:49:47 +0200 Subject: [PATCH] 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. --- .../socks5/Socks5ByteStreamManagerTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java index 0564f29f2..0b297c1ad 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/bytestreams/socks5/Socks5ByteStreamManagerTest.java @@ -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()); } /**