Skip to content

Commit

Permalink
Merge pull request #2014 from sunsun314/master
Browse files Browse the repository at this point in the history
fix bug:LOCK TABLES table_name write 在mysql防火墙校验的时候会过不了校验
  • Loading branch information
wenshao authored Sep 28, 2017
2 parents 260579e + b1dadc7 commit e7dd64c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,12 @@ public boolean parseStatementListDialect(List<SQLStatement> statementList) {
stmt.setLockType(LockType.READ);
}
} else if (lexer.identifierEquals(WRITE)) {
lexer.nextToken();
stmt.setLockType(LockType.WRITE);
} else if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
lexer.nextToken();
acceptIdentifier(WRITE);
lexer.nextToken();
stmt.setLockType(LockType.LOW_PRIORITY_WRITE);
} else {
throw new ParserException("syntax error, expect READ or WRITE, actual " + lexer.token() + ", " + lexer.info());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,19 @@
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);
Expand Down Expand Up @@ -76,4 +70,58 @@ public void test_false() throws Exception {
// 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));


sql = "lock table dsdfsdf read";
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 table dsdfsdf read local";
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));


}

}

0 comments on commit e7dd64c

Please sign in to comment.