Search in sources :

Example 56 with WallConfig

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

the class MySqlWallTest_hint method test_true_11.

public void test_true_11() throws Exception {
    WallConfig config = new WallConfig();
    config.setHintAllow(true);
    config.setMultiStatementAllow(true);
    config.setNoneBaseStatementAllow(true);
    String sql = "EXPLAIN /*!40100 EXTENDED */ SELECT * FROM trade_order_header WHERE id = ?";
    //
    Assert.assertTrue(WallUtils.isValidateMySql(sql, config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 57 with WallConfig

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

the class MySqlWallTest_union method testUnion.

public void testUnion() throws Exception {
    WallConfig config = new WallConfig();
    config.setSelectUnionCheck(true);
    // not end of comment
    Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select 1, 2", config));
    Assert.assertFalse(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select 1, 2 --", config));
    // no where
    Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t union select 1, 2", config));
    Assert.assertFalse(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select null, '1', 2 --", config));
    //union select item is not const
    Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select c1, c2", config));
    Assert.assertTrue(WallUtils.isValidateMySql("SELECT typeid, typename FROM (SELECT typeid, typename FROM materialtype UNION ALL SELECT ? AS typeid, ? AS typename) a ORDER BY typeid", // union select item has alias
    config));
    // from is subQuery
    Assert.assertFalse(WallUtils.isValidateMySql("select f1, f2 from (select 1 as f1, 2 as f2) t union select 'u1', 'u2' --", config));
    // union select item has alias
    Assert.assertTrue(WallUtils.isValidateMySql("select f1, f2 from t where id=1 union select 'u1' as u1, 'u2' as u2", config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 58 with WallConfig

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

the class MysqlWallTest_rename_table method test_true.

public void test_true() throws Exception {
    WallConfig config = new WallConfig();
    config.setRenameTableAllow(true);
    Assert.assertTrue(WallUtils.isValidateMySql("RENAME TABLE t1 TO t2", config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 59 with WallConfig

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

the class OracleWallPermitFunctionTest method test_permitTable_allow.

public void test_permitTable_allow() throws Exception {
    WallConfig config = new WallConfig();
    config.setFunctionCheck(false);
    Assert.assertTrue(WallUtils.isValidateOracle("select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from X", config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

Example 60 with WallConfig

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

the class MySqlWallTest_hint method test_true_3.

public void test_true_3() throws Exception {
    WallConfig config = new WallConfig();
    config.setHintAllow(true);
    config.setMultiStatementAllow(true);
    String sql = " /*!50003 CREATE*/ /*!50020  /*!50003 PROCEDURE `top_calculate_customer_update`(in update_time DATETIME)" + " DETERMINISTIC" + " BEGIN" + " DECLARE done INT DEFAULT FALSE;" + " DECLARE c_receiver_city,c_receiver_district,c_receiver_address VARCHAR(200);" + " DECLARE c_last_updated DATETIME;" + " DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;" + " insert into top_calculate_customer_log (execute_time,info) values (now(),'update table top_taobao_order_customer_mid begin');" + " update top_tmp_order_middle_last_sync set status = 'wait', last_sync = update_time where plat_form = 'taobao' and status = 'blocking';" + " END */";
    Assert.assertTrue(WallUtils.isValidateMySql(sql, config));
}
Also used : WallConfig(com.alibaba.druid.wall.WallConfig)

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