improve WallFilter, support conditionOpBitwiseAllow

This commit is contained in:
wenshao
2013-03-19 01:12:11 +08:00
parent 9e12ffb86e
commit 19b24d8022
16 changed files with 235 additions and 44 deletions
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class BitwiseAndTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 & 2")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 & 2", config)); //
}
}
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class BitwiseInvertTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = ~2")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = ~2", config)); //
}
}
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class BitwiseOrTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 | 2")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 | 2", config)); //
}
}
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class BitwiseXorTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 ^ 2")); //
}
public void test_true() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 ^ 2", config)); //
}
}
@@ -0,0 +1,23 @@
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class BooleanXorTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 XOR id = 2")); //
}
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)); //
}
}
@@ -4,12 +4,20 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallConfig;
import com.alibaba.druid.wall.WallUtils;
public class ConstantArithmeticCheckTest extends TestCase {
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 3 - 1")); //
}
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConstArithmeticAllow(false);
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 3 - 1")); //
"SELECT * from t where id = 3 - 1", config)); //
}
}
@@ -22,7 +22,6 @@ import org.junit.Assert;
import com.alibaba.druid.wall.WallUtils;
/**
* 这个场景,检测可疑的Having条件
* @author wenshao
*
*/