Search in sources :

Example 31 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class ConnectionVersionValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    _connectionValidator = new ConnectionVersionValidator();
    _virtualHostMock = mock(QueueManagingVirtualHost.class);
    _connectionMock = mock(AMQPConnection.class);
    _eventLoggerMock = mock(EventLogger.class);
    Broker brokerMock = mock(Broker.class);
    when(_virtualHostMock.getBroker()).thenReturn(brokerMock);
    when(brokerMock.getEventLogger()).thenReturn(_eventLoggerMock);
}
Also used : Broker(org.apache.qpid.server.model.Broker) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) EventLogger(org.apache.qpid.server.logging.EventLogger) Before(org.junit.Before)

Example 32 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class ServerConnectionDelegateTest method setUp.

@Before
public void setUp() {
    _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance();
    final Broker broker = mock(Broker.class);
    when(broker.getNetworkBufferSize()).thenReturn(0xffff);
    when(broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(Long.MAX_VALUE);
    when(broker.getTaskExecutor()).thenReturn(_taskExecutor);
    when(broker.getModel()).thenReturn(BrokerModel.getInstance());
    final AuthenticationProvider authenticationProvider = mock(AuthenticationProvider.class);
    when(authenticationProvider.getAvailableMechanisms(anyBoolean())).thenReturn(Collections.singletonList("PLAIN"));
    final AmqpPort<?> port = mock(AmqpPort.class);
    when(port.getAuthenticationProvider()).thenReturn(authenticationProvider);
    when(port.getParent()).thenReturn(broker);
    _delegate = new ServerConnectionDelegate(port, true, "test");
    _delegate.setState(ServerConnectionDelegate.ConnectionState.OPEN);
    final NamedAddressSpace addressSpace = mock(NamedAddressSpace.class);
    when(addressSpace.getConnections()).thenReturn(Collections.emptyList());
    final Subject subject = new Subject();
    subject.setReadOnly();
    _accessControlContext = AccessController.getContext();
    final AMQPConnection_0_10 amqpConnection = mock(AMQPConnection_0_10.class);
    when(amqpConnection.getParent()).thenReturn(broker);
    when(amqpConnection.getBroker()).thenReturn(broker);
    when(amqpConnection.getChildExecutor()).thenReturn(_taskExecutor);
    when(amqpConnection.getModel()).thenReturn(BrokerModel.getInstance());
    when(amqpConnection.getSubject()).thenReturn(subject);
    when(amqpConnection.getContextValue(Long.class, org.apache.qpid.server.model.Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Long.MAX_VALUE);
    when(amqpConnection.getContextValue(Integer.class, org.apache.qpid.server.model.Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Integer.MAX_VALUE);
    doAnswer((Answer<AccessControlContext>) invocationOnMock -> {
        Subject subject1 = (Subject) invocationOnMock.getArgument(0);
        return AccessController.doPrivileged((PrivilegedAction<AccessControlContext>) () -> new AccessControlContext(_accessControlContext, new SubjectDomainCombiner(subject1)));
    }).when(amqpConnection).getAccessControlContextFromSubject(any());
    when(amqpConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
    _serverConnection = mock(ServerConnection.class);
    when(_serverConnection.getAddressSpace()).thenReturn(addressSpace);
    when(_serverConnection.getBroker()).thenReturn(broker);
    when(_serverConnection.getAmqpConnection()).thenReturn(amqpConnection);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AccessControlContext(java.security.AccessControlContext) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) MessageDigest(java.security.MessageDigest) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) MESSAGE_DIGEST_SHA1(org.apache.qpid.server.protocol.v0_10.ServerConnectionDelegate.MESSAGE_DIGEST_SHA1) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) EventLogger(org.apache.qpid.server.logging.EventLogger) BrokerModel(org.apache.qpid.server.model.BrokerModel) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BASE64_LIMIT(org.apache.qpid.server.protocol.v0_10.ServerConnectionDelegate.BASE64_LIMIT) Before(org.junit.Before) SessionAttach(org.apache.qpid.server.protocol.v0_10.transport.SessionAttach) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Broker(org.apache.qpid.server.model.Broker) UnitTestBase(org.apache.qpid.test.utils.UnitTestBase) SubjectDomainCombiner(javax.security.auth.SubjectDomainCombiner) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) Subject(javax.security.auth.Subject) Mockito.verify(org.mockito.Mockito.verify) Base64(java.util.Base64) Stream(java.util.stream.Stream) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessController(java.security.AccessController) Collections(java.util.Collections) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) Mockito.mock(org.mockito.Mockito.mock) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Broker(org.apache.qpid.server.model.Broker) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Subject(javax.security.auth.Subject) SubjectDomainCombiner(javax.security.auth.SubjectDomainCombiner) AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction) Before(org.junit.Before)

Example 33 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class VirtualHostLoggerTest method setUp.

@Before
public void setUp() throws Exception {
    _taskExecutor = new TaskExecutorImpl();
    _taskExecutor.start();
    Model model = BrokerModel.getInstance();
    EventLogger eventLogger = mock(EventLogger.class);
    SystemConfig<?> systemConfig = mock(SystemConfig.class);
    when(systemConfig.getModel()).thenReturn(model);
    when(systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
    when(systemConfig.getEventLogger()).thenReturn(eventLogger);
    when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
    doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
    Principal systemPrincipal = mock(Principal.class);
    AccessControl accessControlMock = BrokerTestHelper.createAccessControlMock();
    Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControlMock);
    when(broker.getModel()).thenReturn(model);
    when(broker.getChildExecutor()).thenReturn(_taskExecutor);
    when(broker.getParent()).thenReturn(systemConfig);
    doReturn(Broker.class).when(broker).getCategoryClass();
    VirtualHostNode node = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControlMock);
    when(node.getModel()).thenReturn(model);
    when(node.getChildExecutor()).thenReturn(_taskExecutor);
    when(node.getParent()).thenReturn(broker);
    when(node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
    doReturn(VirtualHostNode.class).when(node).getCategoryClass();
    when(node.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
    // use real VH object rather then mock in order to test create/start/stop functionality
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(VirtualHost.NAME, getTestName());
    attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
    _virtualHost = new TestMemoryVirtualHost(attributes, node);
    _virtualHost.open();
    _baseFolder = new File(TMP_FOLDER, "test-sub-folder");
    _logFile = new File(_baseFolder, "tmp-virtual-host.log." + System.currentTimeMillis());
    if (_baseFolder.exists()) {
        FileUtils.delete(_baseFolder, true);
    }
}
Also used : TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) TestMemoryVirtualHost(org.apache.qpid.server.virtualhost.TestMemoryVirtualHost) Broker(org.apache.qpid.server.model.Broker) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) AccessControl(org.apache.qpid.server.security.AccessControl) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) File(java.io.File) Principal(java.security.Principal) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Before(org.junit.Before)

Example 34 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class JDBCVirtualHostNodeTest method testInvalidTableNamePrefix.

@Test
public void testInvalidTableNamePrefix() throws Exception {
    SystemConfig systemConfig = mock(SystemConfig.class);
    Broker broker = mock(Broker.class);
    final ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
    when(broker.getObjectFactory()).thenReturn(factory);
    when(broker.getModel()).thenReturn(factory.getModel());
    when(broker.getChildExecutor()).thenReturn(_taskExecutor);
    when(broker.getParent()).thenReturn(systemConfig);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, getTestName());
    attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
    attributes.put("connectionUrl", "jdbc://example.com");
    JDBCVirtualHostNode<?> jdbcVirtualHostNode = new JDBCVirtualHostNodeImpl(attributes, broker);
    // This list is not exhaustive
    List<String> knownInvalidPrefixes = Arrays.asList("with\"dblquote", "with'quote", "with-dash", "with;semicolon", "with space", "with%percent", "with|pipe", "with(paren", "with)paren", "with[bracket", "with]bracket", "with{brace", "with}brace");
    for (String invalidPrefix : knownInvalidPrefixes) {
        try {
            jdbcVirtualHostNode.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
            fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
        } catch (IllegalConfigurationException e) {
        // pass
        }
    }
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl) Test(org.junit.Test)

Example 35 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class BrokerMemoryLoggerTest method doMemoryLoggerLimitsTest.

private void doMemoryLoggerLimitsTest(final int illegalValue, final int legalValue) {
    final String brokerLoggerName = "TestBrokerLogger";
    Broker broker = _systemConfig.getContainer(Broker.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, brokerLoggerName);
    attributes.put(ConfiguredObject.TYPE, BrokerMemoryLogger.TYPE);
    attributes.put(BrokerMemoryLogger.MAX_RECORDS, illegalValue);
    try {
        broker.createChild(BrokerLogger.class, attributes);
        fail("Exception not thrown");
    } catch (IllegalConfigurationException ice) {
    // PASS
    }
    attributes.put(BrokerMemoryLogger.MAX_RECORDS, legalValue);
    BrokerLogger brokerLogger = (BrokerLogger) broker.createChild(BrokerLogger.class, attributes);
    try {
        brokerLogger.setAttributes(Collections.singletonMap(BrokerMemoryLogger.MAX_RECORDS, illegalValue));
        fail("Exception not thrown");
    } catch (IllegalConfigurationException ice) {
    // PASS
    } finally {
        brokerLogger.delete();
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Aggregations

Broker (org.apache.qpid.server.model.Broker)38 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)15 EventLogger (org.apache.qpid.server.logging.EventLogger)13 Before (org.junit.Before)11 Test (org.junit.Test)8 Subject (javax.security.auth.Subject)7 HashMap (java.util.HashMap)6 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)6 VirtualHost (org.apache.qpid.server.model.VirtualHost)6 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)6 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)5 Model (org.apache.qpid.server.model.Model)5 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)4 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AccessControlException (java.security.AccessControlException)3 Principal (java.security.Principal)3 SSLContext (javax.net.ssl.SSLContext)3 BrokerModel (org.apache.qpid.server.model.BrokerModel)3 Queue (org.apache.qpid.server.model.Queue)3