Search in sources :

Example 26 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testStopVHNDeniedByACL.

@Test
public void testStopVHNDeniedByACL() throws Exception {
    AccessControl mockAccessControl = mock(AccessControl.class);
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.setAccessControl(mockAccessControl);
    node.open();
    node.start();
    when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
    try {
        node.stop();
        fail("Exception not throws");
    } catch (AccessControlException ace) {
    // PASS
    }
    assertEquals("Virtual host node state changed unexpectedly", State.ACTIVE, node.getState());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) AccessControlException(java.security.AccessControlException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AccessControl(org.apache.qpid.server.security.AccessControl) Test(org.junit.Test)

Example 27 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testActivateVHN_StoreHasVH.

/**
 *  Tests activating a virtualhostnode with a config store that specifies a
 *  virtualhost.  Ensures that the virtualhost created.
 */
@Test
public void testActivateVHN_StoreHasVH() throws Exception {
    UUID virtualHostId = UUID.randomUUID();
    ConfiguredObjectRecord vhostRecord = createVirtualHostConfiguredObjectRecord(virtualHostId);
    DurableConfigurationStore configStore = configStoreThatProduces(vhostRecord);
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.open();
    node.start();
    VirtualHost<?> virtualHost = node.getVirtualHost();
    assertNotNull("Virtual host was not recovered", virtualHost);
    assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
    assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
    assertEquals("Unexpected virtual host id", virtualHostId, virtualHost.getId());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testActivateVHNWithVHBlueprintUsed_StoreHasNoVH.

/**
 *  Tests activating a virtualhostnode with blueprint context variable and the
 *  but the virtualhostInitialConfiguration set to empty.  Config store does not specify a virtualhost.
 *  Checks virtualhost is not recreated from the blueprint.
 */
@Test
public void testActivateVHNWithVHBlueprintUsed_StoreHasNoVH() throws Exception {
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}", TestMemoryVirtualHost.VIRTUAL_HOST_TYPE, TEST_VIRTUAL_HOST_NAME);
    Map<String, String> context = new HashMap<>();
    context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    nodeAttributes.put(VirtualHostNode.CONTEXT, context);
    nodeAttributes.put(VirtualHostNode.VIRTUALHOST_INITIAL_CONFIGURATION, "{}");
    VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.open();
    node.start();
    VirtualHost<?> virtualHost = node.getVirtualHost();
    assertNull("Virtual host should not be created by blueprint", virtualHost);
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 29 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testUpdateVHNDeniedByACL.

// ***************  VHN Access Control Tests  ***************
@Test
public void testUpdateVHNDeniedByACL() throws Exception {
    AccessControl mockAccessControl = mock(AccessControl.class);
    DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
    Map<String, Object> nodeAttributes = new HashMap<>();
    nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
    nodeAttributes.put(VirtualHostNode.ID, _nodeId);
    TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
    node.setAccessControl(mockAccessControl);
    node.open();
    node.start();
    when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
    assertNull(node.getDescription());
    try {
        node.setAttributes(Collections.<String, Object>singletonMap(VirtualHostNode.DESCRIPTION, "My virtualhost node"));
        fail("Exception not throws");
    } catch (AccessControlException ace) {
    // PASS
    }
    assertNull("Description unexpected updated", node.getDescription());
    node.close();
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) AccessControlException(java.security.AccessControlException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AccessControl(org.apache.qpid.server.security.AccessControl) Test(org.junit.Test)

Example 30 with DurableConfigurationStore

use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.

the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateFails_StoreFails.

@Test
public void testValidateOnCreateFails_StoreFails() throws Exception {
    String nodeName = getTestName();
    Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
    final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
    doThrow(new RuntimeException("Cannot open store")).when(store).init(any(ConfiguredObject.class));
    AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
    try {
        node.create();
        fail("Exception not thrown");
    } catch (IllegalConfigurationException e) {
        assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
    }
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)30 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)21 Test (org.junit.Test)18 HashMap (java.util.HashMap)14 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)4 AccessControlException (java.security.AccessControlException)3 AccessControl (org.apache.qpid.server.security.AccessControl)3 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)3 UUID (java.util.UUID)2 AbstractSystemConfig (org.apache.qpid.server.model.AbstractSystemConfig)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 TestMemoryVirtualHost (org.apache.qpid.server.virtualhost.TestMemoryVirtualHost)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 DatabaseException (com.sleepycat.je.DatabaseException)1 ReplicationGroupAdmin (com.sleepycat.je.rep.util.ReplicationGroupAdmin)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1