use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithJWTCondition.
@Test
public void testGetThrottledInConditionWithJWTCondition() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableJwtConditions(true);
String jwt = "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3c28yLm9yZy9wcm9kdWN0cy9hbSIsImV4cCI6MTM0NTE4MzQ5MjE4MSwiaHR0cDov" + "L3dzbzIub3JnL2NsYWltcy9hYmMiOiJjZGUiLCJodHRwOi8vd3NvMi5vcmcvY2xhaW1zL2JjZCI6Inh5eiJ9.9zGU062DJ5mQ5hne" + "41h4IRpLbaY_b5thRxb3feebOcA";
AuthenticationContext authenticationContext = new AuthenticationContext();
authenticationContext.setCallerToken(jwt);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map<String, List<ConditionDto>> conditionMap = new HashMap<>();
conditionMap.put("condition1", Arrays.asList(new ConditionDto[] { getJWTCondition(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getJWTCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, authenticationContext, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method getComplexCondition2.
private ConditionDto getComplexCondition2() {
ConditionDto conditionDto = new ConditionDto();
ConditionDto.IPCondition ipCondition = new ConditionDto.IPCondition(APIUtil.ipToBigInteger("127.0.0.1"), false);
conditionDto.setIpCondition(ipCondition);
ConditionDto.QueryParamConditions queryParamConditions = new ConditionDto.QueryParamConditions();
Map map = new HashMap();
map.put("abc", "cde");
map.put("bcd", "xyz");
queryParamConditions.setValues(map);
conditionDto.setQueryParameterConditions(queryParamConditions);
return conditionDto;
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithIPConditionWithDefaultWithInvert.
@Test
public void testGetThrottledInConditionWithIPConditionWithDefaultWithInvert() {
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("X-Forwarded-For", "127.0.0.2");
((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, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method testGetThrottledInConditionWithHeaderCondition.
@Test
public void testGetThrottledInConditionWithHeaderCondition() {
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableHeaderConditions(true);
ServiceReferenceHolder.getInstance().setThrottleProperties(throttleProperties);
MessageContext messageContext = TestUtils.getMessageContext(apiContext, apiVersion);
Map map = new TreeMap();
map.put("abc", "cde");
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(false) }));
conditionMap.put("default", Arrays.asList(new ConditionDto[] { getHeaderCondition(false) }));
String condition = throttleConditionEvaluator.getThrottledInCondition(messageContext, null, conditionMap);
Assert.assertEquals(condition, "condition1");
}
use of org.wso2.carbon.apimgt.impl.dto.ConditionDto in project carbon-apimgt by wso2.
the class ThrottleConditionEvaluatorTest method getIpRangeCondition.
private ConditionDto getIpRangeCondition(boolean invert) {
ConditionDto conditionDto = new ConditionDto();
conditionDto.setIpRangeCondition(new ConditionDto.IPCondition(APIUtil.ipToBigInteger("192.168.0.0"), APIUtil.ipToBigInteger("192.168.0.10"), invert));
return conditionDto;
}
Aggregations