You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/04/11 16:21:35 UTC

[shardingsphere] branch master updated: complete code MaskRuleConfigurationYamlIT and EncryptRuleConfigurationYamlIT (#25043)

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 15d3b63d45e complete code MaskRuleConfigurationYamlIT and EncryptRuleConfigurationYamlIT (#25043)
15d3b63d45e is described below

commit 15d3b63d45e6b700424447d0fe68ef6ad023aa24
Author: shangqingL <30...@users.noreply.github.com>
AuthorDate: Wed Apr 12 00:21:26 2023 +0800

    complete code MaskRuleConfigurationYamlIT and EncryptRuleConfigurationYamlIT (#25043)
    
    * modify mode.cn.md
    
    * complete code MaskRuleConfigurationYamlIT
    
    * complete code EncryptRuleConfigurationYamlIT
    
    ---------
    
    Co-authored-by: sq.liu05 <sq...@zuche.com>
---
 features/encrypt/core/pom.xml                      |  6 ++
 .../yaml/EncryptRuleConfigurationYamlIT.java       | 66 ++++++++++++++++++++++
 .../core/src/test/resources/yaml/encrypt-rule.yaml | 42 ++++++++++++++
 features/mask/core/pom.xml                         |  6 ++
 .../mask/yaml/MaskRuleConfigurationYamlIT.java     | 54 ++++++++++++++++++
 .../core/src/test/resources/yaml/mask-rule.yaml    | 35 ++++++++++++
 6 files changed, 209 insertions(+)

diff --git a/features/encrypt/core/pom.xml b/features/encrypt/core/pom.xml
index 9d7db925282..9894063284b 100644
--- a/features/encrypt/core/pom.xml
+++ b/features/encrypt/core/pom.xml
@@ -67,5 +67,11 @@
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-it-yaml</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
new file mode 100644
index 00000000000..ac2e959c62b
--- /dev/null
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/EncryptRuleConfigurationYamlIT.java
@@ -0,0 +1,66 @@
+/*
+ * 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.yaml;
+
+import org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
+import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class EncryptRuleConfigurationYamlIT extends YamlRuleConfigurationIT {
+    
+    EncryptRuleConfigurationYamlIT() {
+        super("yaml/encrypt-rule.yaml");
+    }
+    
+    @Override
+    protected void assertYamlRootConfiguration(final YamlRootConfiguration actual) {
+        assertEncryptRule((YamlEncryptRuleConfiguration) actual.getRules().iterator().next());
+    }
+    
+    private void assertEncryptRule(final YamlEncryptRuleConfiguration actual) {
+        assertColumns(actual);
+        assertQueryColumn(actual);
+        assertEncryptAlgorithm(actual);
+    }
+    
+    private void assertColumns(final YamlEncryptRuleConfiguration actual) {
+        assertThat(actual.getTables().size(), is(1));
+        assertThat(actual.getTables().get("t_user").getColumns().size(), is(1));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getPlainColumn(), is("username"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getCipherColumn(), is("username_cipher"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getEncryptorName(), is("username_encryptor"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getAssistedQueryColumn(), is("assisted_query_username"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getAssistedQueryEncryptorName(), is("assisted_encryptor"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getLikeQueryColumn(), is("like_query_username"));
+        assertThat(actual.getTables().get("t_user").getColumns().get("username").getLikeQueryEncryptorName(), is("like_encryptor"));
+    }
+    
+    private void assertQueryColumn(final YamlEncryptRuleConfiguration actual) {
+        assertTrue(actual.isQueryWithCipherColumn());
+    }
+    
+    private void assertEncryptAlgorithm(final YamlEncryptRuleConfiguration actual) {
+        assertThat(actual.getEncryptors().size(), is(3));
+        assertThat(actual.getEncryptors().get("username_encryptor").getType(), is("AES"));
+        assertThat(actual.getEncryptors().get("username_encryptor").getProps().get("aes-key-value"), is("123456abc"));
+    }
+}
diff --git a/features/encrypt/core/src/test/resources/yaml/encrypt-rule.yaml b/features/encrypt/core/src/test/resources/yaml/encrypt-rule.yaml
new file mode 100644
index 00000000000..9be5e3a1753
--- /dev/null
+++ b/features/encrypt/core/src/test/resources/yaml/encrypt-rule.yaml
@@ -0,0 +1,42 @@
+#
+# 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:
+            plainColumn: username
+            cipherColumn: username_cipher
+            encryptorName: username_encryptor
+            assistedQueryColumn: assisted_query_username
+            assistedQueryEncryptorName: assisted_encryptor
+            likeQueryColumn: like_query_username
+            likeQueryEncryptorName: like_encryptor
+        queryWithCipherColumn: true
+    encryptors:
+      username_encryptor:
+        type: AES
+        props:
+          aes-key-value: 123456abc
+      assisted_encryptor:
+        type: AES
+        props:
+          aes-key-value: 123456abc
+      like_encryptor:
+        type: CHAR_DIGEST_LIKE
diff --git a/features/mask/core/pom.xml b/features/mask/core/pom.xml
index c1d42e05ae2..08345e1e65d 100644
--- a/features/mask/core/pom.xml
+++ b/features/mask/core/pom.xml
@@ -50,5 +50,11 @@
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-it-yaml</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/MaskRuleConfigurationYamlIT.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/MaskRuleConfigurationYamlIT.java
new file mode 100644
index 00000000000..e5601e6f059
--- /dev/null
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/MaskRuleConfigurationYamlIT.java
@@ -0,0 +1,54 @@
+/*
+ * 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.mask.yaml;
+
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
+import org.apache.shardingsphere.mask.yaml.config.YamlMaskRuleConfiguration;
+import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class MaskRuleConfigurationYamlIT extends YamlRuleConfigurationIT {
+    
+    MaskRuleConfigurationYamlIT() {
+        super("yaml/mask-rule.yaml");
+    }
+    
+    @Override
+    protected void assertYamlRootConfiguration(final YamlRootConfiguration actual) {
+        assertMaskRule((YamlMaskRuleConfiguration) actual.getRules().iterator().next());
+    }
+    
+    private void assertMaskRule(final YamlMaskRuleConfiguration actual) {
+        assertTables(actual);
+        assertMaskAlgorithm(actual);
+    }
+    
+    private void assertTables(final YamlMaskRuleConfiguration actual) {
+        assertThat(actual.getTables().size(), is(1));
+        assertThat(actual.getTables().get("t_user").getColumns().size(), is(2));
+    }
+    
+    private void assertMaskAlgorithm(final YamlMaskRuleConfiguration actual) {
+        assertThat(actual.getMaskAlgorithms().size(), is(2));
+        assertThat(actual.getTables().get("t_user").getColumns().get("telephone").getMaskAlgorithm(), is("keep_first_n_last_m_mask"));
+        assertThat(actual.getMaskAlgorithms().get("keep_first_n_last_m_mask").getType(), is("KEEP_FIRST_N_LAST_M"));
+        assertThat(actual.getMaskAlgorithms().get("keep_first_n_last_m_mask").getProps().get("replace-char"), is("*"));
+    }
+}
diff --git a/features/mask/core/src/test/resources/yaml/mask-rule.yaml b/features/mask/core/src/test/resources/yaml/mask-rule.yaml
new file mode 100644
index 00000000000..2a06ee9d9a3
--- /dev/null
+++ b/features/mask/core/src/test/resources/yaml/mask-rule.yaml
@@ -0,0 +1,35 @@
+#
+# 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:
+  - !MASK
+    tables:
+      t_user:
+        columns:
+          telephone :
+            maskAlgorithm: keep_first_n_last_m_mask
+          password :
+            maskAlgorithm: md5_mask
+    maskAlgorithms:
+      keep_first_n_last_m_mask:
+        type: KEEP_FIRST_N_LAST_M
+        props:
+          first-n: 3
+          last-m: 4
+          replace-char: '*'
+      md5_mask:
+        type: MD5