use of org.wso2.carbon.apimgt.core.api.Analyzer 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.core.api.Analyzer 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.core.api.Analyzer 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.core.api.Analyzer 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");
}
use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.
the class XMLAnalyzerTestCase method testAnalyzerDTDDisabled.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testAnalyzerDTDDisabled() throws Exception {
init();
XMLAnalyzer analyzer = new XMLAnalyzer();
analyzer.configure(xmlConfig);
String xmlString = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENTITY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<lolz>&lol9;</lolz>";
analyzer.analyze(xmlString, "/foo");
}
Aggregations