mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add sql wall suppport
This commit is contained in:
@@ -14,9 +14,12 @@ import com.alibaba.druid.filter.wall.WallUtils;
|
||||
public class OracleWallPermitObjectTest extends TestCase {
|
||||
|
||||
public void test_permitTable() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("select sys.LinxReadFile('c:/boot.ini') from dual"));
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("select sys.LinxRunCMD('cmd /c net user linx /add') from dual"));
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("select utl_inaddr.get_host_address from DUAL"));
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("select TO_CHAR(utl_inaddr.get_host_address) from DUAL"));
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("SELECT SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT'.PUT(:P1));"));
|
||||
Assert.assertFalse(WallUtils.isValidateOracle("select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES()"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.wall.WallUtils;
|
||||
|
||||
/**
|
||||
* 这个场景,检测可疑的Having条件
|
||||
* @author wenshao
|
||||
*
|
||||
*/
|
||||
public class WallSelectWhereTest3 extends TestCase {
|
||||
private String sql = "select * from t WHERE FID = 256 AND CHR(67)||CHR(65)||CHR(84) = 'CAT'";
|
||||
|
||||
public void testMySql() throws Exception {
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(sql));
|
||||
}
|
||||
|
||||
public void testORACLE() throws Exception {
|
||||
Assert.assertTrue(WallUtils.isValidateOracle(sql));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.wall.WallUtils;
|
||||
|
||||
/**
|
||||
* 这个场景,检测可疑的Having条件
|
||||
* @author wenshao
|
||||
*
|
||||
*/
|
||||
public class WallSelectWhereTest4 extends TestCase {
|
||||
private String sql = "select * from t WHERE FID = 256 OR CHR(67)||CHR(65)||CHR(84) = 'CAT'";
|
||||
|
||||
public void testMySql() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateMySql(sql));
|
||||
}
|
||||
|
||||
public void testORACLE() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateOracle(sql));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.wall.WallUtils;
|
||||
|
||||
/**
|
||||
* 这个场景,检测可疑的Having条件
|
||||
* @author wenshao
|
||||
*
|
||||
*/
|
||||
public class WallSelectWhereTest5 extends TestCase {
|
||||
private String sql = "select * from t WHERE FID = 256 OR CONCAT(CHR(67)||CHR(65)||CHR(84), '-DOG') = 'CAT-DOG'";
|
||||
|
||||
public void testMySql() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateMySql(sql));
|
||||
}
|
||||
|
||||
public void testORACLE() throws Exception {
|
||||
Assert.assertFalse(WallUtils.isValidateOracle(sql));
|
||||
}
|
||||
}
|
||||
@@ -18,23 +18,31 @@ public class WallVisitorUtilsTest extends TestCase {
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("f1 like '%%'")));
|
||||
Assert.assertEquals(null, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("a1 = b1 AND f1 like '%%'")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("a1 = b1 OR f1 like '%%'")));
|
||||
|
||||
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("1 < 2")));
|
||||
Assert.assertEquals(Boolean.FALSE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("2 < 2")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("2 <= 2")));
|
||||
|
||||
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("2 > 1")));
|
||||
Assert.assertEquals(Boolean.FALSE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("2 > 2")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("2 >= 2")));
|
||||
|
||||
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("len('44') > 0")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("len('44') >= 2")));
|
||||
|
||||
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("(select count(*) from t) > 0")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("(select count(*) from t) >= 0")));
|
||||
Assert.assertEquals(Boolean.FALSE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("(select count(*) from t) < 0")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("NOT (select count(*) from t) < 0")));
|
||||
|
||||
Assert.assertEquals(Boolean.TRUE,
|
||||
WallVisitorUtils.getValue(SQLUtils.toSQLExpr("(select count(*) from t) >= 0")));
|
||||
Assert.assertEquals(Boolean.FALSE,
|
||||
WallVisitorUtils.getValue(SQLUtils.toSQLExpr("(select count(*) from t) < 0")));
|
||||
Assert.assertEquals(Boolean.TRUE,
|
||||
WallVisitorUtils.getValue(SQLUtils.toSQLExpr("NOT (select count(*) from t) < 0")));
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
public void test_chr() throws Exception {
|
||||
Assert.assertEquals("CAT", WallVisitorUtils.getValue(SQLUtils.toSQLExpr("CHR(67)||CHR(65)||CHR(84)")));
|
||||
Assert.assertEquals(Boolean.TRUE, WallVisitorUtils.getValue(SQLUtils.toSQLExpr("CHR(67)||CHR(65)||CHR(84) = 'CAT'")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user