未验证 提交 6b105f52 编写于 作者: L Liang Zhang 提交者: GitHub

Refactor parameterized encrypt test cases (#3245)

* Use yaml to setup encrypt rewrite engine

* make sense of column for table t_encrypt

* rename table t_encrypt to t_cipher

* make sense of column for table t_cipher_assisted_query

* make sense of column for table t_cipher_plain

* make sense of column for table t_cipher_assisted_query_plain

* simplify column name of EncryptSQLRewriteEngineTest

* use real parse engine for sharding test

* fix case for ShardingSQLRewriteEngineTest.assertRewriteSelectInWithAggregationDistinct

* fix test cases for SHOW XXX

* fix test case for assertRewriteInsertWithGeneratedKeyAndQueryAssistedShardingEncryptor

* fix test case for assertRewriteTableTokenWithSchemaForInsert

* refactor type of encrypt fixture

* add EncryptSQLRewriteEngineParameterizedTest

* add EncryptSQLRewriteEngineParameterizedTest

* add all insert case into new test engine

* refactor jaxb

* refactor insert.xml

* add insert_values_for_encrypt_only_with_literal

* refactor TestShardingEncryptor & TestQueryAssistedShardingEncryptor, make encrypt value more accurate

* split insert values and insert set

* add insert_set_for_query_encrypt_with_literal

* add insert_set_for_encrypt_only

* finish insert test case for encrypt

* add delete_query_with_cipher.xml

* add file name for test case

* add delete_query_without_cipher

* fix query_plain_encrypt

* fix plain_encrypt_with_literals

* fix all delete cases

* add fixme for sql92 bug

* adjust seq of test cases

* add update_query_with_cipher

* add update_query_without_cipher

* add select_query_with_cipher

* add select_query_without_cipher

* remove useless EncryptSQLRewriteEngineTest

* fix ShardingSQLRewriteEngineTest

* permit multiple output for sharding assert

* rename jaxb.entity

* add ShardingSQLRewriteEngineParameterizedTest

* add ShardingSQLRewriteEngineParameterizedTest

* remove ShardingSQLRewriteEngineParameterizedTest.LOGIC_AND_ACTUAL_TABLES

* rename table_z to t_encrypt for sharding-rewrite-rule.xml

* move encrypt.yaml

* refactor fixture

* add insert_into_with_parameters

* finish insert_for_normal_encrypt_for_query_with_cipher

* add assisted_query for insert_for_query_with_cipher

* finish delete_for_query_with_cipher

* finish delete_for_query_with_plain

* delete old delete test case

* finish update_for_query_with_cipher

* finish update_for_query_with_plain

* delete old update test cases

* add select_for_query_with_cipher

* add select_for_query_with_plain

* remove old select test cases

* finish encrypt test cases
上级 03bf7111
......@@ -657,13 +657,6 @@ public final class ShardingSQLRewriteEngineTest {
return result;
}
@Test
public void assertRewriteTableTokenWithoutBackQuoteForShow() {
SQLRewriteResult actual = getSQLRewriteResult("SHOW COLUMNS FROM table_x", Collections.emptyList(), true);
assertThat(actual.getSql(), is("SHOW COLUMNS FROM table_1"));
assertThat(actual.getParameters(), is(Collections.emptyList()));
}
@Test
public void assertRewriteTableTokenWithoutBackQuoteFromSchemaForShow() {
SQLRewriteResult actual = getSQLRewriteResult("SHOW COLUMNS FROM table_x FROM `sharding_db`", Collections.emptyList(), true);
......@@ -757,15 +750,15 @@ public final class ShardingSQLRewriteEngineTest {
@Test
public void assertRewriteSelectInWithShardingEncryptorWithCipher() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id in (3,5)", Collections.emptyList(), true);
assertThat(actual.getSql(), is("SELECT cipher FROM table_z WHERE cipher IN ('encrypt_3', 'encrypt_5')"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password in (3,5)", Collections.emptyList(), true);
assertThat(actual.getSql(), is("SELECT cipher_password FROM t_cipher WHERE cipher_password IN ('encrypt_3', 'encrypt_5')"));
assertThat(actual.getParameters(), is(Collections.emptyList()));
}
@Test
public void assertRewriteSelectInWithShardingEncryptorWithPlain() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id in (3,5)", Collections.emptyList(), false);
assertThat(actual.getSql(), is("SELECT plain FROM table_z WHERE plain IN (3, 5)"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password in (3,5)", Collections.emptyList(), false);
assertThat(actual.getSql(), is("SELECT plain_password FROM t_cipher WHERE plain_password IN (3, 5)"));
assertThat(actual.getParameters(), is(Collections.emptyList()));
}
......@@ -778,8 +771,8 @@ public final class ShardingSQLRewriteEngineTest {
@Test
public void assertRewriteUpdateWithShardingEncryptor() {
SQLRewriteResult actual = getSQLRewriteResult("UPDATE table_z SET id = 1 WHERE id = 2", Collections.emptyList(), true);
assertThat(actual.getSql(), is("UPDATE table_z SET cipher = 'encrypt_1', plain = 1 WHERE cipher = 'encrypt_2'"));
SQLRewriteResult actual = getSQLRewriteResult("UPDATE t_cipher SET password = 1 WHERE password = 2", Collections.emptyList(), true);
assertThat(actual.getSql(), is("UPDATE t_cipher SET cipher_password = 'encrypt_1', plain_password = 1 WHERE cipher_password = 'encrypt_2'"));
assertThat(actual.getParameters(), is(Collections.emptyList()));
}
......@@ -792,36 +785,36 @@ public final class ShardingSQLRewriteEngineTest {
@Test
public void assertRewriteSelectInWithAggregationDistinct() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT COUNT(DISTINCT id) a, SUM(DISTINCT id) a FROM table_z WHERE id IN (3,5)", Collections.emptyList(), true);
assertThat(actual.getSql(), is("SELECT DISTINCT id a, id a FROM table_z WHERE cipher IN ('encrypt_3', 'encrypt_5')"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT COUNT(DISTINCT id) a, SUM(DISTINCT id) a FROM table_x WHERE id IN (3,5)", Collections.emptyList(), true);
assertThat(actual.getSql(), is("SELECT DISTINCT id a, id a FROM table_1 WHERE id IN (3,5)"));
assertThat(actual.getParameters(), is(Collections.emptyList()));
}
@Test
public void assertRewriteSelectEqualWithShardingEncryptorWithCipher() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id=? AND name=?", Arrays.<Object>asList(1, "x"), true);
assertThat(actual.getSql(), is("SELECT cipher FROM table_z WHERE cipher = ? AND name=?"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password=? AND name=?", Arrays.<Object>asList(1, "x"), true);
assertThat(actual.getSql(), is("SELECT cipher_password FROM t_cipher WHERE cipher_password = ? AND name=?"));
assertThat(actual.getParameters(), is(Arrays.<Object>asList("encrypt_1", "x")));
}
@Test
public void assertRewriteSelectEqualWithShardingEncryptorWithPlain() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id=? AND name=?", Arrays.<Object>asList(1, "x"), false);
assertThat(actual.getSql(), is("SELECT plain FROM table_z WHERE plain = ? AND name=?"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password=? AND name=?", Arrays.<Object>asList(1, "x"), false);
assertThat(actual.getSql(), is("SELECT plain_password FROM t_cipher WHERE plain_password = ? AND name=?"));
assertThat(actual.getParameters(), is(Arrays.<Object>asList(1, "x")));
}
@Test
public void assertRewriteSelectInWithShardingEncryptorWithParameterWithCipher() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id in (?, ?) or id = 3", Arrays.<Object>asList(1, 2), true);
assertThat(actual.getSql(), is("SELECT cipher FROM table_z WHERE cipher IN (?, ?) or cipher = 'encrypt_3'"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password in (?, ?) or password = 3", Arrays.<Object>asList(1, 2), true);
assertThat(actual.getSql(), is("SELECT cipher_password FROM t_cipher WHERE cipher_password IN (?, ?) or cipher_password = 'encrypt_3'"));
assertThat(actual.getParameters(), is(Arrays.<Object>asList("encrypt_1", "encrypt_2")));
}
@Test
public void assertRewriteSelectInWithShardingEncryptorWithParameterWithPlain() {
SQLRewriteResult actual = getSQLRewriteResult("SELECT id FROM table_z WHERE id in (?, ?) or id = 3", Arrays.<Object>asList(1, 2), false);
assertThat(actual.getSql(), is("SELECT plain FROM table_z WHERE plain IN (?, ?) or plain = 3"));
SQLRewriteResult actual = getSQLRewriteResult("SELECT password FROM t_cipher WHERE password in (?, ?) or password = 3", Arrays.<Object>asList(1, 2), false);
assertThat(actual.getSql(), is("SELECT plain_password FROM t_cipher WHERE plain_password IN (?, ?) or plain_password = 3"));
assertThat(actual.getParameters(), is(Arrays.<Object>asList(1, 2)));
}
......
......@@ -25,13 +25,13 @@ import java.util.Properties;
@Getter
@Setter
public final class TestShardingEncryptor implements ShardingEncryptor {
public final class NormalEncryptorFixture implements ShardingEncryptor {
private Properties properties = new Properties();
@Override
public String getType() {
return "TEST";
return "NORMAL_ENCRYPT";
}
@Override
......
......@@ -25,13 +25,13 @@ import java.util.Properties;
@Getter
@Setter
public final class TestQueryAssistedShardingEncryptor implements ShardingQueryAssistedEncryptor {
public final class QueryAssistedEncryptorFixture implements ShardingQueryAssistedEncryptor {
private Properties properties = new Properties();
@Override
public String getType() {
return "ASSISTED_QUERY_TEST";
return "ASSISTED_QUERY_ENCRYPT";
}
@Override
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.fixture;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;
import java.util.Properties;
@Getter
@Setter
public final class ShardingKeyGeneratorFixture implements ShardingKeyGenerator {
private Properties properties = new Properties();
@Override
public Comparable<?> generateKey() {
return 1L;
}
@Override
public String getType() {
return "TEST";
}
}
......@@ -30,8 +30,8 @@ import org.apache.shardingsphere.core.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.core.rewrite.engine.SQLRewriteResult;
import org.apache.shardingsphere.core.rewrite.engine.impl.DefaultSQLRewriteEngine;
import org.apache.shardingsphere.core.rewrite.feature.encrypt.context.EncryptSQLRewriteContextDecorator;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.EncryptRewriteAssertionEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.EncryptRewriteAssertionsRootEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteAssertionEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteAssertionsRootEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.loader.EncryptRewriteAssertionsRootEntityLoader;
import org.apache.shardingsphere.core.rule.EncryptRule;
import org.apache.shardingsphere.core.yaml.config.encrypt.YamlRootEncryptRuleConfiguration;
......@@ -62,6 +62,8 @@ import static org.mockito.Mockito.mock;
@RequiredArgsConstructor
public final class EncryptSQLRewriteEngineParameterizedTest {
private static final String PATH = "encrypt";
private final String fileName;
private final String ruleFile;
......@@ -81,39 +83,39 @@ public final class EncryptSQLRewriteEngineParameterizedTest {
@Parameters(name = "{2} -> {0}")
public static Collection<Object[]> getTestParameters() {
Collection<Object[]> result = new LinkedList<>();
for (Entry<String, EncryptRewriteAssertionsRootEntity> entry : getAllEncryptRewriteAssertionsRootEntities().entrySet()) {
for (Entry<String, RewriteAssertionsRootEntity> entry : getAllRewriteAssertionsRootEntities().entrySet()) {
result.addAll(getTestParameters(entry.getKey(), entry.getValue()));
}
return result;
}
private static Collection<Object[]> getTestParameters(final String fileName, final EncryptRewriteAssertionsRootEntity rootAssertions) {
private static Collection<Object[]> getTestParameters(final String fileName, final RewriteAssertionsRootEntity rootAssertions) {
Collection<Object[]> result = new LinkedList<>();
for (EncryptRewriteAssertionEntity each : rootAssertions.getAssertions()) {
for (RewriteAssertionEntity each : rootAssertions.getAssertions()) {
result.add(getTestParameter(fileName, rootAssertions, each));
}
return result;
}
private static Object[] getTestParameter(final String fileName, final EncryptRewriteAssertionsRootEntity rootAssertions, final EncryptRewriteAssertionEntity assertion) {
private static Object[] getTestParameter(final String fileName, final RewriteAssertionsRootEntity rootAssertions, final RewriteAssertionEntity assertion) {
Object[] result = new Object[8];
result[0] = fileName;
result[1] = rootAssertions.getYamlRule();
result[2] = assertion.getId();
result[3] = assertion.getInput().getSql();
result[4] = null == assertion.getInput().getParameters() ? Collections.emptyList() : Splitter.on(",").trimResults().splitToList(assertion.getInput().getParameters());
result[5] = assertion.getOutput().getSql();
result[6] = null == assertion.getOutput().getParameters() ? Collections.emptyList() : Splitter.on(",").trimResults().splitToList(assertion.getOutput().getParameters());
result[5] = assertion.getOutputs().get(0).getSql();
result[6] = null == assertion.getOutputs().get(0).getParameters() ? Collections.emptyList() : Splitter.on(",").trimResults().splitToList(assertion.getOutputs().get(0).getParameters());
result[7] = assertion.getDatabaseType();
return result;
}
private static Map<String, EncryptRewriteAssertionsRootEntity> getAllEncryptRewriteAssertionsRootEntities() {
Map<String, EncryptRewriteAssertionsRootEntity> result = new LinkedHashMap<>();
File file = new File(EncryptSQLRewriteEngineParameterizedTest.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "/encrypt");
private static Map<String, RewriteAssertionsRootEntity> getAllRewriteAssertionsRootEntities() {
Map<String, RewriteAssertionsRootEntity> result = new LinkedHashMap<>();
File file = new File(EncryptSQLRewriteEngineParameterizedTest.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "/" + PATH);
for (File each : Objects.requireNonNull(file.listFiles())) {
if (each.getName().endsWith(".xml")) {
result.put(each.getName(), new EncryptRewriteAssertionsRootEntityLoader().load("encrypt/" + each.getName()));
result.put(each.getName(), new EncryptRewriteAssertionsRootEntityLoader().load(PATH + "/" + each.getName()));
}
}
return result;
......@@ -128,9 +130,9 @@ public final class EncryptSQLRewriteEngineParameterizedTest {
private SQLRewriteResult getSQLRewriteResult() throws IOException {
SQLRewriteContext sqlRewriteContext = getSQLRewriteContext();
YamlRootEncryptRuleConfiguration encryptRuleConfiguration = createEncryptRuleConfiguration();
EncryptRule encryptRule = new EncryptRule(new EncryptRuleConfigurationYamlSwapper().swap(encryptRuleConfiguration.getEncryptRule()));
boolean isQueryWithCipherColumn = (boolean) encryptRuleConfiguration.getProps().get("query.with.cipher.column");
YamlRootEncryptRuleConfiguration ruleConfiguration = createRuleConfiguration();
EncryptRule encryptRule = new EncryptRule(new EncryptRuleConfigurationYamlSwapper().swap(ruleConfiguration.getEncryptRule()));
boolean isQueryWithCipherColumn = (boolean) ruleConfiguration.getProps().get("query.with.cipher.column");
new EncryptSQLRewriteContextDecorator(encryptRule, isQueryWithCipherColumn).decorate(sqlRewriteContext);
return new DefaultSQLRewriteEngine().rewrite(sqlRewriteContext);
}
......@@ -141,7 +143,7 @@ public final class EncryptSQLRewriteEngineParameterizedTest {
return new SQLRewriteContext(mock(TableMetas.class), sqlStatementContext, inputSQL, inputParameters);
}
private YamlRootEncryptRuleConfiguration createEncryptRuleConfiguration() throws IOException {
private YamlRootEncryptRuleConfiguration createRuleConfiguration() throws IOException {
URL url = EncryptSQLRewriteEngineParameterizedTest.class.getClassLoader().getResource(ruleFile);
Preconditions.checkNotNull(url, "Cannot found rewrite rule yaml configuration.");
return YamlEngine.unmarshal(new File(url.getFile()), YamlRootEncryptRuleConfiguration.class);
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.parameterized.engine;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.core.database.DatabaseTypes;
import org.apache.shardingsphere.core.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.core.metadata.table.TableMetas;
import org.apache.shardingsphere.core.parse.SQLParseEngine;
import org.apache.shardingsphere.core.parse.sql.statement.SQLStatement;
import org.apache.shardingsphere.core.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.core.rewrite.engine.SQLRewriteResult;
import org.apache.shardingsphere.core.rewrite.feature.encrypt.context.EncryptSQLRewriteContextDecorator;
import org.apache.shardingsphere.core.rewrite.feature.sharding.ShardingSQLRewriteEngineTest;
import org.apache.shardingsphere.core.rewrite.feature.sharding.context.ShardingSQLRewriteContextDecorator;
import org.apache.shardingsphere.core.rewrite.feature.sharding.engine.ShardingSQLRewriteEngine;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteAssertionEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteAssertionsRootEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteOutputEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.loader.EncryptRewriteAssertionsRootEntityLoader;
import org.apache.shardingsphere.core.route.SQLRouteResult;
import org.apache.shardingsphere.core.route.router.sharding.ShardingRouter;
import org.apache.shardingsphere.core.route.type.RoutingUnit;
import org.apache.shardingsphere.core.route.type.TableUnit;
import org.apache.shardingsphere.core.rule.BindingTableRule;
import org.apache.shardingsphere.core.rule.ShardingRule;
import org.apache.shardingsphere.core.yaml.config.sharding.YamlRootShardingConfiguration;
import org.apache.shardingsphere.core.yaml.engine.YamlEngine;
import org.apache.shardingsphere.core.yaml.swapper.impl.ShardingRuleConfigurationYamlSwapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
@RunWith(Parameterized.class)
@RequiredArgsConstructor
public final class ShardingSQLRewriteEngineParameterizedTest {
private static final String PATH = "sharding";
private final String fileName;
private final String ruleFile;
private final String name;
private final String inputSQL;
private final List<Object> inputParameters;
private final List<String> outputSQLs;
private final List<List<Object>> outputGroupedParameters;
private final String databaseType;
@Parameters(name = "{2} -> {0}")
public static Collection<Object[]> getTestParameters() {
Collection<Object[]> result = new LinkedList<>();
for (Entry<String, RewriteAssertionsRootEntity> entry : getAllRewriteAssertionsRootEntities().entrySet()) {
result.addAll(getTestParameters(entry.getKey(), entry.getValue()));
}
return result;
}
private static Collection<Object[]> getTestParameters(final String fileName, final RewriteAssertionsRootEntity rootAssertions) {
Collection<Object[]> result = new LinkedList<>();
for (RewriteAssertionEntity each : rootAssertions.getAssertions()) {
result.add(getTestParameter(fileName, rootAssertions, each));
}
return result;
}
private static Object[] getTestParameter(final String fileName, final RewriteAssertionsRootEntity rootAssertions, final RewriteAssertionEntity assertion) {
Object[] result = new Object[8];
result[0] = fileName;
result[1] = rootAssertions.getYamlRule();
result[2] = assertion.getId();
result[3] = assertion.getInput().getSql();
result[4] = null == assertion.getInput().getParameters() ? Collections.emptyList() : Splitter.on(",").trimResults().splitToList(assertion.getInput().getParameters());
List<RewriteOutputEntity> outputs = assertion.getOutputs();
List<String> outputSQLs = new ArrayList<>(outputs.size());
List<Object> outputGroupedParameters = new ArrayList<>(outputs.size());
for (RewriteOutputEntity each : outputs) {
outputSQLs.add(each.getSql());
outputGroupedParameters.add(null == each.getParameters() ? Collections.emptyList() : Splitter.on(",").trimResults().splitToList(each.getParameters()));
}
result[5] = outputSQLs;
result[6] = outputGroupedParameters;
result[7] = assertion.getDatabaseType();
return result;
}
private static Map<String, RewriteAssertionsRootEntity> getAllRewriteAssertionsRootEntities() {
Map<String, RewriteAssertionsRootEntity> result = new LinkedHashMap<>();
File file = new File(ShardingSQLRewriteEngineParameterizedTest.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "/" + PATH);
for (File each : Objects.requireNonNull(file.listFiles())) {
if (each.getName().endsWith(".xml")) {
result.put(each.getName(), new EncryptRewriteAssertionsRootEntityLoader().load(PATH + "/" + each.getName()));
}
}
return result;
}
@Test
public void assertRewrite() throws IOException {
Collection<SQLRewriteResult> actual = getSQLRewriteResults();
assertThat(actual.size(), is(outputSQLs.size()));
int count = 0;
for (SQLRewriteResult each : actual) {
assertThat(each.getSql(), is(outputSQLs.get(count)));
assertThat(each.getParameters(), is(outputGroupedParameters.get(count)));
count++;
}
}
private Collection<SQLRewriteResult> getSQLRewriteResults() throws IOException {
YamlRootShardingConfiguration ruleConfiguration = createRuleConfiguration();
ShardingRule shardingRule = new ShardingRule(new ShardingRuleConfigurationYamlSwapper().swap(ruleConfiguration.getShardingRule()), ruleConfiguration.getDataSources().keySet());
SQLParseEngine parseEngine = new SQLParseEngine(DatabaseTypes.getActualDatabaseType(null == databaseType ? "SQL92" : databaseType));
ShardingRouter shardingRouter = new ShardingRouter(shardingRule, mock(ShardingSphereMetaData.class), parseEngine);
SQLStatement sqlStatement = shardingRouter.parse(inputSQL, false);
SQLRouteResult sqlRouteResult = shardingRouter.route(inputSQL, inputParameters, sqlStatement);
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(mock(TableMetas.class), sqlRouteResult.getSqlStatementContext(), inputSQL, inputParameters);
new ShardingSQLRewriteContextDecorator(shardingRule, sqlRouteResult).decorate(sqlRewriteContext);
boolean isQueryWithCipherColumn = (boolean) ruleConfiguration.getProps().get("query.with.cipher.column");
new EncryptSQLRewriteContextDecorator(shardingRule.getEncryptRule(), isQueryWithCipherColumn).decorate(sqlRewriteContext);
Collection<SQLRewriteResult> result = new LinkedList<>();
for (RoutingUnit each : sqlRouteResult.getRoutingResult().getRoutingUnits()) {
result.add(new ShardingSQLRewriteEngine(sqlRouteResult.getShardingConditions(),
each, getLogicAndActualTables(shardingRule, each, sqlRouteResult.getSqlStatementContext().getTablesContext().getTableNames())).rewrite(sqlRewriteContext));
}
return result;
}
private YamlRootShardingConfiguration createRuleConfiguration() throws IOException {
URL url = ShardingSQLRewriteEngineTest.class.getClassLoader().getResource(ruleFile);
Preconditions.checkNotNull(url, "Cannot found rewrite rule yaml configuration.");
return YamlEngine.unmarshal(new File(url.getFile()), YamlRootShardingConfiguration.class);
}
private Map<String, String> getLogicAndActualTables(final ShardingRule shardingRule, final RoutingUnit routingUnit, final Collection<String> parsedTableNames) {
Map<String, String> result = new HashMap<>();
for (TableUnit each : routingUnit.getTableUnits()) {
String logicTableName = each.getLogicTableName().toLowerCase();
result.put(logicTableName, each.getActualTableName());
result.putAll(getLogicAndActualTablesFromBindingTable(shardingRule, routingUnit.getMasterSlaveLogicDataSourceName(), each, parsedTableNames));
}
return result;
}
private Map<String, String> getLogicAndActualTablesFromBindingTable(final ShardingRule shardingRule,
final String dataSourceName, final TableUnit tableUnit, final Collection<String> parsedTableNames) {
Map<String, String> result = new LinkedHashMap<>();
Optional<BindingTableRule> bindingTableRule = shardingRule.findBindingTableRule(tableUnit.getLogicTableName());
if (bindingTableRule.isPresent()) {
result.putAll(getLogicAndActualTablesFromBindingTable(dataSourceName, tableUnit, parsedTableNames, bindingTableRule.get()));
}
return result;
}
private Map<String, String> getLogicAndActualTablesFromBindingTable(
final String dataSourceName, final TableUnit tableUnit, final Collection<String> parsedTableNames, final BindingTableRule bindingTableRule) {
Map<String, String> result = new LinkedHashMap<>();
for (String each : parsedTableNames) {
String tableName = each.toLowerCase();
if (!tableName.equals(tableUnit.getLogicTableName().toLowerCase()) && bindingTableRule.hasLogicTable(tableName)) {
result.put(tableName, bindingTableRule.getBindingActualTable(dataSourceName, tableName, tableUnit.getActualTableName()));
}
}
return result;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity;
import lombok.Getter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
/**
* Rewrite assertion entity for JAXB.
*
* @author zhangliang
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
public final class RewriteAssertionEntity {
@XmlAttribute(required = true)
private String id;
@XmlElement(required = true)
private RewriteInputEntity input;
@XmlElement(required = true, name = "output")
private List<RewriteOutputEntity> outputs;
@XmlAttribute(name = "db-type")
private String databaseType;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity;
import lombok.Getter;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collection;
import java.util.LinkedList;
/**
* Rewrite assertions root entity for JAXB.
*
* @author zhangliang
*/
@XmlRootElement(name = "rewrite-assertions")
@Getter
public final class RewriteAssertionsRootEntity {
@XmlAttribute(name = "yaml-rule", required = true)
private String yamlRule;
@XmlElement(name = "rewrite-assertion")
private Collection<RewriteAssertionEntity> assertions = new LinkedList<>();
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity;
import lombok.Getter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
/**
* Rewrite input entity for JAXB.
*
* @author zhangliang
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
public final class RewriteInputEntity {
@XmlAttribute(required = true)
private String sql;
@XmlAttribute
private String parameters;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity;
import lombok.Getter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
/**
* Rewrite input entity for JAXB.
*
* @author zhangliang
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
public final class RewriteOutputEntity {
@XmlAttribute(required = true)
private String sql;
@XmlAttribute
private String parameters;
}
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.core.rewrite.parameterized.jaxb.loader;
import lombok.SneakyThrows;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.EncryptRewriteAssertionsRootEntity;
import org.apache.shardingsphere.core.rewrite.parameterized.jaxb.entity.RewriteAssertionsRootEntity;
import javax.xml.bind.JAXBContext;
import java.io.InputStream;
......@@ -37,9 +37,9 @@ public final class EncryptRewriteAssertionsRootEntityLoader {
* @return rewrite assertions entity for JAXB
*/
@SneakyThrows
public EncryptRewriteAssertionsRootEntity load(final String file) {
public RewriteAssertionsRootEntity load(final String file) {
InputStream inputStream = EncryptRewriteAssertionsRootEntityLoader.class.getClassLoader().getResourceAsStream(file);
return null == inputStream ? new EncryptRewriteAssertionsRootEntity()
: (EncryptRewriteAssertionsRootEntity) JAXBContext.newInstance(EncryptRewriteAssertionsRootEntity.class).createUnmarshaller().unmarshal(inputStream);
return null == inputStream ? new RewriteAssertionsRootEntity()
: (RewriteAssertionsRootEntity) JAXBContext.newInstance(RewriteAssertionsRootEntity.class).createUnmarshaller().unmarshal(inputStream);
}
}
......@@ -15,5 +15,5 @@
# limitations under the License.
#
org.apache.shardingsphere.core.rewrite.fixture.TestShardingEncryptor
org.apache.shardingsphere.core.rewrite.fixture.TestQueryAssistedShardingEncryptor
org.apache.shardingsphere.core.rewrite.fixture.NormalEncryptorFixture
org.apache.shardingsphere.core.rewrite.fixture.QueryAssistedEncryptorFixture
......@@ -15,4 +15,4 @@
# limitations under the License.
#
org.apache.shardingsphere.core.rewrite.fixture.TestShardingKeyGenerator
org.apache.shardingsphere.core.rewrite.fixture.ShardingKeyGeneratorFixture
......@@ -16,28 +16,26 @@
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-without-cipher.yaml">
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_parameters" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_plain WHERE encrypt_1 = ? or encrypt_2 = ?" parameters="1, 2" />
<output sql="SELECT plain_1, plain_2 FROM t_cipher_plain WHERE plain_1 = ? or plain_2 = ?" parameters="1, 2" />
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-cipher.yaml">
<rewrite-assertion id="delete_for_parameters">
<input sql="DELETE FROM t_account WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK" />
<output sql="DELETE FROM t_account WHERE account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND status = ?" parameters="1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_plain WHERE encrypt_1 = 1 or encrypt_2 = 2" />
<output sql="SELECT plain_1, plain_2 FROM t_cipher_plain WHERE plain_1 = 1 or plain_2 = 2" />
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="delete_for_literals" db-type="MySQL">
<input sql="DELETE FROM t_account WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="DELETE FROM t_account WHERE account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK'" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_parameters" db-type="MySQL">
<input sql="SELECT encrypt_1 as alias FROM t_cipher_assisted_query_plain WHERE encrypt_1 in (?, ?) and encrypt_2 in (?, ?)" parameters="1, 2, 3, 4" />
<output sql="SELECT plain_1 as alias FROM t_cipher_assisted_query_plain WHERE plain_1 IN (?, ?) and plain_2 IN (?, ?)" parameters="1, 2, 3, 4" />
<rewrite-assertion id="delete_plain_for_parameters">
<input sql="DELETE FROM t_account_bak WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK" />
<output sql="DELETE FROM t_account_bak WHERE account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND status = ?" parameters="1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="SELECT encrypt_1 as alias FROM t_cipher_assisted_query_plain WHERE encrypt_1 in (1, 2) and encrypt_2 in (3, 4)" />
<output sql="SELECT plain_1 as alias FROM t_cipher_assisted_query_plain WHERE plain_1 IN (1, 2) and plain_2 IN (3, 4)" />
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="delete_for_literals" db-type="MySQL">
<input sql="DELETE FROM t_account_bak WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="DELETE FROM t_account_bak WHERE account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
......@@ -16,25 +16,15 @@
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-without-cipher.yaml">
<rewrite-assertion id="plain_encrypt_with_parameters">
<input sql="DELETE FROM t_cipher_plain WHERE encrypt_1 IN (?, ?) or encrypt_2 IN (?, ?)" parameters="1, 2, 3, 4" />
<output sql="DELETE FROM t_cipher_plain WHERE plain_1 IN (?, ?) or plain_2 IN (?, ?)" parameters="1, 2, 3, 4" />
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-plain.yaml">
<rewrite-assertion id="delete_plain_for_parameters">
<input sql="DELETE FROM t_account_bak WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK" />
<output sql="DELETE FROM t_account_bak WHERE account_id = ? AND plain_password = ? AND plain_amount = ? AND status = ?" parameters="1, aaa, 1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="DELETE FROM t_cipher_plain WHERE encrypt_1 IN (1, '2') or encrypt_2 IN (3, '4')" />
<output sql="DELETE FROM t_cipher_plain WHERE plain_1 IN (1, '2') or plain_2 IN (3, '4')" />
</rewrite-assertion>
<rewrite-assertion id="plain_query_encrypt_with_parameters">
<input sql="DELETE FROM t_cipher_assisted_query_plain WHERE encrypt_1 IN (?, ?) or encrypt_2 IN (?, ?)" parameters="1, 2, 3, 4" />
<output sql="DELETE FROM t_cipher_assisted_query_plain WHERE plain_1 IN (?, ?) or plain_2 IN (?, ?)" parameters="1, 2, 3, 4" />
</rewrite-assertion>
<rewrite-assertion id="plain_query_encrypt_with_literals">
<input sql="DELETE FROM t_cipher_assisted_query_plain WHERE encrypt_1 IN (1, 2) or encrypt_2 IN (3, 4)" />
<output sql="DELETE FROM t_cipher_assisted_query_plain WHERE plain_1 IN (1, 2) or plain_2 IN (3, 4)" />
<rewrite-assertion id="delete_for_literals" db-type="MySQL">
<input sql="DELETE FROM t_account_bak WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="DELETE FROM t_account_bak WHERE account_id = 1 AND plain_password = 'aaa' AND plain_amount = 1000 AND status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-with-cipher.yaml">
<rewrite-assertion id="encrypt_only_with_parameters">
<input sql="DELETE FROM t_cipher WHERE encrypt_1 = ? and encrypt_2 = ?" parameters="1, 2" />
<output sql="DELETE FROM t_cipher WHERE cipher_1 = ? and cipher_2 = ?" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<rewrite-assertion id="encrypt_only_with_literals">
<input sql="DELETE FROM t_cipher WHERE encrypt_1 = 1 and encrypt_2 = 2" />
<output sql="DELETE FROM t_cipher WHERE cipher_1 = 'encrypt_1' and cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_parameters">
<input sql="DELETE FROM t_cipher_assisted_query WHERE encrypt_1 = ? and encrypt_2 = ?" parameters="1, 2"/>
<output sql="DELETE FROM t_cipher_assisted_query WHERE assisted_query_1 = ? and assisted_query_2 = ?" parameters="assisted_query_1, assisted_query_2"/>
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_literals">
<input sql="DELETE FROM t_cipher_assisted_query WHERE encrypt_1 = 1 and encrypt_2 = 2" />
<output sql="DELETE FROM t_cipher_assisted_query WHERE assisted_query_1 = 'assisted_query_1' and assisted_query_2 = 'assisted_query_2'" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_parameters">
<input sql="DELETE FROM t_cipher_plain WHERE encrypt_1 IN (?, ?) or encrypt_2 in (?, ?)" parameters="1, 2, 3, 4" />
<output sql="DELETE FROM t_cipher_plain WHERE cipher_1 IN (?, ?) or cipher_2 IN (?, ?)" parameters="encrypt_1, encrypt_2, encrypt_3, encrypt_4" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="DELETE FROM t_cipher_plain WHERE encrypt_1 IN (1, '2') or encrypt_2 in (3, '4')" />
<output sql="DELETE FROM t_cipher_plain WHERE cipher_1 IN ('encrypt_1', 'encrypt_2') or cipher_2 IN ('encrypt_3', 'encrypt_4')" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="query_plain_encrypt_with_parameters" db-type="MySQL">
<input sql="DELETE FROM t_cipher_assisted_query_plain WHERE encrypt_1 = ? or encrypt_2 IN (?,?,?)" parameters="1, 2, 3, 4" />
<output sql="DELETE FROM t_cipher_assisted_query_plain WHERE assisted_query_1 = ? or assisted_query_2 IN (?, ?, ?)" parameters="assisted_query_1, assisted_query_2, assisted_query_3, assisted_query_4" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="query_plain_encrypt_with_literals" db-type="MySQL">
<input sql="DELETE FROM t_cipher_assisted_query_plain WHERE encrypt_1 = 1 or encrypt_2 IN (2,3,4)" />
<output sql="DELETE FROM t_cipher_assisted_query_plain WHERE assisted_query_1 = 'assisted_query_1' or assisted_query_2 IN ('assisted_query_2', 'assisted_query_3', 'assisted_query_4')" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-cipher.yaml">
<!-- FIXME fix sql92 -->
<rewrite-assertion id="insert_values_for_parameters" db-type="MySQL">
<input sql="INSERT INTO t_account(account_id, password, amount, status) VALUES (?, ?, ?, ?), (2, 'bbb', 2000, 'OK'), (?, ?, ?, ?), (4, 'ddd', 4000, 'OK')" parameters="1, aaa, 1000, OK, 3, ccc, 3000, OK" />
<output sql="INSERT INTO t_account(account_id, cipher_password, cipher_amount, status, assisted_query_password) VALUES (?, ?, ?, ?, ?), (2, 'encrypt_bbb', 'encrypt_2000', 'OK', 'assisted_query_bbb'), (?, ?, ?, ?, ?), (4, 'encrypt_ddd', 'encrypt_4000', 'OK', 'assisted_query_ddd')" parameters="1, encrypt_aaa, encrypt_1000, OK, assisted_query_aaa, 3, encrypt_ccc, encrypt_3000, OK, assisted_query_ccc" />
</rewrite-assertion>
<!-- FIXME fix sql92 -->
<rewrite-assertion id="insert_values_for_literals" db-type="MySQL">
<input sql="INSERT INTO t_account(account_id, password, amount, status) VALUES (1, 'aaa', 1000, 'OK'), (2, 'bbb', 2000, 'OK'), (3, 'ccc', 3000, 'OK'), (4, 'ddd', 4000, 'OK')" />
<output sql="INSERT INTO t_account(account_id, cipher_password, cipher_amount, status, assisted_query_password) VALUES (1, 'encrypt_aaa', 'encrypt_1000', 'OK', 'assisted_query_aaa'), (2, 'encrypt_bbb', 'encrypt_2000', 'OK', 'assisted_query_bbb'), (3, 'encrypt_ccc', 'encrypt_3000', 'OK', 'assisted_query_ccc'), (4, 'encrypt_ddd', 'encrypt_4000', 'OK', 'assisted_query_ddd')" />
</rewrite-assertion>
<!-- FIXME fix sql92 -->
<rewrite-assertion id="insert_values_with_plain_for_parameters" db-type="MySQL">
<input sql="INSERT INTO t_account_bak(account_id, password, amount, status) VALUES (?, ?, ?, ?), (2, 'bbb', 2000, 'OK'), (?, ?, ?, ?), (4, 'ddd', 4000, 'OK')" parameters="1, aaa, 1000, OK, 3, ccc, 3000, OK" />
<output sql="INSERT INTO t_account_bak(account_id, cipher_password, cipher_amount, status, assisted_query_password, plain_password, plain_amount) VALUES (?, ?, ?, ?, ?, ?, ?), (2, 'encrypt_bbb', 'encrypt_2000', 'OK', 'assisted_query_bbb', 'bbb', 2000), (?, ?, ?, ?, ?, ?, ?), (4, 'encrypt_ddd', 'encrypt_4000', 'OK', 'assisted_query_ddd', 'ddd', 4000)" parameters="1, encrypt_aaa, encrypt_1000, OK, assisted_query_aaa, aaa, 1000, 3, encrypt_ccc, encrypt_3000, OK, assisted_query_ccc, ccc, 3000" />
</rewrite-assertion>
<!-- FIXME fix sql92 -->
<rewrite-assertion id="insert_values_with_plain_for_literals" db-type="MySQL">
<input sql="INSERT INTO t_account_bak(account_id, password, amount, status) VALUES (1, 'aaa', 1000, 'OK'), (2, 'bbb', 2000, 'OK'), (3, 'ccc', 3000, 'OK'), (4, 'ddd', 4000, 'OK')" />
<output sql="INSERT INTO t_account_bak(account_id, cipher_password, cipher_amount, status, assisted_query_password, plain_password, plain_amount) VALUES (1, 'encrypt_aaa', 'encrypt_1000', 'OK', 'assisted_query_aaa', 'aaa', 1000), (2, 'encrypt_bbb', 'encrypt_2000', 'OK', 'assisted_query_bbb', 'bbb', 2000), (3, 'encrypt_ccc', 'encrypt_3000', 'OK', 'assisted_query_ccc', 'ccc', 3000), (4, 'encrypt_ddd', 'encrypt_4000', 'OK', 'assisted_query_ddd', 'ddd', 4000)" />
</rewrite-assertion>
<rewrite-assertion id="insert_set_for_parameters" db-type="MySQL">
<input sql="INSERT INTO t_account SET account_id = ?, password = ?, amount = ?, status = ?" parameters="1, aaa, 1000, OK" />
<output sql="INSERT INTO t_account SET account_id = ?, cipher_password = ?, assisted_query_password = ?, cipher_amount = ?, status = ?" parameters="1, encrypt_aaa, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<rewrite-assertion id="insert_set_for_literals" db-type="MySQL">
<input sql="INSERT INTO t_account SET account_id = 1, password = 'aaa', amount = 1000, status = 'OK'" />
<output sql="INSERT INTO t_account SET account_id = 1, cipher_password = 'encrypt_aaa', assisted_query_password = 'assisted_query_aaa', cipher_amount = 'encrypt_1000', status = 'OK'" />
</rewrite-assertion>
<rewrite-assertion id="insert_set_with_plain_for_parameters" db-type="MySQL">
<input sql="INSERT INTO t_account_bak SET account_id = ?, password = ?, amount = ?, status = ?" parameters="1, aaa, 1000, OK" />
<output sql="INSERT INTO t_account_bak SET account_id = ?, cipher_password = ?, assisted_query_password = ?, plain_password = ?, cipher_amount = ?, plain_amount = ?, status = ?" parameters="1, encrypt_aaa, assisted_query_aaa, aaa, encrypt_1000, 1000, OK" />
</rewrite-assertion>
<rewrite-assertion id="insert_set_with_plain_for_literals" db-type="MySQL">
<input sql="INSERT INTO t_account_bak SET account_id = 1, password = 'aaa', amount = 1000, status = 'OK'" />
<output sql="INSERT INTO t_account_bak SET account_id = 1, cipher_password = 'encrypt_aaa', assisted_query_password = 'assisted_query_aaa', plain_password = 'aaa', cipher_amount = 'encrypt_1000', plain_amount = 1000, status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-with-cipher.yaml">
<rewrite-assertion id="encrypt_only_with_parameters" db-type="MySQL">
<input sql="INSERT INTO t_cipher SET encrypt_1 = ?, encrypt_2 = ?" parameters="1, 2" />
<output sql="INSERT INTO t_cipher SET cipher_1 = ?, cipher_2 = ?" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<rewrite-assertion id="encrypt_only_with_literals" db-type="MySQL">
<input sql="INSERT INTO t_cipher SET encrypt_1 = 1, encrypt_2 = 2" />
<output sql="INSERT INTO t_cipher SET cipher_1 = 'encrypt_1', cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_parameters" db-type="MySQL">
<input sql="INSERT INTO t_cipher_assisted_query SET encrypt_1 = ?, encrypt_2 = ?" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_assisted_query SET cipher_1 = ?, assisted_query_1 = ?, cipher_2 = ?, assisted_query_2 = ?" parameters="encrypt_1, assisted_query_1, encrypt_2, assisted_query_2" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_literals" db-type="MySQL">
<input sql="INSERT INTO t_cipher_assisted_query SET encrypt_1 = 1, encrypt_2 = 2" />
<output sql="INSERT INTO t_cipher_assisted_query SET cipher_1 = 'encrypt_1', assisted_query_1 = 'assisted_query_1', cipher_2 = 'encrypt_2', assisted_query_2 = 'assisted_query_2'" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_parameters" db-type="MySQL">
<input sql="INSERT INTO t_cipher_plain SET encrypt_1 = ?, encrypt_2 = ?" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_plain SET cipher_1 = ?, plain_1 = ?, cipher_2 = ?, plain_2 = ?" parameters="encrypt_1, 1, encrypt_2, 2" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="INSERT INTO t_cipher_plain SET encrypt_1 = 1, encrypt_2 = 2" />
<output sql="INSERT INTO t_cipher_plain SET cipher_1 = 'encrypt_1', plain_1 = 1, cipher_2 = 'encrypt_2', plain_2 = 2" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_parameters" db-type="MySQL">
<input sql="INSERT INTO t_cipher_assisted_query_plain SET encrypt_1 = ?, encrypt_2 = ?" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_assisted_query_plain SET cipher_1 = ?, assisted_query_1 = ?, plain_1 = ?, cipher_2 = ?, assisted_query_2 = ?, plain_2 = ?" parameters="encrypt_1, assisted_query_1, 1, encrypt_2, assisted_query_2, 2" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_literals" db-type="MySQL">
<input sql="INSERT INTO t_cipher_assisted_query_plain SET encrypt_1 = 1, encrypt_2 = 2" />
<output sql="INSERT INTO t_cipher_assisted_query_plain SET cipher_1 = 'encrypt_1', assisted_query_1 = 'assisted_query_1', plain_1 = 1, cipher_2 = 'encrypt_2', assisted_query_2 = 'assisted_query_2', plain_2 = 2" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-with-cipher.yaml">
<rewrite-assertion id="encrypt_only_with_parameters">
<input sql="INSERT INTO t_cipher(encrypt_1, encrypt_2) VALUES (?, ?), (3, 4)" parameters="1, 2" />
<output sql="INSERT INTO t_cipher(cipher_1, cipher_2) VALUES (?, ?), ('encrypt_3', 'encrypt_4')" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<rewrite-assertion id="encrypt_only_with_literals">
<input sql="INSERT INTO t_cipher(encrypt_1, encrypt_2) VALUES (1, 2), (3, 4)" />
<output sql="INSERT INTO t_cipher(cipher_1, cipher_2) VALUES ('encrypt_1', 'encrypt_2'), ('encrypt_3', 'encrypt_4')" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_parameters">
<input sql="INSERT INTO t_cipher_assisted_query(encrypt_1, encrypt_2) VALUES (?, ?), (3, 4)" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_assisted_query(cipher_1, cipher_2, assisted_query_1, assisted_query_2) VALUES (?, ?, ?, ?), ('encrypt_3', 'encrypt_4', 'assisted_query_3', 'assisted_query_4')" parameters="encrypt_1, encrypt_2, assisted_query_1, assisted_query_2" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_literals">
<input sql="INSERT INTO t_cipher_assisted_query(encrypt_1, encrypt_2) VALUES (1, 2), (3, 4)" />
<output sql="INSERT INTO t_cipher_assisted_query(cipher_1, cipher_2, assisted_query_1, assisted_query_2) VALUES ('encrypt_1', 'encrypt_2', 'assisted_query_1', 'assisted_query_2'), ('encrypt_3', 'encrypt_4', 'assisted_query_3', 'assisted_query_4')" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_parameters">
<input sql="INSERT INTO t_cipher_plain(encrypt_1, encrypt_2) VALUES (?, ?), (3, 4)" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_plain(cipher_1, cipher_2, plain_1, plain_2) VALUES (?, ?, ?, ?), ('encrypt_3', 'encrypt_4', 3, 4)" parameters="encrypt_1, encrypt_2, 1, 2" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_literals">
<input sql="INSERT INTO t_cipher_plain(encrypt_1, encrypt_2) VALUES (1, 2), (3, 4)" />
<output sql="INSERT INTO t_cipher_plain(cipher_1, cipher_2, plain_1, plain_2) VALUES ('encrypt_1', 'encrypt_2', 1, 2), ('encrypt_3', 'encrypt_4', 3, 4)" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_parameter">
<input sql="INSERT INTO t_cipher_assisted_query_plain(encrypt_1, encrypt_2) VALUES (?, ?), (3, 4)" parameters="1, 2" />
<output sql="INSERT INTO t_cipher_assisted_query_plain(cipher_1, cipher_2, assisted_query_1, plain_1, assisted_query_2, plain_2) VALUES (?, ?, ?, ?, ?, ?), ('encrypt_3', 'encrypt_4', 'assisted_query_3', 3, 'assisted_query_4', 4)" parameters="encrypt_1, encrypt_2, assisted_query_1, 1, assisted_query_2, 2" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_literals">
<input sql="INSERT INTO t_cipher_assisted_query_plain(encrypt_1, encrypt_2) VALUES (1, 2), (3, 4)" />
<output sql="INSERT INTO t_cipher_assisted_query_plain(cipher_1, cipher_2, assisted_query_1, plain_1, assisted_query_2, plain_2) VALUES ('encrypt_1', 'encrypt_2', 'assisted_query_1', 1, 'assisted_query_2', 2), ('encrypt_3', 'encrypt_4', 'assisted_query_3', 3, 'assisted_query_4', 4)" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-cipher.yaml">
<rewrite-assertion id="select_for_parameters">
<input sql="SELECT account_id, password, amount AS a, status AS s FROM t_account WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK" />
<output sql="SELECT account_id, cipher_password, cipher_amount AS a, status AS s FROM t_account WHERE account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND status = ?" parameters="1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="select_for_literals" db-type="MySQL">
<input sql="SELECT account_id, password, amount AS a, status AS s FROM t_account WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="SELECT account_id, cipher_password, cipher_amount AS a, status AS s FROM t_account WHERE account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK'" />
</rewrite-assertion>
<!-- FIXME lost owner of predicate when rewrite -->
<rewrite-assertion id="select_plain_for_parameters">
<input sql="SELECT a.account_id, a.password, a.amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = ? AND a.password = ? AND a.amount = ? AND a.status = ?" parameters="1, aaa, 1000, OK" />
<output sql="SELECT a.account_id, a.cipher_password, a.cipher_amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND a.status = ?" parameters="1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<!-- FIXME lost owner of predicate when rewrite -->
<rewrite-assertion id="select_plain_for_literals" db-type="MySQL">
<input sql="SELECT a.account_id, a.password, a.amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = 1 AND a.password = 'aaa' AND a.amount = 1000 AND a.status = 'OK'" />
<output sql="SELECT a.account_id, a.cipher_password, a.cipher_amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND a.status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
......@@ -16,24 +16,17 @@
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-without-cipher.yaml">
<rewrite-assertion id="plain_encrypt_with_parameters">
<input sql="UPDATE t_cipher_plain set encrypt_1 = ? where encrypt_2 = ?" parameters="1, 2" />
<output sql="UPDATE t_cipher_plain set cipher_1 = ?, plain_1 = ? where plain_2 = ?" parameters="encrypt_1, 1, 2" />
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-plain.yaml">
<!-- FIXME lost owner of predicate when rewrite -->
<rewrite-assertion id="select_plain_for_parameters">
<input sql="SELECT a.account_id, a.password, a.amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = ? AND a.password = ? AND a.amount = ? AND a.status = ?" parameters="1, aaa, 1000, OK" />
<output sql="SELECT a.account_id, a.plain_password, a.plain_amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = ? AND plain_password = ? AND plain_amount = ? AND a.status = ?" parameters="1, aaa, 1000, OK" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_literals">
<input sql="UPDATE t_cipher_plain set encrypt_1 = 1 where encrypt_2 = 2" />
<output sql="UPDATE t_cipher_plain set cipher_1 = 'encrypt_1', plain_1 = 1 where plain_2 = 2" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_parameters">
<input sql="UPDATE t_cipher_assisted_query_plain set encrypt_1 = ?, encrypt_2 = ?, other_1 = ? where encrypt_2 =? and other_2 = ?" parameters="1, 2, update_regular, 2, query_regular" />
<output sql="UPDATE t_cipher_assisted_query_plain set cipher_1 = ?, assisted_query_1 = ?, plain_1 = ?, cipher_2 = ?, assisted_query_2 = ?, plain_2 = ?, other_1 = ? where plain_2 = ? and other_2 = ?" parameters="encrypt_1, assisted_query_1, 1, encrypt_2, assisted_query_2, 2, update_regular, 2, query_regular" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_literals">
<input sql="UPDATE t_cipher_assisted_query_plain set encrypt_1 = 1, encrypt_2 = 2, other_1 = 'update_regular' where encrypt_2 = 2 and other_2 = 'query_regular'" />
<output sql="UPDATE t_cipher_assisted_query_plain set cipher_1 = 'encrypt_1', assisted_query_1 = 'assisted_query_1', plain_1 = 1, cipher_2 = 'encrypt_2', assisted_query_2 = 'assisted_query_2', plain_2 = 2, other_1 = 'update_regular' where plain_2 = 2 and other_2 = 'query_regular'" />
<!-- FIXME SQL92 dialect has problem -->
<!-- FIXME lost owner of predicate when rewrite -->
<rewrite-assertion id="select_plain_for_literals" db-type="MySQL">
<input sql="SELECT a.account_id, a.password, a.amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = 1 AND a.password = 'aaa' AND a.amount = 1000 AND a.status = 'OK'" />
<output sql="SELECT a.account_id, a.plain_password, a.plain_amount AS a, a.status AS s FROM t_account_bak AS a WHERE a.account_id = 1 AND plain_password = 'aaa' AND plain_amount = 1000 AND a.status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-with-cipher.yaml">
<!-- FIXME SQL92 -->
<rewrite-assertion id="encrypt_only_with_parameters" db-type="MySQL">
<input sql="SELECT * FROM t_cipher WHERE encrypt_1 = ? or encrypt_2 = ?" parameters="1, 2" />
<output sql="SELECT * FROM t_cipher WHERE cipher_1 = ? or cipher_2 = ?" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="encrypt_only_with_literals" db-type="MySQL">
<input sql="SELECT * FROM t_cipher WHERE encrypt_1 = 1 or encrypt_2 = 2" />
<output sql="SELECT * FROM t_cipher WHERE cipher_1 = 'encrypt_1' or cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="query_encrypt_with_parameters" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_assisted_query WHERE encrypt_1 = ? or encrypt_2 = ?" parameters="1, 2" />
<output sql="SELECT cipher_1, cipher_2 FROM t_cipher_assisted_query WHERE assisted_query_1 = ? or assisted_query_2 = ?" parameters="assisted_query_1, assisted_query_2" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="query_encrypt_with_literals" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_assisted_query WHERE encrypt_1 = 1 or encrypt_2 = 2" />
<output sql="SELECT cipher_1, cipher_2 FROM t_cipher_assisted_query WHERE assisted_query_1 = 'assisted_query_1' or assisted_query_2 = 'assisted_query_2'" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_parameters" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_plain WHERE encrypt_1 = ? or encrypt_2 = ?" parameters="1, 2" />
<output sql="SELECT cipher_1, cipher_2 FROM t_cipher_plain WHERE cipher_1 = ? or cipher_2 = ?" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="SELECT encrypt_1, encrypt_2 FROM t_cipher_plain WHERE encrypt_1 = 1 or encrypt_2 = 2" />
<output sql="SELECT cipher_1, cipher_2 FROM t_cipher_plain WHERE cipher_1 = 'encrypt_1' or cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_parameters" db-type="MySQL">
<input sql="SELECT encrypt_1 as alias FROM t_cipher_assisted_query_plain WHERE encrypt_1 in (?, ?) and encrypt_2 in (?, ?)" parameters="1, 2, 3, 4" />
<output sql="SELECT cipher_1 as alias FROM t_cipher_assisted_query_plain WHERE assisted_query_1 IN (?, ?) and assisted_query_2 IN (?, ?)" parameters="assisted_query_1, assisted_query_2, assisted_query_3, assisted_query_4" />
</rewrite-assertion>
<!-- FIXME SQL92 -->
<rewrite-assertion id="plain_encrypt_with_literals" db-type="MySQL">
<input sql="SELECT encrypt_1 as alias FROM t_cipher_assisted_query_plain WHERE encrypt_1 in (1, 2) and encrypt_2 in (3, 4)" />
<output sql="SELECT cipher_1 as alias FROM t_cipher_assisted_query_plain WHERE assisted_query_1 IN ('assisted_query_1', 'assisted_query_2') and assisted_query_2 IN ('assisted_query_3', 'assisted_query_4')" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-cipher.yaml">
<rewrite-assertion id="update_for_parameters">
<input sql="UPDATE t_account SET account_id = ?, password = ?, amount = ?, status = ? WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK, 1, aaa, 1000, OK" />
<output sql="UPDATE t_account SET account_id = ?, cipher_password = ?, assisted_query_password = ?, cipher_amount = ?, status = ? WHERE account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND status = ?" parameters="1, encrypt_aaa, assisted_query_aaa, encrypt_1000, OK, 1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="update_for_literals" db-type="MySQL">
<input sql="UPDATE t_account SET account_id = 1, password = 'aaa', amount = 1000, status = 'OK' WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="UPDATE t_account SET account_id = 1, cipher_password = 'encrypt_aaa', assisted_query_password = 'assisted_query_aaa', cipher_amount = 'encrypt_1000', status = 'OK' WHERE account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK'" />
</rewrite-assertion>
<rewrite-assertion id="update_plain_for_parameters">
<input sql="UPDATE t_account_bak SET account_id = ?, password = ?, amount = ?, status = ? WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK, 1, aaa, 1000, OK" />
<output sql="UPDATE t_account_bak SET account_id = ?, cipher_password = ?, assisted_query_password = ?, plain_password = ?, cipher_amount = ?, plain_amount = ?, status = ? WHERE account_id = ? AND assisted_query_password = ? AND cipher_amount = ? AND status = ?" parameters="1, encrypt_aaa, assisted_query_aaa, aaa, encrypt_1000, 1000, OK, 1, assisted_query_aaa, encrypt_1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="update_plain_for_literals" db-type="MySQL">
<input sql="UPDATE t_account_bak SET account_id = 1, password = 'aaa', amount = 1000, status = 'OK' WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="UPDATE t_account_bak SET account_id = 1, cipher_password = 'encrypt_aaa', assisted_query_password = 'assisted_query_aaa', plain_password = 'aaa', cipher_amount = 'encrypt_1000', plain_amount = 1000, status = 'OK' WHERE account_id = 1 AND assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 'encrypt_1000' AND status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt/query-with-plain.yaml">
<rewrite-assertion id="update_plain_for_parameters">
<input sql="UPDATE t_account_bak SET account_id = ?, password = ?, amount = ?, status = ? WHERE account_id = ? AND password = ? AND amount = ? AND status = ?" parameters="1, aaa, 1000, OK, 1, aaa, 1000, OK" />
<output sql="UPDATE t_account_bak SET account_id = ?, cipher_password = ?, assisted_query_password = ?, plain_password = ?, cipher_amount = ?, plain_amount = ?, status = ? WHERE account_id = ? AND plain_password = ? AND plain_amount = ? AND status = ?" parameters="1, encrypt_aaa, assisted_query_aaa, aaa, encrypt_1000, 1000, OK, 1, aaa, 1000, OK" />
</rewrite-assertion>
<!-- FIXME SQL92 dialect has problem -->
<rewrite-assertion id="update_plain_for_literals" db-type="MySQL">
<input sql="UPDATE t_account_bak SET account_id = 1, password = 'aaa', amount = 1000, status = 'OK' WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND status = 'OK'" />
<output sql="UPDATE t_account_bak SET account_id = 1, cipher_password = 'encrypt_aaa', assisted_query_password = 'assisted_query_aaa', plain_password = 'aaa', cipher_amount = 'encrypt_1000', plain_amount = 1000, status = 'OK' WHERE account_id = 1 AND plain_password = 'aaa' AND plain_amount = 1000 AND status = 'OK'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/encrypt-rewrite-rule-query-with-cipher.yaml">
<rewrite-assertion id="encrypt_only_with_parameters">
<input sql="UPDATE t_cipher set encrypt_1 = ? where encrypt_2 = ?" parameters="1, 2" />
<output sql="UPDATE t_cipher set cipher_1 = ? where cipher_2 = ?" parameters="encrypt_1, encrypt_2" />
</rewrite-assertion>
<rewrite-assertion id="encrypt_only_with_literals">
<input sql="UPDATE t_cipher set encrypt_1 = 1 where encrypt_2 = 2" />
<output sql="UPDATE t_cipher set cipher_1 = 'encrypt_1' where cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_parameters">
<input sql="UPDATE t_cipher_assisted_query set encrypt_1 = ? where encrypt_2 = ?" parameters="1, 2" />
<output sql="UPDATE t_cipher_assisted_query set cipher_1 = ?, assisted_query_1 = ? where assisted_query_2 = ?" parameters="encrypt_1, assisted_query_1, assisted_query_2" />
</rewrite-assertion>
<rewrite-assertion id="query_encrypt_with_literals">
<input sql="UPDATE t_cipher_assisted_query set encrypt_1 = 1 where encrypt_2 = 2" />
<output sql="UPDATE t_cipher_assisted_query set cipher_1 = 'encrypt_1', assisted_query_1 = 'assisted_query_1' where assisted_query_2 = 'assisted_query_2'" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_parameters">
<input sql="UPDATE t_cipher_plain set encrypt_1 = ? where encrypt_2 = ?" parameters="1, 2" />
<output sql="UPDATE t_cipher_plain set cipher_1 = ?, plain_1 = ? where cipher_2 = ?" parameters="encrypt_1, 1, encrypt_2" />
</rewrite-assertion>
<rewrite-assertion id="plain_encrypt_with_literals">
<input sql="UPDATE t_cipher_plain set encrypt_1 = 1 where encrypt_2 = 2" />
<output sql="UPDATE t_cipher_plain set cipher_1 = 'encrypt_1', plain_1 = 1 where cipher_2 = 'encrypt_2'" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_parameters">
<input sql="UPDATE t_cipher_assisted_query_plain set encrypt_1 = ?, encrypt_2 = ?, other_1 = ? where other_2 = ?" parameters="1, 2, update_regular, query_regular" />
<output sql="UPDATE t_cipher_assisted_query_plain set cipher_1 = ?, assisted_query_1 = ?, plain_1 = ?, cipher_2 = ?, assisted_query_2 = ?, plain_2 = ?, other_1 = ? where other_2 = ?" parameters="encrypt_1, assisted_query_1, 1, encrypt_2, assisted_query_2, 2, update_regular, query_regular" />
</rewrite-assertion>
<rewrite-assertion id="query_plain_encrypt_with_literals">
<input sql="UPDATE t_cipher_assisted_query_plain set encrypt_1 = 1, encrypt_2 = 2, other_1 = 'update_regular' where other_2 = 'query_regular'" />
<output sql="UPDATE t_cipher_assisted_query_plain set cipher_1 = 'encrypt_1', assisted_query_1 = 'assisted_query_1', plain_1 = 1, cipher_2 = 'encrypt_2', assisted_query_2 = 'assisted_query_2', plain_2 = 2, other_1 = 'update_regular' where other_2 = 'query_regular'" />
</rewrite-assertion>
</rewrite-assertions>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<rewrite-assertions yaml-rule="yaml/sharding-rewrite-rule.yaml">
<rewrite-assertion id="show_columns_from_table" db-type="MySQL">
<input sql="SHOW COLUMNS FROM table_x" />
<output sql="SHOW COLUMNS FROM table_x" />
</rewrite-assertion>
</rewrite-assertions>
......@@ -23,51 +23,31 @@ dataSource: !!com.zaxxer.hikari.HikariDataSource
encryptRule:
tables:
t_cipher:
t_account:
columns:
encrypt_1:
cipherColumn: cipher_1
encryptor: test
encrypt_2:
cipherColumn: cipher_2
encryptor: test
t_cipher_assisted_query:
password:
cipherColumn: cipher_password
assistedQueryColumn: assisted_query_password
encryptor: assisted_query
amount:
cipherColumn: cipher_amount
encryptor: normal
t_account_bak:
columns:
encrypt_1:
cipherColumn: cipher_1
assistedQueryColumn: assisted_query_1
encryptor: assisted_query_test
encrypt_2:
cipherColumn: cipher_2
assistedQueryColumn: assisted_query_2
encryptor: assisted_query_test
t_cipher_plain:
columns:
encrypt_1:
cipherColumn: cipher_1
plainColumn: plain_1
encryptor: test
encrypt_2:
cipherColumn: cipher_2
plainColumn: plain_2
encryptor: test
t_cipher_assisted_query_plain:
columns:
encrypt_1:
cipherColumn: cipher_1
assistedQueryColumn: assisted_query_1
plainColumn: plain_1
encryptor: assisted_query_test
encrypt_2:
cipherColumn: cipher_2
assistedQueryColumn: assisted_query_2
plainColumn: plain_2
encryptor: assisted_query_test
password:
cipherColumn: cipher_password
assistedQueryColumn: assisted_query_password
plainColumn: plain_password
encryptor: assisted_query
amount:
cipherColumn: cipher_amount
plainColumn: plain_amount
encryptor: normal
encryptors:
test:
type: TEST
assisted_query_test:
type: ASSISTED_QUERY_TEST
normal:
type: NORMAL_ENCRYPT
assisted_query:
type: ASSISTED_QUERY_ENCRYPT
props:
query.with.cipher.column: true
......@@ -23,51 +23,31 @@ dataSource: !!com.zaxxer.hikari.HikariDataSource
encryptRule:
tables:
t_cipher:
t_account:
columns:
encrypt_1:
cipherColumn: cipher_1
encryptor: test
encrypt_2:
cipherColumn: cipher_2
encryptor: test
t_cipher_assisted_query:
password:
cipherColumn: cipher_password
assistedQueryColumn: assisted_query_password
encryptor: assisted_query
amount:
cipherColumn: cipher_amount
encryptor: normal
t_account_bak:
columns:
encrypt_1:
cipherColumn: cipher_1
assistedQueryColumn: assisted_query_1
encryptor: assisted_query_test
encrypt_2:
cipherColumn: cipher_2
assistedQueryColumn: assisted_query_2
encryptor: assisted_query_test
t_cipher_plain:
columns:
encrypt_1:
cipherColumn: cipher_1
plainColumn: plain_1
encryptor: test
encrypt_2:
cipherColumn: cipher_2
plainColumn: plain_2
encryptor: test
t_cipher_assisted_query_plain:
columns:
encrypt_1:
cipherColumn: cipher_1
assistedQueryColumn: assisted_query_1
plainColumn: plain_1
encryptor: assisted_query_test
encrypt_2:
cipherColumn: cipher_2
assistedQueryColumn: assisted_query_2
plainColumn: plain_2
encryptor: assisted_query_test
password:
cipherColumn: cipher_password
assistedQueryColumn: assisted_query_password
plainColumn: plain_password
encryptor: assisted_query
amount:
cipherColumn: cipher_amount
plainColumn: plain_amount
encryptor: normal
encryptors:
test:
type: TEST
assisted_query_test:
type: ASSISTED_QUERY_TEST
normal:
type: NORMAL_ENCRYPT
assisted_query:
type: ASSISTED_QUERY_ENCRYPT
props:
query.with.cipher.column: false
......@@ -38,7 +38,7 @@ shardingRule:
worker.id: 123
table_y:
actualDataNodes: db${0..1}.table_y
table_z:
t_cipher:
actualDataNodes: db${0..1}.table_z
table_k:
actualDataNodes: db${0..1}.table_k
......@@ -51,19 +51,20 @@ shardingRule:
worker.id: 123
bindingTables:
- table_x, table_y
encryptRule:
encryptors:
z_encryptor:
type: TEST
normal:
type: NORMAL_ENCRYPT
k_encryptor:
type: ASSISTED_QUERY_TEST
type: ASSISTED_QUERY_ENCRYPT
tables:
table_z:
t_cipher:
columns:
id:
cipherColumn: cipher
plainColumn: plain
encryptor: z_encryptor
password:
cipherColumn: cipher_password
plainColumn: plain_password
encryptor: normal
table_k:
columns:
id:
......@@ -81,3 +82,6 @@ shardingRule:
cipherColumn: cipher
assistedQueryColumn: query
encryptor: k_encryptor
props:
query.with.cipher.column: true
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册