1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-25 15:52:06 +01:00

Use loopback address for Socks5 unit tests

to prevent using an address that is not reachable for whatever reason.
This commit is contained in:
Florian Schmaus 2016-07-08 16:34:21 +02:00
parent 651f8cf7c0
commit d1fe5c2933
2 changed files with 13 additions and 10 deletions

View file

@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import org.jivesoftware.smack.SmackException;
@ -58,7 +59,8 @@ public class Socks5ClientForInitiatorTest {
static final EntityFullJid targetJID = JidTestUtil.FULL_JID_1_RESOURCE_1;
static final DomainBareJid xmppServer = JidTestUtil.DOMAIN_BARE_JID_1;
static final DomainBareJid proxyJID = JidTestUtil.MUC_EXAMPLE_ORG;
String proxyAddress = "127.0.0.1";
static final String loopbackAddress = InetAddress.getLoopbackAddress().getHostAddress();
int proxyPort = 7890;
String sessionID = "session_id";
@ -82,7 +84,6 @@ public class Socks5ClientForInitiatorTest {
// create mocked XMPP connection
connection = ConnectionUtils.createMockedConnection(protocol, initiatorJID, xmppServer);
}
/**
@ -100,7 +101,7 @@ public class Socks5ClientForInitiatorTest {
// build stream host information for local SOCKS5 proxy
StreamHost streamHost = new StreamHost(connection.getUser(),
socks5Proxy.getLocalAddresses().get(0),
loopbackAddress,
socks5Proxy.getPort());
// create digest to get the socket opened by target
@ -147,7 +148,7 @@ public class Socks5ClientForInitiatorTest {
// build stream host information
final StreamHost streamHost = new StreamHost(connection.getUser(),
socks5Proxy.getLocalAddresses().get(0),
loopbackAddress,
socks5Proxy.getPort());
// target connects to local SOCKS5 proxy
@ -213,7 +214,7 @@ public class Socks5ClientForInitiatorTest {
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID,
Socks5TestProxy.getAddress(), socks5Proxy.getPort());
loopbackAddress, socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);
@ -266,7 +267,7 @@ public class Socks5ClientForInitiatorTest {
socks5Proxy.start();
StreamHost streamHost = new StreamHost(proxyJID,
Socks5TestProxy.getAddress(), socks5Proxy.getPort());
loopbackAddress, socks5Proxy.getPort());
// create digest to get the socket opened by target
String digest = Socks5Utils.createDigest(sessionID, initiatorJID, targetJID);

View file

@ -42,6 +42,8 @@ import org.junit.Test;
*/
public class Socks5ProxyTest {
static final String loopbackAddress = InetAddress.getLoopbackAddress().getHostAddress();
/**
* The SOCKS5 proxy should be a singleton used by all XMPP connections.
*/
@ -199,7 +201,7 @@ public class Socks5ProxyTest {
proxy.start();
@SuppressWarnings("resource")
Socket socket = new Socket(proxy.getLocalAddresses().get(0), proxy.getPort());
Socket socket = new Socket(loopbackAddress, proxy.getPort());
OutputStream out = socket.getOutputStream();
out.write(new byte[] { 1, 2, 3 });
@ -230,7 +232,7 @@ public class Socks5ProxyTest {
proxy.start();
@SuppressWarnings("resource")
Socket socket = new Socket(proxy.getLocalAddresses().get(0), proxy.getPort());
Socket socket = new Socket(loopbackAddress, proxy.getPort());
OutputStream out = socket.getOutputStream();
@ -261,7 +263,7 @@ public class Socks5ProxyTest {
proxy.start();
@SuppressWarnings("resource")
Socket socket = new Socket(proxy.getLocalAddresses().get(0), proxy.getPort());
Socket socket = new Socket(loopbackAddress, proxy.getPort());
OutputStream out = socket.getOutputStream();
out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x00 });
@ -309,7 +311,7 @@ public class Socks5ProxyTest {
proxy.addTransfer(digest);
@SuppressWarnings("resource")
Socket socket = new Socket(proxy.getLocalAddresses().get(0), proxy.getPort());
Socket socket = new Socket(loopbackAddress, proxy.getPort());
OutputStream out = socket.getOutputStream();
out.write(new byte[] { (byte) 0x05, (byte) 0x01, (byte) 0x00 });