This is an automated email from the ASF dual-hosted git repository.
panjuan 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 ea2f7a3 assert Encrypt Rule Configuration (#10348)
ea2f7a3 is described below
commit ea2f7a390a811c9d0f96648d232bd897036a55be
Author: totalo <[email protected]>
AuthorDate: Sun May 16 16:18:15 2021 +0800
assert Encrypt Rule Configuration (#10348)
---
.../spring/boot/EncryptSpringBootStarterTest.java | 41 +++++++++++++++++++++-
.../test/resources/application-encrypt.properties | 7 ++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
index 31a4753..609dd0a 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/java/org/apache/shardingsphere/encrypt/spring/boot/EncryptSpringBootStarterTest.java
@@ -18,7 +18,11 @@
package org.apache.shardingsphere.encrypt.spring.boot;
import org.apache.shardingsphere.encrypt.algorithm.AESEncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.algorithm.MD5EncryptAlgorithm;
import
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
+import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -28,6 +32,10 @@ import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -50,6 +58,37 @@ public class EncryptSpringBootStarterTest {
@Test
public void assertEncryptRuleConfiguration() {
- // TODO assert Encrypt Rule Configuration
+ assertEncryptors(encryptRuleConfiguration.getEncryptors());
+ assertThat(encryptRuleConfiguration.getTables().size(), is(1));
+
assertEncryptTable(encryptRuleConfiguration.getTables().iterator().next());
+ }
+
+ private void assertEncryptors(final Map<String, EncryptAlgorithm>
encryptors) {
+ assertThat(encryptors.size(), is(2));
+ assertThat(encryptors.get("aesEncryptor"),
instanceOf(AESEncryptAlgorithm.class));
+
assertThat(encryptors.get("aesEncryptor").getProps().getProperty("aes-key-value"),
is("123456"));
+ assertThat(encryptors.get("md5Encryptor"),
instanceOf(MD5EncryptAlgorithm.class));
+ }
+
+ private void assertEncryptTable(final EncryptTableRuleConfiguration
tableRuleConfig) {
+ assertThat(tableRuleConfig.getName(), is("t_order"));
+ assertThat(tableRuleConfig.getColumns().size(), is(2));
+ Iterator<EncryptColumnRuleConfiguration> columnRuleConfigs =
tableRuleConfig.getColumns().iterator();
+ assertEncryptColumn2(columnRuleConfigs.next());
+ assertEncryptColumn1(columnRuleConfigs.next());
+ }
+
+ private void assertEncryptColumn1(final EncryptColumnRuleConfiguration
columnRuleConfig) {
+ assertThat(columnRuleConfig.getLogicColumn(), is("pwd"));
+ assertThat(columnRuleConfig.getCipherColumn(), is("pwd_cipher"));
+ assertThat(columnRuleConfig.getEncryptorName(), is("aesEncryptor"));
+ }
+
+ private void assertEncryptColumn2(final EncryptColumnRuleConfiguration
columnRuleConfig) {
+ assertThat(columnRuleConfig.getLogicColumn(), is("credit_card"));
+ assertThat(columnRuleConfig.getCipherColumn(),
is("credit_card_cipher"));
+ assertThat(columnRuleConfig.getAssistedQueryColumn(),
is("credit_card_assisted_query"));
+ assertThat(columnRuleConfig.getPlainColumn(), is("credit_card_plain"));
+ assertThat(columnRuleConfig.getEncryptorName(), is("md5Encryptor"));
}
}
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
index b97cccc..1932702 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-spring/shardingsphere-encrypt-spring-boot-starter/src/test/resources/application-encrypt.properties
@@ -18,6 +18,13 @@
spring.shardingsphere.rules.encrypt.encryptors.aesEncryptor.type=AES
spring.shardingsphere.rules.encrypt.encryptors.aesEncryptor.props.aes-key-value=123456
+spring.shardingsphere.rules.encrypt.encryptors.md5Encryptor.type=MD5
+
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.cipher-column=pwd_cipher
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.plain-column=pwd_plain
spring.shardingsphere.rules.encrypt.tables.t_order.columns.pwd.encryptor-name=aesEncryptor
+
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.credit_card.cipher-column=credit_card_cipher
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.credit_card.plain-column=credit_card_plain
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.credit_card.assisted-query-column=credit_card_assisted_query
+spring.shardingsphere.rules.encrypt.tables.t_order.columns.credit_card.encryptor-name=md5Encryptor