Search in sources :

Example 11 with ConditionGroupDTO

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));
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) Test(org.junit.Test)

Example 12 with ConditionGroupDTO

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));
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Example 13 with ConditionGroupDTO

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");
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 14 with ConditionGroupDTO

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));
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 15 with ConditionGroupDTO

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));
}
Also used : AuthenticationContext(org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext) ConditionDTO(org.wso2.carbon.apimgt.api.dto.ConditionDTO) ConditionGroupDTO(org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO) Test(org.junit.Test)

Aggregations

ConditionGroupDTO (org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO)37 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)31 Test (org.junit.Test)29 MessageContext (org.apache.synapse.MessageContext)21 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)21 ConditionDTO (org.wso2.carbon.apimgt.api.dto.ConditionDTO)19 ArrayList (java.util.ArrayList)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 ThrottleDataHolder (org.wso2.carbon.apimgt.gateway.throttling.ThrottleDataHolder)12 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)6 HashMap (java.util.HashMap)3 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Before (org.junit.Before)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)2 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)2 Timer (org.wso2.carbon.metrics.manager.Timer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1