Search in sources :

Example 16 with WallProvider

use of com.alibaba.druid.wall.WallProvider 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 17 with WallProvider

use of com.alibaba.druid.wall.WallProvider 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 18 with WallProvider

use of com.alibaba.druid.wall.WallProvider 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)

Example 19 with WallProvider

use of com.alibaba.druid.wall.WallProvider in project druid by alibaba.

the class WallStatTest_create_table method testSQLServer.

public void testSQLServer() throws Exception {
    WallProvider provider = new SQLServerWallProvider();
    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) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider)

Example 20 with WallProvider

use of com.alibaba.druid.wall.WallProvider in project druid by alibaba.

the class WallStatTest_delete method testPG.

public void testPG() throws Exception {
    WallProvider provider = new PGWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(1, tableStat.getDeleteCount());
}
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

WallProvider (com.alibaba.druid.wall.WallProvider)195 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)182 SQLServerWallProvider (com.alibaba.druid.wall.spi.SQLServerWallProvider)47 WallTableStat (com.alibaba.druid.wall.WallTableStat)41 PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)36 OracleWallProvider (com.alibaba.druid.wall.spi.OracleWallProvider)34 WallCheckResult (com.alibaba.druid.wall.WallCheckResult)3 Violation (com.alibaba.druid.wall.Violation)2 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)1 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)1 WallConfig (com.alibaba.druid.wall.WallConfig)1 WallFunctionStat (com.alibaba.druid.wall.WallFunctionStat)1 Map (java.util.Map)1 Test (org.junit.Test)1