Search in sources :

Example 31 with WallCheckResult

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

the class TenantSelectTest3 method testMySql.

public void testMySql() throws Exception {
    WallConfig config = new WallConfig();
    WallConfig config_callback = new WallConfig();
    config.setTenantTablePattern("*");
    config.setTenantColumn("tenant");
    config_callback.setTenantCallBack(new TenantTestCallBack());
    WallProvider.setTenantValue(123);
    MySqlWallProvider provider = new MySqlWallProvider(config);
    WallCheckResult checkResult = provider.check(sql);
    Assert.assertEquals(0, checkResult.getViolations().size());
    String resultSql = SQLUtils.toSQLString(checkResult.getStatementList(), JdbcConstants.MYSQL);
    Assert.assertEquals(expect_sql, resultSql);
}
Also used : MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) WallConfig(com.alibaba.druid.wall.WallConfig) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 32 with WallCheckResult

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

the class TenantSelectTest3 method testMySql2.

public void testMySql2() throws Exception {
    WallConfig config = new WallConfig();
    WallConfig config_callback = new WallConfig();
    config.setTenantTablePattern("*");
    config.setTenantColumn("tenant");
    config_callback.setTenantCallBack(new TenantTestCallBack());
    MySqlWallProvider provider = new MySqlWallProvider(config_callback);
    WallCheckResult checkResult = provider.check(sql);
    Assert.assertEquals(0, checkResult.getViolations().size());
    String resultSql = SQLUtils.toSQLString(checkResult.getStatementList(), JdbcConstants.MYSQL);
    Assert.assertEquals(expect_sql, resultSql);
}
Also used : MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) WallConfig(com.alibaba.druid.wall.WallConfig) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 33 with WallCheckResult

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

the class WallSelectLimitTest_2 method testOracle.

public void testOracle() throws Exception {
    String sql = PagerUtils.limit("select * from t", JdbcConstants.ORACLE, 0, 10);
    WallProvider provider = new OracleWallProvider(config);
    WallCheckResult checkResult = provider.check(sql);
    String resultSql = checkResult.getSql();
    System.out.println(resultSql);
    assertEquals("SELECT *\n" + "FROM t\n" + "WHERE ROWNUM <= 10", resultSql);
    sql = PagerUtils.limit("select * from t", JdbcConstants.OCEANBASE_ORACLE, 0, 10);
    provider = new OracleWallProvider(config);
    checkResult = provider.check(sql);
    resultSql = checkResult.getSql();
    System.out.println(resultSql);
    assertEquals("SELECT *\n" + "FROM t\n" + "WHERE ROWNUM <= 10", resultSql);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 34 with WallCheckResult

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

the class WallSelectLimitTest_2 method testMySql.

public void testMySql() throws Exception {
    String sql = "select * from t limit 10";
    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 10", resultSql);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) WallCheckResult(com.alibaba.druid.wall.WallCheckResult)

Example 35 with WallCheckResult

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

the class WallSelectLimitTest method testOracle.

public void testOracle() throws Exception {
    WallProvider provider = new OracleWallProvider(config);
    WallCheckResult checkResult = provider.check(sql);
    String resultSql = checkResult.getSql();
    System.out.println(resultSql);
    assertEquals("SELECT *\n" + "FROM t\n" + "WHERE ROWNUM <= 1000", resultSql);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) 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