Search in sources :

Example 76 with WallConfig

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

the class BigSqlTest method test_true.

public void test_true() throws Exception {
    String sql = "SELECT c from sbtest where id=0";
    for (int i = 0; i < 10000; i++) {
        sql += " or id=0";
    }
    WallConfig config = new WallConfig();
    Assert.assertTrue(WallUtils.isValidateMySql(sql, config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 77 with WallConfig

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

the class BitwiseInvertTest method test_false.

public void test_false() throws Exception {
    WallConfig config = new WallConfig();
    config.setConditionOpBitwseAllow(false);
    Assert.assertFalse(//
    WallUtils.isValidateMySql("SELECT * from t where ~2", //
    config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 78 with WallConfig

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

the class BooleanXorTest method test_true.

public void test_true() throws Exception {
    WallConfig config = new WallConfig();
    config.setConditionOpXorAllow(true);
    Assert.assertTrue(//
    WallUtils.isValidateMySql("SELECT * from t where id = 1 XOR id = 2", //
    config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 79 with WallConfig

use of com.alibaba.druid.wall.WallConfig 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 80 with WallConfig

use of com.alibaba.druid.wall.WallConfig 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)

Aggregations

WallConfig (com.alibaba.druid.wall.WallConfig)83 Properties (java.util.Properties)8 WallFilter (com.alibaba.druid.wall.WallFilter)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 WallCheckResult (com.alibaba.druid.wall.WallCheckResult)3 Filter (com.alibaba.druid.filter.Filter)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)2 WallContext (com.alibaba.druid.wall.WallContext)2 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)2 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLStartTransactionStatement (com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement)1 MySqlCommitStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement)1 MySqlDeleteStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement)1 MySqlDescribeStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDescribeStatement)1 MySqlHintStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHintStatement)1 MySqlLockTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement)1 MySqlRenameTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement)1 MySqlReplaceStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement)1