Search in sources :

Example 36 with WallCheckResult

use of com.alibaba.druid.wall.WallCheckResult in project druid by alibaba.

the class WallSelectLimitTest method testMySql.

public void testMySql() throws Exception {
    WallProvider provider = new MySqlWallProvider(config);
    WallCheckResult checkResult = provider.check(sql);
    String resultSql = checkResult.getSql();
    System.out.println(resultSql);
    assertEquals("SELECT *\n" + "FROM t\n" + "LIMIT 1000", resultSql);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 37 with WallCheckResult

use of com.alibaba.druid.wall.WallCheckResult in project druid by alibaba.

the class WallUpdateCheckTest method test_update_check_handler.

public void test_update_check_handler() throws Exception {
    {
        WallCheckResult result = wallProvider.check("update t_orders set status = 3 where id = 3 and status = 4");
        assertTrue(result.getViolations().size() == 0);
    }
    wallProvider.getConfig().setUpdateCheckHandler(new WallUpdateCheckHandler() {

        @Override
        public boolean check(String table, String column, Object setValue, List<Object> filterValues) {
            return false;
        }
    });
    {
        WallCheckResult result = wallProvider.check("update t_orders set status = 3 where id = 3 and status = 4");
        assertTrue(result.getViolations().size() > 0);
    }
    wallProvider.getConfig().setUpdateCheckHandler(new WallUpdateCheckHandler() {

        @Override
        public boolean check(String table, String column, Object setValue, List<Object> filterValues) {
            return true;
        }
    });
    {
        WallCheckResult result = wallProvider.check("update t_orders set status = 3 where id = 3 and status = 4");
        assertTrue(result.getViolations().size() == 0);
    }
    assertEquals(0, wallProvider.getWhiteListHitCount());
    assertEquals(0, wallProvider.getBlackListHitCount());
    wallProvider.getConfig().setUpdateCheckHandler(new WallUpdateCheckHandler() {

        @Override
        public boolean check(String table, String column, Object setValue, List<Object> filterValues) {
            // 增加对in语句的支持, status in (1, 2) 应该返回的filterValue为1和2
            assertTrue(filterValues.size() == 2);
            return true;
        }
    });
    {
        WallCheckResult result = wallProvider.check("update t_orders set status = 3 where id = 3 and status in (1, 2)");
        assertTrue(result.getViolations().size() == 0);
    }
    {
        WallCheckResult result = wallProvider.check("update t_orders set status = 3 where id = 3 and status = 3 and status in (3, 4)");
        assertTrue(result.getViolations().size() == 0);
    }
}
Also used : WallUpdateCheckHandler(com.alibaba.druid.wall.WallUpdateCheckHandler) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 38 with WallCheckResult

use of com.alibaba.druid.wall.WallCheckResult in project druid by alibaba.

the class MySqlWallTest152 method test_false.

public void test_false() throws Exception {
    WallProvider provider = new MySqlWallProvider();
    provider.getConfig().setSelectLimit(100);
    String sql = "SELECT version FROM schema_migrations";
    // assertTrue(
    // provider.checkValid(sql)
    // );
    WallCheckResult result = provider.check(sql);
    assertEquals(0, result.getViolations().size());
    String wsql = result.getStatementList().get(0).toString();
    assertEquals("SELECT version\n" + "FROM schema_migrations\n" + "LIMIT 100", wsql);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Aggregations

WallCheckResult (com.alibaba.druid.wall.WallCheckResult)38 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)21 WallProvider (com.alibaba.druid.wall.WallProvider)18 Violation (com.alibaba.druid.wall.Violation)3 WallConfig (com.alibaba.druid.wall.WallConfig)3 FirewallConfig (io.mycat.config.model.FirewallConfig)2 Test (org.junit.Test)2 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)1 WallUpdateCheckHandler (com.alibaba.druid.wall.WallUpdateCheckHandler)1 OracleWallProvider (com.alibaba.druid.wall.spi.OracleWallProvider)1 PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)1