use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.
the class StrongConnectionEstablishmentLimiterTest method testMultipleIndependentConnections.
@Test
public void testMultipleIndependentConnections() {
final AMQPConnection_1_0<?> connection1 = newConnection("C1", null);
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
final AMQPConnection_1_0<?> connection2 = newConnection("C2", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection("C3", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
final ConnectionSlot slot3 = _limiter.register(connection3);
assertTrue(_registry.isRegistered(connection3));
slot3.free();
assertFalse(_registry.isRegistered(connection3));
assertTrue(_registry.hasBeenRegistered(connection3));
slot2.free();
assertFalse(_registry.isRegistered(connection2));
assertTrue(_registry.hasBeenRegistered(connection2));
slot1.free();
assertFalse(_registry.isRegistered(connection1));
assertTrue(_registry.hasBeenRegistered(connection1));
}
use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.
the class StrongConnectionEstablishmentLimiterTest method testMultipleIndependentConnections2.
@Test
public void testMultipleIndependentConnections2() {
final AMQPConnection_1_0<?> connection1 = newConnection(null, null);
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
final AMQPConnection_1_0<?> connection2 = newConnection(null, null);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection(null, null);
final ConnectionSlot slot3 = _limiter.register(connection3);
assertTrue(_registry.isRegistered(connection3));
slot3.free();
assertFalse(_registry.isRegistered(connection3));
assertTrue(_registry.hasBeenRegistered(connection3));
slot2.free();
assertFalse(_registry.isRegistered(connection2));
assertTrue(_registry.hasBeenRegistered(connection2));
slot1.free();
assertFalse(_registry.isRegistered(connection1));
assertTrue(_registry.hasBeenRegistered(connection1));
}
use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.
the class StrongConnectionEstablishmentLimiterTest method testNewConnectionWithPolicy2_ClosedExisting.
@Test
public void testNewConnectionWithPolicy2_ClosedExisting() {
final AMQPConnection_1_0<?> connection1 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
Mockito.doReturn(false).when(connection1).isClosing();
final ConnectionSlot slot1 = _limiter.register(connection1);
assertTrue(_registry.isRegistered(connection1));
Mockito.doReturn(true).when(connection1).isClosing();
final AMQPConnection_1_0<?> connection2 = newConnection("C", SoleConnectionEnforcementPolicy.REFUSE_CONNECTION);
final ConnectionSlot slot2 = _limiter.register(connection2);
assertTrue(_registry.isRegistered(connection2));
final AMQPConnection_1_0<?> connection3 = newConnection("C", SoleConnectionEnforcementPolicy.CLOSE_EXISTING);
try {
_limiter.register(connection3);
fail("A sole connection enforcement policy exception is expected");
} catch (SoleConnectionEnforcementPolicyException e) {
assertEquals("Single connection with container ID 'C' is required due to sole connection enforcement policy 'refuse-connection'", e.getMessage());
assertEquals(1, e.getExistingConnections().size());
assertTrue(e.getExistingConnections().contains(connection2));
assertEquals(SoleConnectionEnforcementPolicy.REFUSE_CONNECTION, e.getPolicy());
}
slot2.free();
assertFalse(_registry.isRegistered(connection2));
assertTrue(_registry.hasBeenRegistered(connection2));
slot1.free();
assertFalse(_registry.isRegistered(connection1));
assertTrue(_registry.hasBeenRegistered(connection1));
}
use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.
the class RuleSetTest method testBlocked.
private void testBlocked(RuleSet ruleSet) {
assertNotNull(ruleSet);
ConnectionSlot connection = null;
try {
connection = ruleSet.register(newConnection());
fail("An exception is expected");
} catch (ConnectionLimitException e) {
assertEquals("User user is blocked on port amqp", e.getMessage());
}
assertNull(connection);
}
use of org.apache.qpid.server.security.limit.ConnectionSlot in project qpid-broker-j by apache.
the class RuleSetTest method testBuilder_AddNull.
@Test
public void testBuilder_AddNull() {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, Duration.ofMillis(2L));
builder.addRule(null);
builder.addRules(null);
final RuleSet ruleSet = builder.build();
assertNotNull(ruleSet);
final ConnectionSlot connection1 = ruleSet.register(newConnection());
assertNotNull(connection1);
final ConnectionSlot connection2 = ruleSet.register(newConnection());
assertNotNull(connection2);
connection1.free();
connection2.free();
}
Aggregations