summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java')
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java97
1 files changed, 74 insertions, 23 deletions
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
index a9303c264e..54826b8c88 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/model/adapter/PortFactoryTest.java
@@ -22,8 +22,8 @@ package org.apache.qpid.server.model.adapter;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.any;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -36,6 +36,7 @@ import java.util.UUID;
import org.apache.qpid.server.configuration.BrokerProperties;
import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.Port;
@@ -47,8 +48,6 @@ import org.apache.qpid.test.utils.QpidTestCase;
public class PortFactoryTest extends QpidTestCase
{
private UUID _portId = UUID.randomUUID();
- private UUID _keyStoreId = UUID.randomUUID();
- private UUID _trustStoreId = UUID.randomUUID();
private int _portNumber = 123;
private Set<String> _tcpStringSet = Collections.singleton(Transport.TCP.name());
private Set<Transport> _tcpTransportSet = Collections.singleton(Transport.TCP);
@@ -60,19 +59,22 @@ public class PortFactoryTest extends QpidTestCase
private Broker _broker = mock(Broker.class);
private KeyStore _keyStore = mock(KeyStore.class);
private TrustStore _trustStore = mock(TrustStore.class);
-
+ private String _authProviderName = "authProvider";
+ private AuthenticationProvider _authProvider = mock(AuthenticationProvider.class);
private PortFactory _portFactory;
@Override
protected void setUp() throws Exception
{
+ when(_broker.findAuthenticationProviderByName(_authProviderName)).thenReturn(_authProvider);
+
setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null);
setTestSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null);
_portFactory = new PortFactory();
_attributes.put(Port.PORT, _portNumber);
_attributes.put(Port.TRANSPORTS, _tcpStringSet);
-
+ _attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName);
_attributes.put(Port.TCP_NO_DELAY, "true");
_attributes.put(Port.RECEIVE_BUFFER_SIZE, "1");
_attributes.put(Port.SEND_BUFFER_SIZE, "2");
@@ -113,6 +115,7 @@ public class PortFactoryTest extends QpidTestCase
{
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(Port.PORT, 1);
+ attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName);
Port port = _portFactory.createPort(_portId, _broker, attributes);
assertNotNull(port);
@@ -134,15 +137,14 @@ public class PortFactoryTest extends QpidTestCase
public void testCreateAmqpPort()
{
- createAmqpPortTestImpl(false,false,false);
+ createAmqpPortTestImpl(false, false, false, null, null);
}
public void testCreateAmqpPortUsingSslFailsWithoutKeyStore()
{
- when(_broker.getKeyStores()).thenReturn(new ArrayList<KeyStore>());
try
{
- createAmqpPortTestImpl(true,false,false);
+ createAmqpPortTestImpl(true, false, false, null, null);
fail("expected exception due to lack of SSL keystore");
}
catch(IllegalConfigurationException e)
@@ -153,18 +155,22 @@ public class PortFactoryTest extends QpidTestCase
public void testCreateAmqpPortUsingSslSucceedsWithKeyStore()
{
- when(_broker.getKeyStores()).thenReturn(Collections.singleton(_keyStore));
+ String keyStoreName = "myKeyStore";
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
- createAmqpPortTestImpl(true,false,false);
+ createAmqpPortTestImpl(true, false, false, keyStoreName, null);
}
public void testCreateAmqpPortNeedingClientAuthFailsWithoutTrustStore()
{
- when(_broker.getKeyStores()).thenReturn(Collections.singleton(_keyStore));
- when(_broker.getTrustStores()).thenReturn(new ArrayList<TrustStore>());
+ String keyStoreName = "myKeyStore";
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
+
+ when(_broker.findTrustStoreByName(any(String.class))).thenReturn(null);
+
try
{
- createAmqpPortTestImpl(true,true,false);
+ createAmqpPortTestImpl(true, true, false, keyStoreName, null);
fail("expected exception due to lack of SSL truststore");
}
catch(IllegalConfigurationException e)
@@ -175,19 +181,23 @@ public class PortFactoryTest extends QpidTestCase
public void testCreateAmqpPortNeedingClientAuthSucceedsWithTrustStore()
{
- when(_broker.getKeyStores()).thenReturn(Collections.singleton(_keyStore));
- when(_broker.getTrustStores()).thenReturn(Collections.singleton(_trustStore));
+ String keyStoreName = "myKeyStore";
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
+
+ String trustStoreName = "myTrustStore";
+ when(_broker.findTrustStoreByName(trustStoreName)).thenReturn(_trustStore);
- createAmqpPortTestImpl(true,true,false);
+ createAmqpPortTestImpl(true, true, false, keyStoreName, new String[]{trustStoreName});
}
public void testCreateAmqpPortWantingClientAuthFailsWithoutTrustStore()
{
- when(_broker.getKeyStores()).thenReturn(Collections.singleton(_keyStore));
- when(_broker.getTrustStores()).thenReturn(new ArrayList<TrustStore>());
+ String keyStoreName = "myKeyStore";
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
+
try
{
- createAmqpPortTestImpl(true,false,true);
+ createAmqpPortTestImpl(true, false, true, keyStoreName, null);
fail("expected exception due to lack of SSL truststore");
}
catch(IllegalConfigurationException e)
@@ -198,13 +208,17 @@ public class PortFactoryTest extends QpidTestCase
public void testCreateAmqpPortWantingClientAuthSucceedsWithTrustStore()
{
- when(_broker.getKeyStores()).thenReturn(Collections.singleton(_keyStore));
- when(_broker.getTrustStores()).thenReturn(Collections.singleton(_trustStore));
+ String keyStoreName = "myKeyStore";
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
+
+ String trustStoreName = "myTrustStore";
+ when(_broker.findTrustStoreByName(trustStoreName)).thenReturn(_trustStore);
- createAmqpPortTestImpl(true,false,true);
+ createAmqpPortTestImpl(true, false, true, keyStoreName, new String[]{trustStoreName});
}
- public void createAmqpPortTestImpl(boolean useSslTransport, boolean needClientAuth, boolean wantClientAuth)
+ public void createAmqpPortTestImpl(boolean useSslTransport, boolean needClientAuth, boolean wantClientAuth,
+ String keystoreName, String[] trustStoreNames)
{
Set<Protocol> amqp010ProtocolSet = Collections.singleton(Protocol.AMQP_0_10);
Set<String> amqp010StringSet = Collections.singleton(Protocol.AMQP_0_10.name());
@@ -225,6 +239,16 @@ public class PortFactoryTest extends QpidTestCase
_attributes.put(Port.WANT_CLIENT_AUTH, "true");
}
+ if(keystoreName != null)
+ {
+ _attributes.put(Port.KEY_STORE, keystoreName);
+ }
+
+ if(trustStoreNames != null)
+ {
+ _attributes.put(Port.TRUST_STORES, Arrays.asList(trustStoreNames));
+ }
+
Port port = _portFactory.createPort(_portId, _broker, _attributes);
assertNotNull(port);
@@ -254,6 +278,7 @@ public class PortFactoryTest extends QpidTestCase
Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
_attributes = new HashMap<String, Object>();
_attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName);
_attributes.put(Port.PORT, _portNumber);
_attributes.put(Port.TRANSPORTS, _tcpStringSet);
@@ -279,6 +304,7 @@ public class PortFactoryTest extends QpidTestCase
Set<String> nonAmqpStringSet = Collections.singleton(Protocol.JMX_RMI.name());
_attributes = new HashMap<String, Object>();
_attributes.put(Port.PROTOCOLS, nonAmqpStringSet);
+ _attributes.put(Port.AUTHENTICATION_PROVIDER, _authProviderName);
_attributes.put(Port.PORT, _portNumber);
Port port = _portFactory.createPort(_portId, _broker, _attributes);
@@ -335,4 +361,29 @@ public class PortFactoryTest extends QpidTestCase
// pass
}
}
+
+ public void testCreateRMIPortRequestingSslFails()
+ {
+ String keyStoreName = "myKeyStore";
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.PORT, 1);
+ attributes.put(Port.NAME, getTestName());
+ attributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
+ attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.RMI));
+ _attributes.put(Port.KEY_STORE, keyStoreName);
+
+ when(_broker.findKeyStoreByName(keyStoreName)).thenReturn(_keyStore);
+
+ try
+ {
+ _portFactory.createPort(_portId, _broker, attributes);
+ fail("RMI port creation should fail due to requesting SSL");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ e.printStackTrace();
+ // pass
+ }
+ }
}