mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve WallFilter, support conditionOpBitwiseAllow
This commit is contained in:
@@ -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
|
||||
*
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user