Search in sources :

Example 11 with WallTableStat

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());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 12 with WallTableStat

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());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) OracleWallProvider(com.alibaba.druid.wall.spi.OracleWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 13 with WallTableStat

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());
    }
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 14 with WallTableStat

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());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 15 with WallTableStat

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());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) OracleWallProvider(com.alibaba.druid.wall.spi.OracleWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider)

Aggregations

WallTableStat (com.alibaba.druid.wall.WallTableStat)42 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)42 WallProvider (com.alibaba.druid.wall.WallProvider)41 OracleWallProvider (com.alibaba.druid.wall.spi.OracleWallProvider)34 PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)34 SQLServerWallProvider (com.alibaba.druid.wall.spi.SQLServerWallProvider)34 WallFunctionStat (com.alibaba.druid.wall.WallFunctionStat)1 WallProviderStatValue (com.alibaba.druid.wall.WallProviderStatValue)1 WallSqlStat (com.alibaba.druid.wall.WallSqlStat)1