Search in sources :

Example 6 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testCheckMaxStringLengthFail.

@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testCheckMaxStringLengthFail() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxStringLength()).thenReturn(10);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"a\": \"abcdef123456\"}";
    analyzer.analyze(jsonString, "/foo2");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Example 7 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxFieldCountPass.

@Test
public void testMaxFieldCountPass() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxPropertyCount()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"a\": [1, 2, 3, 4, 5, 6], \"b\": 1, \"c\": 2, \"d\": 3, \"e\": 5}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Example 8 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testInvalidJsonPayload.

@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testInvalidJsonPayload() throws Exception {
    JSONAnalyzer analyzer = new JSONAnalyzer();
    String jsonString = "{abcdef: {\"abc\"}:\", \"123456\", 3, 4, 5, 6]}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) Test(org.testng.annotations.Test)

Example 9 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxFieldCountFail.

@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxFieldCountFail() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxPropertyCount()).thenReturn(3);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"a\": [1, 2, 3, 4, 5, 6], \"b\": 1, \"c\": 2, \"d\": 3, \"e\": 5}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Example 10 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxArrayElementCountPass.

@Test
public void testMaxArrayElementCountPass() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxArrayElementCount()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"a\": [1, 2, 3, 4, 5]}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)27 JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)15 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)14 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 BeforeTest (org.testng.annotations.BeforeTest)7 XMLAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.XMLAnalyzer)7 ArrayList (java.util.ArrayList)6 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 ZoneId (java.time.ZoneId)5 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)3 BBoolean (org.ballerinalang.model.values.BBoolean)2 APIMThreatAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)2 XMLConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig)2 APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)2 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)2 ApplicationCount (org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount)2 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)2 SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)2