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 8253ea2d74e Add more test cases on MD5AssistedEncryptAlgorithm (#33630)
8253ea2d74e is described below
commit 8253ea2d74e219caccbe6a9e6b15f061364c5b56
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 12 16:29:58 2024 +0800
Add more test cases on MD5AssistedEncryptAlgorithm (#33630)
---
.../assisted/MD5AssistedEncryptAlgorithmTest.java | 17 +++++++++--------
.../algorithm/standard/AESEncryptAlgorithmTest.java | 9 +++++++--
.../aes/AESCryptographicAlgorithmTest.java | 10 ++++++++--
3 files changed, 24 insertions(+), 12 deletions(-)
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
index f4422f8f911..d952f1cd3e8 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithmTest.java
@@ -18,16 +18,16 @@
package org.apache.shardingsphere.encrypt.algorithm.assisted;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
class MD5AssistedEncryptAlgorithmTest {
@@ -45,13 +45,14 @@ class MD5AssistedEncryptAlgorithmTest {
}
@Test
- void assertEncryptWithNullPlaintext() {
- assertNull(encryptAlgorithm.encrypt(null,
mock(AlgorithmSQLContext.class)));
+ void assertDecrypt() {
+ assertThrows(UnsupportedOperationException.class, () ->
encryptAlgorithm.decrypt("test", mock(AlgorithmSQLContext.class)));
}
@Test
- void assertEncryptWhenConfigSalt() {
- encryptAlgorithm.init(PropertiesBuilder.build(new Property("salt",
"202cb962ac5907")));
- assertThat(encryptAlgorithm.encrypt("test",
mock(AlgorithmSQLContext.class)), is("0c243d2934937738f36514035d95344a"));
+ void assertToConfiguration() {
+ AlgorithmConfiguration actual = encryptAlgorithm.toConfiguration();
+ assertThat(actual.getType(), is("MD5"));
+ assertTrue(actual.getProps().isEmpty());
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
index 1b16c3e0b2c..958acd14597 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithmTest.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContex
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -32,8 +33,12 @@ import static org.mockito.Mockito.mock;
class AESEncryptAlgorithmTest {
- private final EncryptAlgorithm encryptAlgorithm =
TypedSPILoader.getService(
- EncryptAlgorithm.class, "AES", PropertiesBuilder.build(new
Property("aes-key-value", "test"), new Property("digest-algorithm-name",
"SHA-1")));
+ private EncryptAlgorithm encryptAlgorithm;
+
+ @BeforeEach
+ void setUp() {
+ encryptAlgorithm = TypedSPILoader.getService(EncryptAlgorithm.class,
"AES", PropertiesBuilder.build(new Property("aes-key-value", "test"), new
Property("digest-algorithm-name", "SHA-1")));
+ }
@Test
void assertEncrypt() {
diff --git
a/infra/algorithm/type/cryptographic/type/aes/src/test/java/org/apache/shardingsphere/infra/algorithm/cryptographic/aes/AESCryptographicAlgorithmTest.java
b/infra/algorithm/type/cryptographic/type/aes/src/test/java/org/apache/shardingsphere/infra/algorithm/cryptographic/aes/AESCryptographicAlgorithmTest.java
index 2881cebc5ca..45e77ee75d7 100644
---
a/infra/algorithm/type/cryptographic/type/aes/src/test/java/org/apache/shardingsphere/infra/algorithm/cryptographic/aes/AESCryptographicAlgorithmTest.java
+++
b/infra/algorithm/type/cryptographic/type/aes/src/test/java/org/apache/shardingsphere/infra/algorithm/cryptographic/aes/AESCryptographicAlgorithmTest.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.algorithm.cryptographic.core.Cryptographi
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.util.PropertiesBuilder;
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -31,8 +32,13 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class AESCryptographicAlgorithmTest {
- private final CryptographicAlgorithm cryptographicAlgorithm =
TypedSPILoader.getService(
- CryptographicAlgorithm.class, "AES", PropertiesBuilder.build(new
Property("aes-key-value", "test"), new Property("digest-algorithm-name",
"SHA-1")));
+ private CryptographicAlgorithm cryptographicAlgorithm;
+
+ @BeforeEach
+ void setUp() {
+ cryptographicAlgorithm =
TypedSPILoader.getService(CryptographicAlgorithm.class, "AES",
+ PropertiesBuilder.build(new Property("aes-key-value", "test"),
new Property("digest-algorithm-name", "SHA-1")));
+ }
@Test
void assertCreateNewInstanceWithoutAESKey() {