use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfMatchingHeaderCondition.
@Test
public void testApplicabilityOfMatchingHeaderCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("HeaderConditionGroup");
ConditionDTO matchingCondition = new ConditionDTO();
matchingCondition.setConditionType("Header");
matchingCondition.setConditionName("host");
matchingCondition.setConditionValue("org.wso2.com");
ConditionDTO[] conditionDTOS = { matchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("host", "org.wso2.com");
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertEquals(matchingConditionGroups.get(0).getConditionGroupId(), "HeaderConditionGroup");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPConditionWithDefaultWithInvertNegative.
@Test
public void testGetThrottledInConditionWithIPConditionWithDefaultWithInvertNegative() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "127.0.0.1");
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getIPCondition(true) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getIPCondition(true) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "default");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedIPRangeCondition.
@Test
public void testApplicabilityOfInvertedIPRangeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPRangeConditionGroup");
// 127.0.0.1 is not in inversion of 127.0.0.0 - 127.0.0.3 IP range
ConditionDTO invertedIPRangeCondition = new ConditionDTO();
invertedIPRangeCondition.setConditionType("IPRange");
invertedIPRangeCondition.setConditionName("127.0.0.0");
invertedIPRangeCondition.setConditionValue("127.0.0.3");
invertedIPRangeCondition.isInverted(true);
ConditionDTO[] conditionDTOS = { invertedIPRangeCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method getHeaderCondition.
private ConditionDto getHeaderCondition(boolean invert) {
ConditionDto conditionDto = new ConditionDto();
ConditionDto.HeaderConditions headerConditions = new ConditionDto.HeaderConditions();
Map map = new HashMap();
map.put("abc", "cde");
map.put("bcd", "xyz");
headerConditions.setValues(map);
headerConditions.setInvert(invert);
conditionDto.setHeaderConditions(headerConditions);
return conditionDto;
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithHeaderConditionNegativeInvert.
@Test
public void testGetThrottledInConditionWithHeaderConditionNegativeInvert() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("abc", "cd1");
map.put("bcd", "xyz");
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, map);
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getHeaderCondition(true) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getHeaderCondition(true) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
Aggregations