use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testRetrievingEmptyApplicableConditionsWhenDefaultAndConditionGroupsAreNotAvailable.
@Test
public void testRetrievingEmptyApplicableConditionsWhenDefaultAndConditionGroupsAreNotAvailable() {
ConditionGroupDTO[] conditionGroupDTOS = new ConditionGroupDTO[0];
List<ConditionGroupDTO> conditionGroupDTOList = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
// Should return empty Condition group in the Condition group array
Assert.assertNull(conditionGroupDTOList.get(0));
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfNotMatchingHeaderCondition.
@Test
public void testApplicabilityOfNotMatchingHeaderCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("HeaderConditionGroup");
ConditionDTO notMatchingCondition = new ConditionDTO();
notMatchingCondition.setConditionType("Header");
notMatchingCondition.setConditionName("host");
notMatchingCondition.setConditionValue("org.ibm.com");
ConditionDTO[] conditionDTOS = { notMatchingCondition };
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.assertNull(matchingConditionGroups.get(0));
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfMatchingJWTClaimsCondition.
@Test
public void testApplicabilityOfMatchingJWTClaimsCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("JWTClaimsConditionGroup");
ConditionDTO matchingCondition = new ConditionDTO();
matchingCondition.setConditionType("JWTClaims");
matchingCondition.setConditionName("http://wso2.org/claims/subscriber");
matchingCondition.setConditionValue("admin");
ConditionDTO[] conditionDTOS = { matchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertEquals(matchingConditionGroups.get(0).getConditionGroupId(), "JWTClaimsConditionGroup");
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfInvertedJWTClaimsCondition.
@Test
public void testApplicabilityOfInvertedJWTClaimsCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("JWTClaimsConditionGroup");
ConditionDTO invertedCondition = new ConditionDTO();
invertedCondition.setConditionType("JWTClaims");
invertedCondition.setConditionName("http://wso2.org/claims/subscriber");
invertedCondition.setConditionValue("admin");
invertedCondition.isInverted(true);
ConditionDTO[] conditionDTOS = { invertedCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(JWTToken);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(messageContext, authenticationContext, conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
use of org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testApplicabilityOfNonMatchingIPRangeCondition.
@Test
public void testApplicabilityOfNonMatchingIPRangeCondition() {
ConditionGroupDTO conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("IPRangeConditionGroup");
// 127.0.0.1 is not in 10.10.0.1 - 10.10.0.4 IP range
ConditionDTO nonMatchingCondition = new ConditionDTO();
nonMatchingCondition.setConditionType("IPRange");
nonMatchingCondition.setConditionName("10.10.0.1");
nonMatchingCondition.setConditionValue("10.10.0.4");
ConditionDTO[] conditionDTOS = { nonMatchingCondition };
conditionGroupDTO.setConditions(conditionDTOS);
ConditionGroupDTO[] conditionGroupDTOS = { conditionGroupDTO };
List<ConditionGroupDTO> matchingConditionGroups = throttleConditionEvaluator.getApplicableConditions(TestUtils.getMessageContext(apiContext, apiVersion), new AuthenticationContext(), conditionGroupDTOS);
Assert.assertNull(matchingConditionGroups.get(0));
}
Aggregations