This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 8041faa651b Move encrypt column conflict checks to Bean Validation
(#39899)
8041faa651b is described below
commit 8041faa651b058533421d0ea0182b80bf86146ce
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Sep 19 23:36:10 2026 +0800
Move encrypt column conflict checks to Bean Validation (#39899)
---
.../config/rule/EncryptTableRuleConfiguration.java | 3 ++
.../EncryptTableRuleConfigurationValidator.java | 61 ++++++++++++++++++++++
.../ValidEncryptTableRuleConfiguration.java | 57 ++++++++++++++++++++
.../config/EncryptRuleConfigurationTest.java | 45 ++++++++++++++--
.../handler/update/AlterEncryptRuleExecutor.java | 14 -----
.../handler/update/CreateEncryptRuleExecutor.java | 14 -----
.../update/AlterEncryptRuleExecutorTest.java | 25 ---------
.../update/CreateEncryptRuleExecutorTest.java | 16 ------
8 files changed, 163 insertions(+), 72 deletions(-)
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/rule/EncryptTableRuleConfiguration.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/rule/EncryptTableRuleConfiguration.java
index 01b12051729..d15fed2b111 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/rule/EncryptTableRuleConfiguration.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/rule/EncryptTableRuleConfiguration.java
@@ -19,6 +19,8 @@ package org.apache.shardingsphere.encrypt.config.rule;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.encrypt.config.validator.ValidEncryptTableRuleConfiguration;
+import
org.apache.shardingsphere.infra.config.rule.validator.group.RuleConfigurationTypeValidationGroup;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
@@ -30,6 +32,7 @@ import java.util.Collection;
*/
@RequiredArgsConstructor
@Getter
+@ValidEncryptTableRuleConfiguration(groups =
RuleConfigurationTypeValidationGroup.class)
public final class EncryptTableRuleConfiguration {
@NotBlank
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/EncryptTableRuleConfigurationValidator.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/EncryptTableRuleConfigurationValidator.java
new file mode 100644
index 00000000000..ea8c69e2771
--- /dev/null
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/EncryptTableRuleConfigurationValidator.java
@@ -0,0 +1,61 @@
+/*
+ * 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.encrypt.config.validator;
+
+import com.cedarsoftware.util.CaseInsensitiveSet;
+import
org.apache.shardingsphere.encrypt.config.rule.EncryptColumnItemRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.config.rule.EncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.config.rule.EncryptTableRuleConfiguration;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * Encrypt table rule configuration validator.
+ */
+public final class EncryptTableRuleConfigurationValidator implements
ConstraintValidator<ValidEncryptTableRuleConfiguration,
EncryptTableRuleConfiguration> {
+
+ @Override
+ public boolean isValid(final EncryptTableRuleConfiguration value, final
ConstraintValidatorContext context) {
+ Collection<String> logicColumnNames = new
CaseInsensitiveSet<>(value.getColumns().size());
+ for (EncryptColumnRuleConfiguration each : value.getColumns()) {
+ logicColumnNames.add(each.getName());
+ }
+ return value.getColumns().stream().allMatch(each ->
isDerivedColumnValid(each, logicColumnNames, context));
+ }
+
+ private boolean isDerivedColumnValid(final EncryptColumnRuleConfiguration
columnConfig, final Collection<String> logicColumnNames, final
ConstraintValidatorContext context) {
+ Optional<EncryptColumnItemRuleConfiguration> assistedQuery =
columnConfig.getAssistedQuery();
+ if (assistedQuery.isPresent() &&
logicColumnNames.contains(assistedQuery.get().getName())) {
+ return addConstraintViolation("assisted query",
assistedQuery.get().getName(), context);
+ }
+ Optional<EncryptColumnItemRuleConfiguration> likeQuery =
columnConfig.getLikeQuery();
+ if (likeQuery.isPresent() &&
logicColumnNames.contains(likeQuery.get().getName())) {
+ return addConstraintViolation("like query",
likeQuery.get().getName(), context);
+ }
+ return true;
+ }
+
+ private boolean addConstraintViolation(final String columnType, final
String columnName, final ConstraintValidatorContext context) {
+ context.disableDefaultConstraintViolation();
+ context.buildConstraintViolationWithTemplate(String.format("%s column
`%s` conflicts with a logic column", columnType,
columnName)).addPropertyNode("columns").addConstraintViolation();
+ return false;
+ }
+}
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/ValidEncryptTableRuleConfiguration.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/ValidEncryptTableRuleConfiguration.java
new file mode 100644
index 00000000000..46e77627010
--- /dev/null
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/config/validator/ValidEncryptTableRuleConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.encrypt.config.validator;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Valid encrypt table rule configuration constraint.
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Constraint(validatedBy = EncryptTableRuleConfigurationValidator.class)
+@Documented
+public @interface ValidEncryptTableRuleConfiguration {
+
+ /**
+ * Get message.
+ *
+ * @return message
+ */
+ String message() default "contains a derived column that conflicts with a
logic column";
+
+ /**
+ * Get groups.
+ *
+ * @return groups
+ */
+ Class<?>[] groups() default {};
+
+ /**
+ * Get payload.
+ *
+ * @return payload
+ */
+ Class<? extends Payload>[] payload() default {};
+}
diff --git
a/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
b/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
index cb3a7d85378..627b5e66f9c 100644
---
a/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
+++
b/features/encrypt/api/src/test/java/org/apache/shardingsphere/encrypt/config/EncryptRuleConfigurationTest.java
@@ -65,7 +65,8 @@ class EncryptRuleConfigurationTest {
Arguments.of("Empty configuration", new
EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())),
Arguments.of("Table without columns", new
EncryptRuleConfiguration(
Collections.singleton(new
EncryptTableRuleConfiguration("foo_tbl", Collections.emptyList())),
Collections.emptyMap())),
- Arguments.of("Complete configuration",
createValidRuleConfiguration()));
+ Arguments.of("Complete configuration",
createValidRuleConfiguration()),
+ Arguments.of("Multiple columns without derived column
conflicts", createValidMultipleColumnRuleConfiguration()));
}
private static EncryptRuleConfiguration createValidRuleConfiguration() {
@@ -78,6 +79,14 @@ class EncryptRuleConfigurationTest {
Collections.singletonMap("foo_encryptor", new
AlgorithmConfiguration("FIXTURE", new Properties())));
}
+ private static EncryptRuleConfiguration
createValidMultipleColumnRuleConfiguration() {
+ EncryptColumnRuleConfiguration fooColumnConfig =
createValidColumnConfiguration();
+ fooColumnConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("foo_assisted", "foo_encryptor"));
+ EncryptColumnRuleConfiguration barColumnConfig = new
EncryptColumnRuleConfiguration("bar_col", new
EncryptColumnItemRuleConfiguration("bar_cipher", "foo_encryptor"));
+ barColumnConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("bar_like", "foo_encryptor"));
+ return createRuleConfiguration(Arrays.asList(fooColumnConfig,
barColumnConfig), Collections.singletonMap("foo_encryptor", new
AlgorithmConfiguration("FIXTURE", new Properties())));
+ }
+
@ParameterizedTest(name = "{0}")
@MethodSource("invalidRuleConfigurationArguments")
void assertValidateInvalidRuleConfiguration(final String name, final
EncryptRuleConfiguration ruleConfig) {
@@ -97,7 +106,19 @@ class EncryptRuleConfigurationTest {
missingAssistedQueryEncryptor.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("foo_assisted", "bar_encryptor"));
EncryptColumnRuleConfiguration missingLikeQueryEncryptor =
createValidColumnConfiguration();
missingLikeQueryEncryptor.setLikeQuery(new
EncryptColumnItemRuleConfiguration("foo_like", "bar_encryptor"));
+ EncryptColumnRuleConfiguration assistedQueryColumnNameConflict =
createValidColumnConfiguration();
+ assistedQueryColumnNameConflict.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("foo_col", "foo_encryptor"));
+ EncryptColumnRuleConfiguration likeQueryColumnNameConflict =
createValidColumnConfiguration();
+ likeQueryColumnNameConflict.setLikeQuery(new
EncryptColumnItemRuleConfiguration("foo_col", "foo_encryptor"));
+ EncryptColumnRuleConfiguration caseInsensitiveColumnNameConflict =
createValidColumnConfiguration();
+ caseInsensitiveColumnNameConflict.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("FOO_COL", "foo_encryptor"));
+ EncryptColumnRuleConfiguration crossColumnAssistedQueryNameConflict =
createValidColumnConfiguration();
+ crossColumnAssistedQueryNameConflict.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("bar_col", "foo_encryptor"));
+ EncryptColumnRuleConfiguration crossColumnLikeQueryNameConflict =
createValidColumnConfiguration();
+ crossColumnLikeQueryNameConflict.setLikeQuery(new
EncryptColumnItemRuleConfiguration("bar_col", "foo_encryptor"));
+ EncryptColumnRuleConfiguration otherLogicColumn = new
EncryptColumnRuleConfiguration("bar_col", new
EncryptColumnItemRuleConfiguration("bar_cipher", "foo_encryptor"));
AlgorithmConfiguration algorithmConfig = new
AlgorithmConfiguration("FIXTURE", new Properties());
+ Map<String, AlgorithmConfiguration> encryptors =
Collections.singletonMap("foo_encryptor", algorithmConfig);
return Stream.of(
Arguments.of("Null tables", new EncryptRuleConfiguration(null,
Collections.emptyMap())),
Arguments.of("Null table", new
EncryptRuleConfiguration(Collections.singleton(null), Collections.emptyMap())),
@@ -127,7 +148,21 @@ class EncryptRuleConfigurationTest {
Arguments.of("Unconfigured assisted query encryptor",
createRuleConfiguration(missingAssistedQueryEncryptor,
Collections.singletonMap("foo_encryptor",
algorithmConfig))),
Arguments.of("Unconfigured like query encryptor",
createRuleConfiguration(missingLikeQueryEncryptor,
- Collections.singletonMap("foo_encryptor",
algorithmConfig))));
+ Collections.singletonMap("foo_encryptor",
algorithmConfig))),
+ Arguments.of("Assisted query column conflicts with its logic
column", createRuleConfiguration(assistedQueryColumnNameConflict, encryptors)),
+ Arguments.of("Like query column conflicts with its logic
column", createRuleConfiguration(likeQueryColumnNameConflict, encryptors)),
+ Arguments.of("Derived column conflicts with its logic column
case insensitively", createRuleConfiguration(caseInsensitiveColumnNameConflict,
encryptors)),
+ Arguments.of("Assisted query column conflicts with another
logic column",
createRuleConfiguration(Arrays.asList(crossColumnAssistedQueryNameConflict,
otherLogicColumn), encryptors)),
+ Arguments.of("Like query column conflicts with another logic
column",
createRuleConfiguration(Arrays.asList(crossColumnLikeQueryNameConflict,
otherLogicColumn), encryptors)));
+ }
+
+ @Test
+ void assertValidateInvalidRuleItemConfiguration() {
+ EncryptColumnRuleConfiguration columnConfig =
createValidColumnConfiguration();
+ columnConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("foo_col", "foo_encryptor"));
+ EncryptTableRuleConfiguration tableConfig = new
EncryptTableRuleConfiguration("foo_tbl", Collections.singleton(columnConfig));
+ EncryptRuleConfiguration ruleConfig = new
EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap());
+ assertThrows(InvalidRuleConfigurationException.class, () ->
RuleConfigurationValidator.validateRuleItem(ruleConfig, tableConfig));
}
private static EncryptColumnRuleConfiguration
createValidColumnConfiguration() {
@@ -139,7 +174,11 @@ class EncryptRuleConfigurationTest {
}
private static EncryptRuleConfiguration createRuleConfiguration(final
EncryptColumnRuleConfiguration columnConfig, final Map<String,
AlgorithmConfiguration> encryptors) {
- EncryptTableRuleConfiguration tableConfig = new
EncryptTableRuleConfiguration("foo_tbl", Collections.singleton(columnConfig));
+ return createRuleConfiguration(Collections.singleton(columnConfig),
encryptors);
+ }
+
+ private static EncryptRuleConfiguration createRuleConfiguration(final
Collection<EncryptColumnRuleConfiguration> columnConfigs, final Map<String,
AlgorithmConfiguration> encryptors) {
+ EncryptTableRuleConfiguration tableConfig = new
EncryptTableRuleConfiguration("foo_tbl", columnConfigs);
return new
EncryptRuleConfiguration(Collections.singleton(tableConfig), encryptors);
}
}
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
index 1ccbf4c2c88..397388c361f 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
@@ -30,7 +30,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -58,7 +57,6 @@ public final class AlterEncryptRuleExecutor implements
DatabaseRuleAlterExecutor
@Override
public void checkBeforeUpdate(final AlterEncryptRuleStatement
sqlStatement) {
checkToBeAlteredRules(sqlStatement);
- checkColumnNames(sqlStatement);
checkToBeAlteredEncryptors(sqlStatement);
}
@@ -71,18 +69,6 @@ public final class AlterEncryptRuleExecutor implements
DatabaseRuleAlterExecutor
return
sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).collect(Collectors.toList());
}
- private void checkColumnNames(final AlterEncryptRuleStatement
sqlStatement) {
- for (EncryptRuleSegment each : sqlStatement.getRules()) {
-
ShardingSpherePreconditions.checkState(isColumnNameNotConflicts(each),
- () -> new InvalidRuleConfigurationException("encrypt",
"assisted query column or like query column conflicts with logic column"));
- }
- }
-
- private boolean isColumnNameNotConflicts(final EncryptRuleSegment rule) {
- return rule.getColumns().stream().noneMatch(each -> null !=
each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName())
- || null != each.getAssistedQuery() &&
each.getName().equals(each.getAssistedQuery().getName()));
- }
-
private void checkToBeAlteredEncryptors(final AlterEncryptRuleStatement
sqlStatement) {
Collection<AlgorithmSegment> encryptors = new LinkedHashSet<>();
sqlStatement.getRules().forEach(each ->
each.getColumns().forEach(column -> {
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
index ae99ab79cab..2324ac64ce4 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutor.java
@@ -30,7 +30,6 @@ import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitial
import org.apache.shardingsphere.infra.exception.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.resource.storageunit.EmptyStorageUnitException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.DuplicateRuleException;
-import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -53,7 +52,6 @@ public final class CreateEncryptRuleExecutor implements
DatabaseRuleCreateExecut
if (!sqlStatement.isIfNotExists()) {
checkDuplicateRuleNames(sqlStatement);
}
- checkColumnNames(sqlStatement);
checkAlgorithmTypes(sqlStatement);
checkDataSources();
}
@@ -67,18 +65,6 @@ public final class CreateEncryptRuleExecutor implements
DatabaseRuleCreateExecut
return null == rule ? Collections.emptyList() :
sqlStatement.getRules().stream().map(EncryptRuleSegment::getTableName).filter(rule.getAllTableNames()::contains).collect(Collectors.toSet());
}
- private void checkColumnNames(final CreateEncryptRuleStatement
sqlStatement) {
- for (EncryptRuleSegment each : sqlStatement.getRules()) {
-
ShardingSpherePreconditions.checkState(isColumnNameNotConflicts(each),
- () -> new InvalidRuleConfigurationException("encrypt",
"assisted query column or like query column conflicts with logic column"));
- }
- }
-
- private boolean isColumnNameNotConflicts(final EncryptRuleSegment rule) {
- return rule.getColumns().stream().noneMatch(each -> null !=
each.getLikeQuery() && each.getName().equals(each.getLikeQuery().getName())
- || null != each.getAssistedQuery() &&
each.getName().equals(each.getAssistedQuery().getName()));
- }
-
private void checkAlgorithmTypes(final CreateEncryptRuleStatement
sqlStatement) {
sqlStatement.getRules().stream().flatMap(each ->
each.getColumns().stream()).forEach(each -> {
checkStandardAlgorithmType(each.getCipher());
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
index 893f5a5c4a4..f20374fb592 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutorTest.java
@@ -31,7 +31,6 @@ import
org.apache.shardingsphere.encrypt.distsql.statement.AlterEncryptRuleState
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
@@ -68,30 +67,6 @@ class AlterEncryptRuleExecutorTest {
() -> new
DistSQLUpdateExecuteEngine(createSQLStatementWithAssistQueryAndLikeColumns(),
"foo_db", mockContextManager(rule), null).executeUpdate());
}
- @Test
- void assertExecuteUpdateWithConflictAssistQueryColumnNames() {
- EncryptRule rule = mock(EncryptRule.class);
-
when(rule.getAllTableNames()).thenReturn(Collections.singleton("t_encrypt"));
- assertThrows(InvalidRuleConfigurationException.class,
- () -> new
DistSQLUpdateExecuteEngine(createColumnNameConflictedSQLStatement("user_id",
"like_column"), "foo_db", mockContextManager(rule), null).executeUpdate());
- }
-
- @Test
- void assertExecuteUpdateWithConflictLikeColumnNames() {
- EncryptRule rule = mock(EncryptRule.class);
-
when(rule.getAllTableNames()).thenReturn(Collections.singleton("t_encrypt"));
- assertThrows(InvalidRuleConfigurationException.class,
- () -> new
DistSQLUpdateExecuteEngine(createColumnNameConflictedSQLStatement("assisted_column",
"user_id"), "foo_db", mockContextManager(rule), null).executeUpdate());
- }
-
- private AlterEncryptRuleStatement
createColumnNameConflictedSQLStatement(final String assistQueryColumnName,
final String likeColumnName) {
- EncryptColumnSegment columnSegment = new
EncryptColumnSegment("user_id",
- new EncryptColumnItemSegment("user_cipher", new
AlgorithmSegment("MD5", new Properties())),
- new EncryptColumnItemSegment(assistQueryColumnName, new
AlgorithmSegment("MD5", new Properties())),
- new EncryptColumnItemSegment(likeColumnName, new
AlgorithmSegment("MD5", new Properties())));
- return new AlterEncryptRuleStatement(Collections.singleton(new
EncryptRuleSegment("t_encrypt", Collections.singleton(columnSegment))));
- }
-
@Test
void assertExecuteUpdateWithAssistQueryAndLikeColumns() throws
SQLException {
EncryptRule rule = mock(EncryptRule.class);
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutorTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutorTest.java
index ea42978c16c..6d43d9a5822 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutorTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/update/CreateEncryptRuleExecutorTest.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.encrypt.distsql.statement.CreateEncryptRuleStat
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import
org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.DuplicateRuleException;
-import
org.apache.shardingsphere.infra.exception.kernel.metadata.rule.InvalidRuleConfigurationException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import
org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
@@ -69,12 +68,6 @@ class CreateEncryptRuleExecutorTest {
() -> new
DistSQLUpdateExecuteEngine(createSQLStatement("INVALID_TYPE"), "foo_db",
mockContextManager(mock(EncryptRule.class)), null).executeUpdate());
}
- @Test
- void assertExecuteUpdateWithConflictedColumnNames() {
- assertThrows(InvalidRuleConfigurationException.class,
- () -> new
DistSQLUpdateExecuteEngine(createConflictColumnNameSQLStatement(), "foo_db",
mockContextManager(mock(EncryptRule.class)), null).executeUpdate());
- }
-
@Test
void assertExecuteUpdateAESEncryptRuleWithPropertiesNotExists() {
assertThrows(AlgorithmInitializationException.class,
@@ -128,15 +121,6 @@ class CreateEncryptRuleExecutorTest {
return new CreateEncryptRuleStatement(false,
Arrays.asList(userRuleSegment, orderRuleSegment));
}
- private CreateEncryptRuleStatement createConflictColumnNameSQLStatement() {
- EncryptColumnSegment columnSegment = new
EncryptColumnSegment("user_id",
- new EncryptColumnItemSegment("user_cipher", new
AlgorithmSegment("MD5", new Properties())),
- new EncryptColumnItemSegment("user_id", new
AlgorithmSegment("test", new Properties())),
- new EncryptColumnItemSegment("like_column", new
AlgorithmSegment("test", new Properties())));
- EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt",
Collections.singleton(columnSegment));
- return new CreateEncryptRuleStatement(false,
Collections.singleton(ruleSegment));
- }
-
private boolean assertIfNotExistsRuleConfiguration(final
EncryptRuleConfiguration actual) {
assertFalse(actual.getTables().isEmpty());
assertFalse(actual.getEncryptors().isEmpty());