sql wall filter

This commit is contained in:
温少
2012-03-16 09:45:34 +08:00
9 changed files with 162 additions and 103 deletions
@@ -0,0 +1,20 @@
package com.alibaba.druid.bvt.filter.wall;
import org.junit.Assert;
import com.alibaba.druid.filter.wall.WallUtils;
import junit.framework.TestCase;
/**
* 这个场景测试访问MySql系统函数
*
* @author admin
*/
public class MySqlWallLoadDataInfileTest extends TestCase {
public void test_permit_stmt() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("load data infile 'c:/boot.ini' into table foo"));
}
}
@@ -0,0 +1,29 @@
package com.alibaba.druid.bvt.filter.wall;
import org.junit.Assert;
import com.alibaba.druid.filter.wall.WallUtils;
import junit.framework.TestCase;
/**
* 这个场景测试访问MySql系统表
*
* @author admin
*/
public class MySqlWallPermitFunctionTest extends TestCase {
public void test_permitTable() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM mysql.user"));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM `mysql`.`user`"));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM \"mysql\".\"user\""));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM MYSQL.USER"));
}
public void test_permitTable_subquery() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM mysql.user) a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM `mysql`.`user`) a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM \"mysql\".\"user\") a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM MYSQL.USER) a"));
}
}
@@ -7,23 +7,14 @@ import com.alibaba.druid.filter.wall.WallUtils;
import junit.framework.TestCase;
/**
* 这个场景测试访问MySql系统表
* 这个场景测试访问MySql系统函数
*
* @author admin
*/
public class MySqlWallPermitTableTest extends TestCase {
public void test_permitTable() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM mysql.user"));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM `mysql`.`user`"));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM \"mysql\".\"user\""));
Assert.assertFalse(WallUtils.isValidateMySql("SELECT User,Password FROM MYSQL.USER"));
Assert.assertFalse(WallUtils.isValidateMySql("select benchmark( 500000, sha1( 'test' ) )"));
}
public void test_permitTable_subquery() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM mysql.user) a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM `mysql`.`user`) a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM \"mysql\".\"user\") a"));
Assert.assertFalse(WallUtils.isValidateMySql("select * from(SELECT User,Password FROM MYSQL.USER) a"));
}
}
@@ -33,7 +33,7 @@ public class OnlineOracleTest3 extends TestCase {
}
public void test_connect() throws Exception {
executeQuery("select * from TAB");
executeQuery("select * from \"SYS\".TAB");
}
public void executeQuery(String sql) throws SQLException {
@@ -33,7 +33,7 @@ public class TestOnlineSQLTest3 extends TestCase {
// ResultSet rs = conn.getMetaData().getTables(null, null, null, null);
// JdbcUtils.printResultSet(rs);
String sql = "SELECT User,Password FROM mysql.user;";
String sql = "select benchmark( 1, sha1( 'test' ) )";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);