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 cc8891527f7 Add test cases on CipherColumnItem (#33631)
cc8891527f7 is described below
commit cc8891527f7d92d4d5acc418e0343d58796b8107
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Nov 12 17:53:32 2024 +0800
Add test cases on CipherColumnItem (#33631)
* Add more test cases on MD5AssistedEncryptAlgorithm
* Add test cases on CipherColumnItem
---
.../rule/column/item/CipherColumnItemTest.java | 67 ++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItemTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItemTest.java
new file mode 100644
index 00000000000..22a161aaab3
--- /dev/null
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/column/item/CipherColumnItemTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.rule.column.item;
+
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static
org.apache.shardingsphere.test.matcher.ShardingSphereArgumentVerifyMatchers.deepEq;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class CipherColumnItemTest {
+
+ @Test
+ void assertEncryptNullValue() {
+ assertNull(new CipherColumnItem("foo_col",
mock(EncryptAlgorithm.class)).encrypt("foo-db", "foo_schema", "foo_table",
"foo_col", (Object) null));
+ }
+
+ @Test
+ void assertEncryptSingleValue() {
+ EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class);
+ when(encryptAlgorithm.encrypt(eq("foo_value"), deepEq(new
AlgorithmSQLContext("foo_db", "foo_schema", "foo_table",
"foo_col")))).thenReturn("encrypted_foo_value");
+ assertThat(new CipherColumnItem("foo_col",
encryptAlgorithm).encrypt("foo_db", "foo_schema", "foo_table", "foo_col",
"foo_value"), is("encrypted_foo_value"));
+ }
+
+ @Test
+ void assertEncryptMultipleValues() {
+ EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class);
+ when(encryptAlgorithm.encrypt(eq("foo_value"), deepEq(new
AlgorithmSQLContext("foo_db", "foo_schema", "foo_table",
"foo_col")))).thenReturn("encrypted_foo_value");
+ assertThat(new CipherColumnItem("foo_col",
encryptAlgorithm).encrypt("foo_db", "foo_schema", "foo_table", "foo_col",
Arrays.asList(null, "foo_value")),
+ is(Arrays.asList(null, "encrypted_foo_value")));
+ }
+
+ @Test
+ void assertDecryptNullValue() {
+ assertNull(new CipherColumnItem("foo_col",
mock(EncryptAlgorithm.class)).decrypt("foo-db", "foo_schema", "foo_table",
"foo_col", (Object) null));
+ }
+
+ @Test
+ void assertDecrypt() {
+ EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class);
+ when(encryptAlgorithm.decrypt(eq("encrypted_foo_value"), deepEq(new
AlgorithmSQLContext("foo_db", "foo_schema", "foo_table",
"foo_col")))).thenReturn("foo_value");
+ assertThat(new CipherColumnItem("foo_col",
encryptAlgorithm).decrypt("foo_db", "foo_schema", "foo_table", "foo_col",
"encrypted_foo_value"), is("foo_value"));
+ }
+}