Search in sources :

Example 6 with JSONAnalyzer

use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer 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)

Example 7 with JSONAnalyzer

use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer 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");
}
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 JSONAnalyzer

use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testConfigureAnalyzerException.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testConfigureAnalyzerException() throws Exception {
    JSONAnalyzer analyzer = new JSONAnalyzer();
    XMLConfig config = new XMLConfig();
    analyzer.configure(config);
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) XMLConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig) Test(org.testng.annotations.Test)

Example 9 with JSONAnalyzer

use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxFieldLengthPass.

@Test
public void testMaxFieldLengthPass() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxKeyLength()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"abcde\": [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)

Example 10 with JSONAnalyzer

use of org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxArrayElementCountFail.

@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxArrayElementCountFail() 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, 6]}";
    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)14 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)14 JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)13 XMLConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig)2 APIMThreatAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)1