This commit is contained in:
wenshao
2013-03-28 09:21:08 +08:00
parent 4d85e96301
commit d22d27ef01
20 changed files with 195 additions and 63 deletions
@@ -10,14 +10,14 @@ import com.alibaba.druid.wall.WallUtils;
public class BitwiseAndTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
Assert.assertTrue(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(//
config.setConditionOpBitwseAllow(false);
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 & 2", config)); //
}
}
@@ -9,15 +9,15 @@ import com.alibaba.druid.wall.WallUtils;
public class BitwiseInvertTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = ~2")); //
}
public void test_true() throws Exception {
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
config.setConditionOpBitwseAllow(false);
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = ~2", config)); //
}
}
@@ -9,15 +9,15 @@ import com.alibaba.druid.wall.WallUtils;
public class BitwiseOrTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 | 2")); //
}
public void test_true() throws Exception {
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
config.setConditionOpBitwseAllow(false);
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 | 2", config)); //
}
}
@@ -9,15 +9,15 @@ import com.alibaba.druid.wall.WallUtils;
public class BitwiseXorTest extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 ^ 2")); //
}
public void test_true() throws Exception {
public void test_false() throws Exception {
WallConfig config = new WallConfig();
config.setConditionOpBitwseAllow(true);
Assert.assertTrue(WallUtils.isValidateMySql(//
config.setConditionOpBitwseAllow(false);
Assert.assertFalse(WallUtils.isValidateMySql(//
"SELECT * from t where id = 1 ^ 2", config)); //
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallUtils;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class MySqlWallTest20 extends TestCase {
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SET sql_mode=?,NAMES ?,CHARACTER SET utf8,CHARACTER_SET_RESULTS=utf8,COLLATION_CONNECTION=?")); //
}
}
@@ -0,0 +1,42 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.bvt.filter.wall;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.wall.WallUtils;
/**
* SQLServerWallTest
*
* @author RaymondXiu
* @version 1.0, 2012-3-18
* @see
*/
public class MySqlWallTest21 extends TestCase {
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"select * from t where 1=1 AND status = 1")); //
}
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
"select * from t where status = 1 AND 1=1")); //
}
}
@@ -30,8 +30,8 @@ import com.alibaba.druid.wall.WallUtils;
*/
public class MySqlWallTest8 extends TestCase {
public void test_false() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(//
public void test_true() throws Exception {
Assert.assertTrue(WallUtils.isValidateMySql(//
"SELECT a.* FROM vote_info a where 1=1 AND FID = ?")); // 前置永真
}
@@ -30,10 +30,10 @@ public class WallSelectWhereTest2 extends TestCase {
private String sql = "SELECT F1, F2 WHERE 1 = 1 AND FID = ?";
public void testMySql() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql(sql));
Assert.assertTrue(WallUtils.isValidateMySql(sql));
}
public void testORACLE() throws Exception {
Assert.assertFalse(WallUtils.isValidateOracle(sql));
Assert.assertTrue(WallUtils.isValidateOracle(sql));
}
}
@@ -32,8 +32,7 @@ public class DMLDeleteParserTest extends TestCase {
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("DELETE LOW_PRIORITY FROM id1.id, id\n" + //
"USING t1 a" + //
Assert.assertEquals("DELETE LOW_PRIORITY FROM id1.id, id USING (t1) AS a" + //
"\nWHERE col1 = ?", output);
}
@@ -53,8 +52,8 @@ public class DMLDeleteParserTest extends TestCase {
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("DELETE FROM offer.*, wp_image.*\n" + //
"USING offer a, wp_image b\n" + //
Assert.assertEquals("DELETE FROM offer.*, wp_image.*" + //
" USING (offer) AS a, wp_image b\n" + //
"WHERE a.member_id = b.member_id\n" + //
"\tAND a.member_id = 'abc'", output);
}
@@ -73,7 +73,7 @@ public class DeleteSyntaxTest extends TestCase {
String text = output(stmtList);
Assert.assertEquals("DELETE FROM a1, a2\nUSING t1 a1" + //
Assert.assertEquals("DELETE FROM a1, a2 USING (t1) AS a1" + //
"\n\tINNER JOIN t2 a2\nWHERE a1.id = a2.id;", text);
}
@@ -46,14 +46,15 @@ public class MySqlDeleteTest_1 extends MysqlTest {
System.out.println("coditions : " + visitor.getConditions());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(3, visitor.getTables().size());
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getConditions().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t1")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("a1")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("a2")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
Assert.assertTrue(visitor.getColumns().contains(new Column("t1", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("a1", "id")));
Assert.assertTrue(visitor.getColumns().contains(new Column("a2", "id")));
}
}