mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
#2000 作为firewall使用在mysql上的时候lock tables .. write过不了校验
This commit is contained in:
@@ -25,25 +25,19 @@ import com.alibaba.druid.wall.Violation;
|
||||
import com.alibaba.druid.wall.WallCheckResult;
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.spi.MySqlWallProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MySqlResourceWallTest extends TestCase {
|
||||
|
||||
private String[] items;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
// File file = new File("/home/wenshao/error_sql");
|
||||
File file = new File("/home/wenshao/scan_result");
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
String text = Utils.read(is);
|
||||
is.close();
|
||||
items = text.split("\\|\\n\\|");
|
||||
}
|
||||
|
||||
public void test_false() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
|
||||
|
||||
provider.getConfig().setConditionDoubleConstAllow(true);
|
||||
|
||||
|
||||
provider.getConfig().setUseAllow(true);
|
||||
provider.getConfig().setStrictSyntaxCheck(false);
|
||||
provider.getConfig().setMultiStatementAllow(true);
|
||||
@@ -76,4 +70,40 @@ public class MySqlResourceWallTest extends TestCase {
|
||||
// Assert.assertFalse(provider.checkValid(sql));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void test_lock_table() throws Exception {
|
||||
WallProvider provider = new MySqlWallProvider();
|
||||
provider.getConfig().setNoneBaseStatementAllow(true);
|
||||
|
||||
String sql = "lock tables etstsun write";
|
||||
WallCheckResult result = provider.check(sql);
|
||||
if (result.getViolations().size() > 0) {
|
||||
Violation violation = result.getViolations().get(0);
|
||||
System.out.println("error () : " + violation.getMessage());
|
||||
}
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
|
||||
|
||||
sql = "lock tables etstsun LOW_PRIORITY write";
|
||||
result = provider.check(sql);
|
||||
if (result.getViolations().size() > 0) {
|
||||
Violation violation = result.getViolations().get(0);
|
||||
System.out.println("error () : " + violation.getMessage());
|
||||
}
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
|
||||
|
||||
sql = "UNLOCK TABLES";
|
||||
result = provider.check(sql);
|
||||
if (result.getViolations().size() > 0) {
|
||||
Violation violation = result.getViolations().get(0);
|
||||
System.out.println("error () : " + violation.getMessage());
|
||||
}
|
||||
Assert.assertTrue(provider.checkValid(sql));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user