This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 645c63b03ea Add test cases for authenticators & defaultAuthenticator
(#29656)
645c63b03ea is described below
commit 645c63b03ea186690affb4b245839e00b9772437
Author: yx9o <[email protected]>
AuthorDate: Fri Jan 5 13:36:09 2024 +0800
Add test cases for authenticators & defaultAuthenticator (#29656)
* Add test cases for authenticators & defaultAuthenticator
* Add test cases
---
...faultAuthorityRuleConfigurationBuilderTest.java | 4 ++++
...wYamlAuthorityRuleConfigurationSwapperTest.java | 19 +++++++++++++--
.../YamlAuthorityRuleConfigurationSwapperTest.java | 27 ++++++++++++++++++----
3 files changed, 44 insertions(+), 6 deletions(-)
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
index 74774d25ab8..efb733b3582 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/rule/builder/DefaultAuthorityRuleConfigurationBuilderTest.java
@@ -22,6 +22,8 @@ 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.assertTrue;
class DefaultAuthorityRuleConfigurationBuilderTest {
@@ -30,5 +32,7 @@ class DefaultAuthorityRuleConfigurationBuilderTest {
AuthorityRuleConfiguration actual = new
DefaultAuthorityRuleConfigurationBuilder().build();
assertThat(actual.getPrivilegeProvider().getType(),
is("ALL_PERMITTED"));
assertThat(actual.getUsers().size(), is(1));
+ assertNull(actual.getDefaultAuthenticator());
+ assertTrue(actual.getAuthenticators().isEmpty());
}
}
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
index 2c5ef8f5112..1f5dff7586c 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
@@ -27,6 +27,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Properties;
+import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -38,7 +39,21 @@ class NewYamlAuthorityRuleConfigurationSwapperTest {
@Test
void assertSwapToDataNodes() {
Collection<ShardingSphereUser> users = Collections.singleton(new
ShardingSphereUser("root", "", "localhost"));
- Collection<YamlDataNode> actual = swapper.swapToDataNodes(new
AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED",
new Properties()), Collections.emptyMap(), null));
- assertThat(actual.iterator().next().getKey(), is("authority"));
+ Collection<YamlDataNode> actual = swapper.swapToDataNodes(new
AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED",
new Properties()),
+ Collections.singletonMap("md5", new
AlgorithmConfiguration("MD5", createProperties())), "scram_sha256"));
+ YamlDataNode yamlDataNode = actual.iterator().next();
+ assertThat(yamlDataNode.getKey(), is("authority"));
+ assertThat(yamlDataNode.getValue(), containsString("user:
root@localhost"));
+ assertThat(yamlDataNode.getValue(), containsString("password: ''"));
+ assertThat(yamlDataNode.getValue(), containsString("type:
ALL_PERMITTED"));
+ assertThat(yamlDataNode.getValue(),
containsString("defaultAuthenticator: scram_sha256"));
+ assertThat(yamlDataNode.getValue(), containsString("type: MD5"));
+ assertThat(yamlDataNode.getValue(),
containsString("proxy-frontend-database-protocol-type: openGauss"));
+ }
+
+ private Properties createProperties() {
+ Properties result = new Properties();
+ result.put("proxy-frontend-database-protocol-type", "openGauss");
+ return result;
}
}
diff --git
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
index d6ec7208fc7..e479bcfd8c7 100644
---
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
+++
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityRuleConfigurationSwapperTest.java
@@ -30,6 +30,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class YamlAuthorityRuleConfigurationSwapperTest {
@@ -38,22 +39,27 @@ class YamlAuthorityRuleConfigurationSwapperTest {
@Test
void assertSwapToYamlConfiguration() {
- AuthorityRuleConfiguration authorityRuleConfig = new
AuthorityRuleConfiguration(Collections.emptyList(), new
AlgorithmConfiguration("type", new Properties()), Collections.emptyMap(), null);
+ AuthorityRuleConfiguration authorityRuleConfig = new
AuthorityRuleConfiguration(Collections.emptyList(), new
AlgorithmConfiguration("ALL_PERMITTED", new Properties()),
+ Collections.singletonMap("md5",
createAlgorithmConfiguration()), "scram_sha256");
YamlAuthorityRuleConfiguration actual =
swapper.swapToYamlConfiguration(authorityRuleConfig);
assertTrue(actual.getUsers().isEmpty());
assertNotNull(actual.getPrivilege());
+ assertThat(actual.getDefaultAuthenticator(), is("scram_sha256"));
+ assertThat(actual.getAuthenticators().size(), is(1));
}
@Test
void assertSwapToObject() {
YamlAuthorityRuleConfiguration authorityRuleConfig = new
YamlAuthorityRuleConfiguration();
authorityRuleConfig.setUsers(Collections.singletonList(getYamlUser()));
- YamlAlgorithmConfiguration yamlAlgorithmConfig = new
YamlAlgorithmConfiguration();
- yamlAlgorithmConfig.setType("type");
- authorityRuleConfig.setPrivilege(yamlAlgorithmConfig);
+ authorityRuleConfig.setPrivilege(createYamlAlgorithmConfiguration());
+ authorityRuleConfig.setDefaultAuthenticator("scram_sha256");
+ authorityRuleConfig.setAuthenticators(Collections.singletonMap("md5",
createYamlAlgorithmConfiguration()));
AuthorityRuleConfiguration actual =
swapper.swapToObject(authorityRuleConfig);
assertThat(actual.getUsers().size(), is(1));
assertNotNull(actual.getPrivilegeProvider());
+ assertThat(actual.getDefaultAuthenticator(), is("scram_sha256"));
+ assertThat(actual.getAuthenticators().size(), is(1));
}
@Test
@@ -63,6 +69,9 @@ class YamlAuthorityRuleConfigurationSwapperTest {
AuthorityRuleConfiguration actual =
swapper.swapToObject(authorityRuleConfig);
assertThat(actual.getUsers().size(), is(1));
assertThat(actual.getPrivilegeProvider().getType(),
is("ALL_PERMITTED"));
+ assertThat(actual.getUsers().size(), is(1));
+ assertNull(actual.getDefaultAuthenticator());
+ assertTrue(actual.getAuthenticators().isEmpty());
}
private YamlUserConfiguration getYamlUser() {
@@ -71,4 +80,14 @@ class YamlAuthorityRuleConfigurationSwapperTest {
result.setPassword("password");
return result;
}
+
+ private AlgorithmConfiguration createAlgorithmConfiguration() {
+ return new AlgorithmConfiguration("MD5", new Properties());
+ }
+
+ private YamlAlgorithmConfiguration createYamlAlgorithmConfiguration() {
+ YamlAlgorithmConfiguration result = new YamlAlgorithmConfiguration();
+ result.setType("MD5");
+ return result;
+ }
}