use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testMaxStringLengthInsideAnArrayPass.
@Test
public void testMaxStringLengthInsideAnArrayPass() throws Exception {
JSONConfig config = Mockito.mock(JSONConfig.class);
Mockito.when(config.getMaxStringLength()).thenReturn(5);
JSONAnalyzer analyzer = new JSONAnalyzer();
analyzer.configure(config);
String jsonString = "{\"abcdef\": [1, \"12345\", 3, 4, 5, 6]}";
analyzer.analyze(jsonString, "/foo");
}
use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testJsonDepthAnalyzePass.
@Test
public void testJsonDepthAnalyzePass() throws Exception {
JSONConfig config = Mockito.mock(JSONConfig.class);
Mockito.when(config.getMaxJsonDepth()).thenReturn(4);
JSONAnalyzer analyzer = new JSONAnalyzer();
analyzer.configure(config);
String jsonString = "{\"a\": {\"b\": {\"c\": {\"d\": 1}}}}";
analyzer.analyze(jsonString, "/foo");
}
use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testJsonDepthAnalyzeFail.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testJsonDepthAnalyzeFail() throws Exception {
JSONConfig config = Mockito.mock(JSONConfig.class);
Mockito.when(config.getMaxJsonDepth()).thenReturn(3);
JSONAnalyzer analyzer = new JSONAnalyzer();
analyzer.configure(config);
String jsonString = "{\"a\": {\"b\": {\"c\": {\"d\": 1}}}}";
analyzer.analyze(jsonString, "/foo");
}
use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testCheckMaxStringLengthPass.
@Test
public void testCheckMaxStringLengthPass() throws Exception {
JSONConfig config = Mockito.mock(JSONConfig.class);
Mockito.when(config.getMaxStringLength()).thenReturn(10);
JSONAnalyzer analyzer = new JSONAnalyzer();
analyzer.configure(config);
String jsonString = "{\"a\": \"abcdef1234\"}";
analyzer.analyze(jsonString, "/foo");
}
use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testMaxFieldLengthFail.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxFieldLengthFail() throws Exception {
JSONConfig config = Mockito.mock(JSONConfig.class);
Mockito.when(config.getMaxKeyLength()).thenReturn(5);
JSONAnalyzer analyzer = new JSONAnalyzer();
analyzer.configure(config);
String jsonString = "{\"abcdef\": [1, 2, 3, 4, 5, 6]}";
analyzer.analyze(jsonString, "/foo");
}
Aggregations