Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug:LOCK TABLES table_name write 在mysql防火墙校验的时候会过不了校验 #2014

Merged
merged 2 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));


}

}