improve WallFilter

This commit is contained in:
wenshao
2013-03-18 21:28:35 +08:00
parent 0163cb488a
commit 434b11695a
12 changed files with 227 additions and 233 deletions
@@ -0,0 +1,15 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallUtils;
public class ConstantArithmeticCheckTest extends TestCase {
public void test_true() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 3 - 1")); //
}
}
@@ -19,6 +19,7 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
/**
@@ -30,13 +31,27 @@ import com.alibaba.druid.wall.WallUtils;
*/
public class MySqlWallTest2 extends TestCase {
public void test_stuff() throws Exception {
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setConstArithmeticAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
"select * from person_qingjia " + //
"where isxiao=1 " + //
"and ((starttime between 2013-01-15 and 2013-01-15)" + //
" or (endtime between 2013-01- 15 and 2013-01-15)" + //
") " + //
"order by xiaojiatime desc"));
"order by xiaojiatime desc", config));
}
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConstArithmeticAllow(true);
Assert.assertFalse(WallUtils.isValidateMySql(//
"select * from person_qingjia " + //
"where isxiao=1 " + //
"and ((starttime between 2013-01-15 and 2013-01-15)" + //
" or (endtime between 2013-01- 15 and 2013-01-15)" + //
") " + //
"order by xiaojiatime desc", config));
}
}