1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-08 06:01:07 +01:00

Reworked Smack initialization

Move extension relevant configuration options from SmackConfiguration to
the extension. Introduced disabledSmackClasses that can be configured
via a system property or configuration file.
This commit is contained in:
Florian Schmaus 2014-02-23 17:48:07 +01:00
parent 4121ec2c0e
commit 3093333533
11 changed files with 193 additions and 338 deletions

View file

@ -25,7 +25,6 @@ import java.io.OutputStream;
import java.net.ConnectException;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
@ -169,7 +168,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldFailIfNoSocks5ProxyFound1() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -220,7 +219,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldFailIfNoSocks5ProxyFound2() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -284,7 +283,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldBlacklistNonSocks5Proxies() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -375,7 +374,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldFailIfTargetDoesNotAcceptSocks5Bytestream() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -465,7 +464,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldFailIfTargetUsesInvalidSocks5Proxy() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -547,7 +546,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldFailIfInitiatorCannotConnectToSocks5Proxy() {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -641,7 +640,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldNegotiateSocks5BytestreamAndTransferData() throws Exception {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -754,8 +753,8 @@ public class Socks5ByteStreamManagerTest {
public void shouldUseMultipleAddressesForLocalSocks5Proxy() throws Exception {
// enable clients local SOCKS5 proxy on port 7778
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
SmackConfiguration.setLocalSocks5ProxyPort(7778);
Socks5Proxy.setLocalSocks5ProxyEnabled(true);
Socks5Proxy.setLocalSocks5ProxyPort(7778);
// start a local SOCKS5 proxy
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
@ -837,7 +836,7 @@ public class Socks5ByteStreamManagerTest {
// reset proxy settings
socks5Proxy.stop();
socks5Proxy.removeLocalAddress("localAddress");
SmackConfiguration.setLocalSocks5ProxyPort(7777);
Socks5Proxy.setLocalSocks5ProxyPort(7777);
}
@ -852,7 +851,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldPrioritizeSecondSocks5ProxyOnSecondAttempt() throws Exception {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -935,7 +934,7 @@ public class Socks5ByteStreamManagerTest {
public void shouldNotPrioritizeSocks5ProxyIfPrioritizationDisabled() throws Exception {
// disable clients local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
// get Socks5ByteStreamManager for connection
Socks5BytestreamManager byteStreamManager = Socks5BytestreamManager.getBytestreamManager(connection);
@ -1093,7 +1092,7 @@ public class Socks5ByteStreamManagerTest {
@After
public void cleanUp() {
Socks5TestProxy.stopProxy();
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
Socks5Proxy.setLocalSocks5ProxyEnabled(true);
}
}

View file

@ -24,7 +24,6 @@ import java.net.ServerSocket;
import java.net.Socket;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
@ -427,7 +426,7 @@ public class Socks5ByteStreamRequestTest {
@After
public void cleanUp() {
Socks5TestProxy.stopProxy();
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
Socks5Proxy.setLocalSocks5ProxyEnabled(true);
}
}

View file

@ -23,7 +23,6 @@ import java.io.OutputStream;
import java.net.Socket;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
@ -87,7 +86,7 @@ public class Socks5ClientForInitiatorTest {
public void shouldFailIfTargetIsNotConnectedToLocalSocks5Proxy() throws Exception {
// start a local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyPort(proxyPort);
Socks5Proxy.setLocalSocks5ProxyPort(proxyPort);
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
socks5Proxy.start();
@ -125,7 +124,7 @@ public class Socks5ClientForInitiatorTest {
public void shouldSuccessfullyConnectThroughLocalSocks5Proxy() throws Exception {
// start a local SOCKS5 proxy
SmackConfiguration.setLocalSocks5ProxyPort(proxyPort);
Socks5Proxy.setLocalSocks5ProxyPort(proxyPort);
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
socks5Proxy.start();
@ -308,7 +307,7 @@ public class Socks5ClientForInitiatorTest {
*/
@After
public void cleanup() {
SmackConfiguration.setLocalSocks5ProxyPort(7777);
Socks5Proxy.setLocalSocks5ProxyPort(7777);
}
}

View file

@ -32,7 +32,6 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.SmackConfiguration;
import org.junit.After;
import org.junit.Test;
@ -48,7 +47,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldBeASingleton() {
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
Socks5Proxy proxy1 = Socks5Proxy.getSocks5Proxy();
Socks5Proxy proxy2 = Socks5Proxy.getSocks5Proxy();
@ -63,7 +62,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldNotBeRunningIfDisabled() {
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
assertFalse(proxy.isRunning());
}
@ -75,12 +74,12 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldUseFreePortOnNegativeValues() throws Exception {
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
Socks5Proxy.setLocalSocks5ProxyEnabled(false);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
assertFalse(proxy.isRunning());
ServerSocket serverSocket = new ServerSocket(0);
SmackConfiguration.setLocalSocks5ProxyPort(-serverSocket.getLocalPort());
Socks5Proxy.setLocalSocks5ProxyPort(-serverSocket.getLocalPort());
proxy.start();
@ -155,7 +154,7 @@ public class Socks5ProxyTest {
public void shouldOnlyStartOneServerThread() {
int threadCount = Thread.activeCount();
SmackConfiguration.setLocalSocks5ProxyPort(7890);
Socks5Proxy.setLocalSocks5ProxyPort(7890);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
proxy.start();
@ -189,7 +188,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldCloseSocketIfNoSocks5Request() throws Exception {
SmackConfiguration.setLocalSocks5ProxyPort(7890);
Socks5Proxy.setLocalSocks5ProxyPort(7890);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
proxy.start();
@ -219,7 +218,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldRespondWithErrorIfNoSupportedAuthenticationMethod() throws Exception {
SmackConfiguration.setLocalSocks5ProxyPort(7890);
Socks5Proxy.setLocalSocks5ProxyPort(7890);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
proxy.start();
@ -249,7 +248,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldRespondWithErrorIfConnectionIsNotAllowed() throws Exception {
SmackConfiguration.setLocalSocks5ProxyPort(7890);
Socks5Proxy.setLocalSocks5ProxyPort(7890);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
proxy.start();
@ -290,7 +289,7 @@ public class Socks5ProxyTest {
*/
@Test
public void shouldSuccessfullyEstablishConnection() throws Exception {
SmackConfiguration.setLocalSocks5ProxyPort(7890);
Socks5Proxy.setLocalSocks5ProxyPort(7890);
Socks5Proxy proxy = Socks5Proxy.getSocks5Proxy();
proxy.start();
@ -355,8 +354,8 @@ public class Socks5ProxyTest {
*/
@After
public void cleanup() {
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
SmackConfiguration.setLocalSocks5ProxyPort(7777);
Socks5Proxy.setLocalSocks5ProxyEnabled(true);
Socks5Proxy.setLocalSocks5ProxyPort(7777);
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
try {
String address = InetAddress.getLocalHost().getHostAddress();