Search in sources :

Example 11 with JSONConfig

use of org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig 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");
}
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 12 with JSONConfig

use of org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig 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");
}
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 13 with JSONConfig

use of org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig 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");
}
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 14 with JSONConfig

use of org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig 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");
}
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 15 with JSONConfig

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

JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)15 Test (org.testng.annotations.Test)13 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)12 BBoolean (org.ballerinalang.model.values.BBoolean)1 BStruct (org.ballerinalang.model.values.BStruct)1 BeforeTest (org.testng.annotations.BeforeTest)1 APIMThreatAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)1 XMLAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.XMLAnalyzer)1 XMLConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig)1