use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.
the class JSONAnalyzerTestCase method testMaxStringLengthInsideAnArrayFail.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxStringLengthInsideAnArrayFail() 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, \"123456\", 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 testConfigureAnalyzerException.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testConfigureAnalyzerException() throws Exception {
XMLAnalyzer analyzer = new XMLAnalyzer();
JSONConfig config = new JSONConfig();
analyzer.configure(config);
}
use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.
the class XMLAnalyzerTestCase method testMaxAttributeCount.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxAttributeCount() throws Exception {
init();
String xmlString = "<a><root aaaaaaaaaa='aaaaaaa' b='b' c='c' d='d' e='e' f='f' g='g'></root></a>";
XMLAnalyzer analyzer = new XMLAnalyzer();
analyzer.configure(xmlConfig);
analyzer.analyze(xmlString, "/foo");
}
use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.
the class AnalyzerImplTestCase method testGetApplicationCount.
@Test(description = "Get application count test")
public void testGetApplicationCount() throws APIManagementException {
AnalyticsDAO analyticsDAO = Mockito.mock(AnalyticsDAO.class);
ApplicationCount applicationCount1 = new ApplicationCount();
ApplicationCount applicationCount2 = new ApplicationCount();
List<ApplicationCount> dummyApplicationCountList = new ArrayList<>();
dummyApplicationCountList.add(applicationCount1);
dummyApplicationCountList.add(applicationCount2);
Analyzer analyzer = getAnalyzerImpl(analyticsDAO);
when(analyticsDAO.getApplicationCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenReturn(dummyApplicationCountList);
List<ApplicationCount> applicationCountListFromDB = analyzer.getApplicationCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
Assert.assertNotNull(applicationCountListFromDB);
verify(analyticsDAO, Mockito.times(1)).getApplicationCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
// Error path
Mockito.when(analyticsDAO.getApplicationCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null)).thenThrow(APIMgtDAOException.class);
try {
analyzer.getApplicationCount(Instant.parse(FROM_TIMESTAMP), Instant.parse(TO_TIMESTAMP), null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while fetching application count information");
}
}
use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.
the class XMLAnalyzerTestCase method testMaxEntityExpansionLimit.
@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxEntityExpansionLimit() throws Exception {
init();
XMLAnalyzer analyzer = new XMLAnalyzer();
xmlConfig.setEntityExpansionLimit(100);
xmlConfig.setDtdEnabled(true);
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