Search in sources :

Example 11 with WallProvider

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

the class WallStatTest_select_1 method testPG.

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

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

the class WallStatTest_select_1 method testSQLServer.

public void testSQLServer() throws Exception {
    WallProvider provider = new SQLServerWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    {
        WallTableStat tableStat = provider.getTableStat("lhwbbs_posts_reply");
        Assert.assertEquals(1, tableStat.getSelectCount());
    }
    {
        WallTableStat tableStat = provider.getTableStat("lhwbbs_posts");
        Assert.assertEquals(1, tableStat.getSelectCount());
    }
}
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 13 with WallProvider

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

the class WallStatTest_select_1 method testMySql.

public void testMySql() throws Exception {
    WallProvider provider = new MySqlWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    {
        WallTableStat tableStat = provider.getTableStat("lhwbbs_posts_reply");
        Assert.assertEquals(1, tableStat.getSelectCount());
    }
    {
        WallTableStat tableStat = provider.getTableStat("lhwbbs_posts");
        Assert.assertEquals(1, tableStat.getSelectCount());
    }
}
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 14 with WallProvider

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

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

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