use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testRegisterNullSubject.
private void testRegisterNullSubject(Duration duration) {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_GROUP1, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_GROUP2, 1000, 1000, duration));
builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
final RuleSet ruleSet = builder.build();
assertNotNull(ruleSet);
final AMQPConnection<?> connection = Mockito.mock(AMQPConnection.class);
Mockito.doReturn(_port).when(connection).getPort();
Mockito.doReturn(_principal).when(connection).getAuthorizedPrincipal();
Mockito.doReturn(_eventLogger).when(connection).getEventLogger();
try {
ruleSet.register(connection);
fail("An exception is expected");
} catch (ConnectionLimitException e) {
assertEquals("User user is blocked on port amqp", e.getMessage());
}
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testAppend_FrequencyLimit.
private void testAppend_FrequencyLimit(Integer countLimit) {
if (countLimit != null && countLimit < 3) {
countLimit = 3;
}
final Duration frequencyPeriod = Duration.ofDays(3650L);
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, TEST_USER, 200, 20000, frequencyPeriod));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1, 1, frequencyPeriod));
builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
final Builder secondaryBuilder = RuleSet.newBuilder(LIMITER_NAME, frequencyPeriod);
secondaryBuilder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_USER, countLimit, 2, frequencyPeriod));
secondaryBuilder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
testConnectionFrequencyLimit2((RuleSet) builder.build().append(secondaryBuilder.build()));
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testBlockedGroup.
private void testBlockedGroup(Duration duration) {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_GROUP1, 10000, null, duration));
builder.addRule(Rule.newBlockingRule(TEST_PORT, TEST_GROUP2));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, OTHER_USER, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP, 1000, 1000, duration));
builder.addRule(Rule.newNonBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS, 10000, 10000, duration));
testBlocked(builder.build());
testBlocked(builder.logAllMessages(true).build());
testBlocked(builder.logAllMessages(false).build());
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testNoLimits.
private void testNoLimits(Duration duration) {
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, duration);
builder.addRule(Rule.newBlockingRule(TEST_PORT, OTHER_USER));
builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, OTHER_GROUP));
final RuleSet ruleSet = builder.build();
assertNotNull(ruleSet);
ConnectionSlot connection1 = null;
ConnectionSlot connection2 = null;
ConnectionSlot connection3 = null;
try {
connection1 = ruleSet.register(newConnection());
connection2 = ruleSet.register(newConnection());
connection3 = ruleSet.register(newConnection());
} catch (ConnectionLimitException e) {
fail("An exception is not expected here");
}
assertNotNull(connection1);
assertNotNull(connection2);
assertNotNull(connection3);
connection1.free();
connection2.free();
connection3.free();
}
use of org.apache.qpid.server.user.connection.limits.config.RuleSet.Builder in project qpid-broker-j by apache.
the class RuleSetTest method testFrequencyLimit_multiplePeriods.
@Test
public void testFrequencyLimit_multiplePeriods() {
final Duration frequencyPeriod1 = Duration.ofSeconds(1L);
final Duration frequencyPeriod2 = Duration.ofSeconds(2L);
final Builder builder = RuleSet.newBuilder(LIMITER_NAME, Duration.ofMinutes(1L));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_USER, null, 3, frequencyPeriod1));
builder.addRule(Rule.newNonBlockingRule(TEST_PORT, TEST_USER, null, 2, frequencyPeriod2));
builder.addRule(Rule.newBlockingRule(RulePredicates.ALL_PORTS, RulePredicates.ALL_USERS));
final RuleSet ruleSet = builder.build();
assertNotNull(ruleSet);
final Instant registrationStart = Instant.now();
try {
ruleSet.register(newConnection()).free();
ruleSet.register(newConnection()).free();
} catch (ConnectionLimitException e) {
fail("An exception is not expected here");
}
final Instant registrationEnd = Instant.now();
Instant before = Instant.now();
do {
try {
before = Instant.now();
ruleSet.register(newConnection()).free();
assertTrue(Duration.between(registrationStart, Instant.now()).compareTo(frequencyPeriod2) >= 0);
break;
} catch (ConnectionLimitException e) {
assertTrue(Duration.between(registrationEnd, before).compareTo(frequencyPeriod2) <= 0);
}
} while (Duration.between(registrationEnd, Instant.now()).compareTo(Duration.ofSeconds(3L)) < 0);
}
Aggregations