This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 32a8a3f3a6e Implement DistSQLDatabaseRuleQueryExecutorAssert on
ShowEncryptRuleExecutorTest (#33195)
32a8a3f3a6e is described below
commit 32a8a3f3a6eedfdc01787fd643cf8dc51fb8e65f
Author: ilyas ahsan <[email protected]>
AuthorDate: Wed Oct 9 22:10:19 2024 +0700
Implement DistSQLDatabaseRuleQueryExecutorAssert on
ShowEncryptRuleExecutorTest (#33195)
* Implement DistSQLDatabaseRuleQueryExecutorAssert on
ShowEncryptRuleExecutorTest
* Add new line on the end of the file
---
.../handler/query/ShowEncryptRuleExecutorTest.java | 53 ++++++----------------
.../cases/show-encrypt-rules-current-config.yaml | 39 ++++++++++++++++
.../test/resources/cases/show-encrypt-rules.xml | 28 ++++++++++++
3 files changed, 82 insertions(+), 38 deletions(-)
diff --git
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
index 69c173440d5..09310b39d95 100644
---
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
+++
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
@@ -19,57 +19,34 @@ package
org.apache.shardingsphere.encrypt.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
-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
org.apache.shardingsphere.encrypt.distsql.statement.ShowEncryptRulesStatement;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-class ShowEncryptRuleExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest
{
+@DistSQLRuleQueryExecutorSettings("cases/show-encrypt-rules.xml")
+class ShowEncryptRuleExecutorTest {
- ShowEncryptRuleExecutorTest() {
- super(mock(EncryptRule.class));
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final EncryptRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mockRule()).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(Arguments.arguments("normal",
createRuleConfiguration(), new ShowEncryptRulesStatement("T_ENCRYPT", null),
- Collections.singleton(new
LocalDataQueryResultRow("t_encrypt", "user_id", "user_cipher", "user_assisted",
"user_like", "md5", "", "", "", "", ""))));
- }
-
- private EncryptRuleConfiguration createRuleConfiguration() {
- EncryptColumnRuleConfiguration encryptColumnRuleConfig = new
EncryptColumnRuleConfiguration("user_id", new
EncryptColumnItemRuleConfiguration("user_cipher", "test"));
- encryptColumnRuleConfig.setAssistedQuery(new
EncryptColumnItemRuleConfiguration("user_assisted",
"foo_assist_query_encryptor"));
- encryptColumnRuleConfig.setLikeQuery(new
EncryptColumnItemRuleConfiguration("user_like", "foo_like_encryptor"));
- EncryptTableRuleConfiguration encryptTableRuleConfig = new
EncryptTableRuleConfiguration("t_encrypt",
Collections.singleton(encryptColumnRuleConfig));
- AlgorithmConfiguration shardingSphereAlgorithmConfig = new
AlgorithmConfiguration("md5", new Properties());
- return new
EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig),
Collections.singletonMap("test", shardingSphereAlgorithmConfig));
- }
+ private EncryptRule mockRule() {
+ EncryptRule result = mock(EncryptRule.class);
+
when(result.getAllTableNames()).thenReturn(Collections.singleton("t_encrypt"));
+ return result;
}
}
diff --git
a/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules-current-config.yaml
b/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules-current-config.yaml
new file mode 100644
index 00000000000..b98a13d6701
--- /dev/null
+++
b/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules-current-config.yaml
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+
+rules:
+ - !ENCRYPT
+ tables:
+ t_user:
+ columns:
+ username:
+ cipher:
+ name: username
+ encryptorName: name_encryptor
+ assistedQuery:
+ name: assisted_username
+ encryptorName: assisted_encryptor
+ encryptors:
+ name_encryptor:
+ type: AES
+ props:
+ aes-key-value: 123456abc
+ digest-algorithm-name: SHA-1
+ assisted_encryptor:
+ type: MD5
+ props:
+ salt: 123456
diff --git
a/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules.xml
b/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules.xml
new file mode 100644
index 00000000000..93d19c02e1d
--- /dev/null
+++
b/features/encrypt/distsql/handler/src/test/resources/cases/show-encrypt-rules.xml
@@ -0,0 +1,28 @@
+<?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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW ENCRYPT RULES"
+
current-rule-config-yaml-file="cases/show-encrypt-rules-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+
t_user|username|username|assisted_username||AES|{"aes-key-value":"123456abc","digest-algorithm-name":"SHA-1"}|MD5|{"salt":123456}||
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>