35
35
import java .util .Collections ;
36
36
import java .util .HashMap ;
37
37
import java .util .Map ;
38
+ import java .util .Optional ;
38
39
import java .util .Properties ;
39
40
import java .util .stream .Stream ;
40
41
41
42
import static org .hamcrest .CoreMatchers .is ;
42
43
import static org .hamcrest .MatcherAssert .assertThat ;
44
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
43
45
import static org .junit .jupiter .api .Assertions .assertThrows ;
44
46
import static org .junit .jupiter .api .Assertions .assertTrue ;
45
47
@@ -73,24 +75,6 @@ private EncryptRuleConfiguration createEncryptRuleConfiguration() {
73
75
new AlgorithmConfiguration ("CORE.QUERY_ASSISTED.FIXTURE" , new Properties ()), new AlgorithmConfiguration ("CORE.QUERY_LIKE.FIXTURE" , new Properties ())));
74
76
}
75
77
76
- @ Test
77
- void assertAssistedQueryEncryptorNameSpecified () {
78
- EncryptColumnRuleConfiguration pwdColumnConfig =
79
- new EncryptColumnRuleConfiguration ("pwd" , new EncryptColumnItemRuleConfiguration ("pwd_cipher" , "standard_encryptor" ));
80
- pwdColumnConfig .setAssistedQuery (new EncryptColumnItemRuleConfiguration ("pwd_assist" , "assisted_query_test_encryptor" ));
81
- assertTrue (pwdColumnConfig .getAssistedQuery ().isPresent ());
82
- assertThat (pwdColumnConfig .getAssistedQuery ().get ().getEncryptorName (), is ("assisted_query_test_encryptor" ));
83
- }
84
-
85
- @ Test
86
- void assertLikeQueryEncryptorNameSpecified () {
87
- EncryptColumnRuleConfiguration pwdColumnConfig =
88
- new EncryptColumnRuleConfiguration ("pwd" , new EncryptColumnItemRuleConfiguration ("pwd_cipher" , "standard_encryptor" ));
89
- pwdColumnConfig .setLikeQuery (new EncryptColumnItemRuleConfiguration ("pwd_like" , "like_query_test_encryptor" ));
90
- assertTrue (pwdColumnConfig .getLikeQuery ().isPresent ());
91
- assertThat (pwdColumnConfig .getLikeQuery ().get ().getEncryptorName (), is ("like_query_test_encryptor" ));
92
- }
93
-
94
78
private Map <String , AlgorithmConfiguration > getEncryptors (final AlgorithmConfiguration standardEncryptConfig , final AlgorithmConfiguration queryAssistedEncryptConfig ,
95
79
final AlgorithmConfiguration queryLikeEncryptConfig ) {
96
80
Map <String , AlgorithmConfiguration > result = new HashMap <>(3 , 1F );
@@ -100,6 +84,18 @@ private Map<String, AlgorithmConfiguration> getEncryptors(final AlgorithmConfigu
100
84
return result ;
101
85
}
102
86
87
+ @ Test
88
+ void assertFindQueryEncryptor () {
89
+ EncryptRule encryptRule = new EncryptRule ("foo_db" , createEncryptRuleConfiguration ());
90
+ assertThat (encryptRule .findQueryEncryptor ("t_encrypt" , "credit_card" ),
91
+ is (Optional .of (encryptRule .getEncryptTable ("t_encrypt" ).getEncryptColumn ("credit_card" ).getCipher ().getEncryptor ())));
92
+ }
93
+
94
+ @ Test
95
+ void assertNotFindQueryEncryptor () {
96
+ assertFalse (new EncryptRule ("foo_db" , createEncryptRuleConfiguration ()).findQueryEncryptor ("t_encrypt" , "invalid_col" ).isPresent ());
97
+ }
98
+
103
99
@ SuppressWarnings ("unused" )
104
100
@ ParameterizedTest (name = "Wrong{0}" )
105
101
@ ArgumentsSource (TestCaseArgumentsProvider .class )
0 commit comments