use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.
the class WallStatTest_WhiteList_disable method testMySql.
public void testMySql() throws Exception {
WallProvider provider = new MySqlWallProvider();
provider.setBlackListEnable(false);
provider.setWhiteListEnable(false);
for (int i = 0; i < 301; ++i) {
String sql = "select * from t where id = " + i;
Assert.assertTrue(provider.checkValid(sql));
}
for (int i = 0; i < 301; ++i) {
String sql = "select * from t where id = " + i + " OR 1 = 1";
Assert.assertFalse(provider.checkValid(sql));
}
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(602, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getBlackListHitCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(602, provider.getCheckCount());
}
use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.
the class WallStatTest_alter_table method testMySql.
public void testMySql() throws Exception {
String sql = "alter table t add column fname varchar(50)";
WallProvider provider = new MySqlWallProvider();
provider.getConfig().setAlterTableAllow(true);
Assert.assertTrue(provider.checkValid(sql));
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(1, tableStat.getAlterCount());
}
use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.
the class WallStatTest_blackList_syntaxError method testMySql.
public void testMySql() throws Exception {
WallProvider provider = new MySqlWallProvider();
String sql = "select xx * x *";
Assert.assertFalse(provider.checkValid(sql));
{
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(0, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getBlackListHitCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(1, provider.getBlackList().size());
Assert.assertEquals(1, provider.getCheckCount());
Assert.assertEquals(1, provider.getSyntaxErrorCount());
Assert.assertEquals(1, provider.getHardCheckCount());
}
Assert.assertFalse(provider.checkValid(sql));
{
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(0, tableStat.getSelectCount());
Assert.assertEquals(1, provider.getBlackListHitCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(0, provider.getWhiteList().size());
Assert.assertEquals(1, provider.getBlackList().size());
Assert.assertEquals(2, provider.getCheckCount());
Assert.assertEquals(2, provider.getSyntaxErrorCount());
Assert.assertEquals(1, provider.getHardCheckCount());
}
}
use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.
the class WallStatTest_blacklist method testMySql.
public void testMySql() throws Exception {
WallProvider provider = new MySqlWallProvider();
for (int i = 0; i < 10; ++i) {
Assert.assertFalse(provider.checkValid(sql));
}
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(10, tableStat.getSelectCount());
Assert.assertEquals(0, provider.getWhiteListHitCount());
Assert.assertEquals(9, provider.getBlackListHitCount());
}
use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.
the class WallStatTest_create_table method testPG.
public void testPG() throws Exception {
WallProvider provider = new PGWallProvider();
provider.getConfig().setCreateTableAllow(true);
Assert.assertTrue(provider.checkValid(sql));
WallTableStat tableStat = provider.getTableStat("t");
Assert.assertEquals(1, tableStat.getCreateCount());
}
Aggregations