bug fixed for sql wall

This commit is contained in:
温少
2012-03-17 21:39:45 +08:00
parent 122d9e1559
commit 694b89d2e3
4 changed files with 44 additions and 6 deletions
@@ -29,7 +29,7 @@ public class WallConfig {
private boolean truncateAllow = false;
private boolean shcemaCheck = true;
private boolean schemaCheck = true;
private boolean tableCheck = true;
private boolean functionCheck = true;
private boolean objectCheck = true;
@@ -194,12 +194,12 @@ public class WallConfig {
this.mergeAllow = mergeAllow;
}
public boolean isShcemaCheck() {
return shcemaCheck;
public boolean isSchemaCheck() {
return schemaCheck;
}
public void setShcemaCheck(boolean shcemaCheck) {
this.shcemaCheck = shcemaCheck;
public void setSchemaCheck(boolean schemaCheck) {
this.schemaCheck = schemaCheck;
}
public boolean isTableCheck() {
@@ -257,16 +257,28 @@ public class WallConfig {
}
public boolean isPermitObjects(String name) {
if (!objectCheck) {
return false;
}
name = WallVisitorUtils.form(name);
return permitObjects.contains(name);
}
public boolean isPermitSchema(String name) {
if (!schemaCheck) {
return false;
}
name = WallVisitorUtils.form(name);
return this.permitSchemas.contains(name);
}
public boolean isPermitFunction(String name) {
if (!functionCheck) {
return false;
}
name = WallVisitorUtils.form(name);
return this.permitFunctions.contains(name);
}
@@ -2,6 +2,7 @@ package com.alibaba.druid.bvt.filter.wall;
import org.junit.Assert;
import com.alibaba.druid.filter.wall.WallConfig;
import com.alibaba.druid.filter.wall.WallUtils;
import junit.framework.TestCase;
@@ -13,8 +14,15 @@ import junit.framework.TestCase;
*/
public class MySqlWallPermitTableTest extends TestCase {
public void test_permitTable() throws Exception {
public void test_default() throws Exception {
Assert.assertFalse(WallUtils.isValidateMySql("select benchmark( 500000, sha1( 'test' ) )"));
}
public void test_allow() throws Exception {
WallConfig config = new WallConfig();
config.setTableCheck(false);
Assert.assertTrue(WallUtils.isValidateMySql("select benchmark( 500000, sha1( 'test' ) )", config));
}
}
@@ -4,6 +4,7 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.filter.wall.WallConfig;
import com.alibaba.druid.filter.wall.WallUtils;
/**
@@ -17,4 +18,10 @@ public class OracleWallPermitFunctionTest extends TestCase {
Assert.assertFalse(WallUtils.isValidateOracle("select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual"));
}
public void test_permitTable_allow() throws Exception {
WallConfig config = new WallConfig();
config.setFunctionCheck(false);
Assert.assertTrue(WallUtils.isValidateOracle("select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual", config));
}
}
@@ -4,6 +4,7 @@ import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.filter.wall.WallConfig;
import com.alibaba.druid.filter.wall.WallUtils;
/**
@@ -22,4 +23,14 @@ public class OracleWallPermitObjectTest extends TestCase {
Assert.assertFalse(WallUtils.isValidateOracle("select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES()"));
}
public void test_permitTable_allow() throws Exception {
WallConfig config = new WallConfig();
config.setObjectCheck(false);
Assert.assertTrue(WallUtils.isValidateOracle("select sys.LinxReadFile('c:/boot.ini') from dual", config));
Assert.assertTrue(WallUtils.isValidateOracle("select sys.LinxRunCMD('cmd /c net user linx /add') from dual", config));
Assert.assertTrue(WallUtils.isValidateOracle("select utl_inaddr.get_host_address from DUAL", config));
Assert.assertTrue(WallUtils.isValidateOracle("select TO_CHAR(utl_inaddr.get_host_address) from DUAL", config));
Assert.assertTrue(WallUtils.isValidateOracle("SELECT SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES('FOO','BAR','DBMS_OUTPUT'.PUT(:P1));", config));
Assert.assertTrue(WallUtils.isValidateOracle("select SYS.DBMS_EXPORT_EXTENSION.GET_DOMAIN_INDEX_TABLES()", config));
}
}