-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AuthorityRuleConfigurationRepositoryTupleSwapperIT (#31093)
* Add AuthorityRuleConfigurationRepositoryTupleSwapperIT * Add AuthorityRuleConfigurationRepositoryTupleSwapperIT
- Loading branch information
Showing
9 changed files
with
177 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
...ngsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...pache/shardingsphere/authority/it/AuthorityRuleConfigurationRepositoryTupleSwapperIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.authority.it; | ||
|
||
import org.apache.shardingsphere.authority.yaml.swapper.AuthorityRuleConfigurationRepositoryTupleSwapper; | ||
import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple; | ||
import org.apache.shardingsphere.test.it.yaml.RepositoryTupleSwapperIT; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class AuthorityRuleConfigurationRepositoryTupleSwapperIT extends RepositoryTupleSwapperIT { | ||
|
||
AuthorityRuleConfigurationRepositoryTupleSwapperIT() { | ||
super("yaml/authority-rule.yaml", new AuthorityRuleConfigurationRepositoryTupleSwapper(), true); | ||
} | ||
|
||
@Override | ||
protected void assertRepositoryTuples(final Collection<RepositoryTuple> actualRepositoryTuples) { | ||
assertThat(actualRepositoryTuples.size(), is(1)); | ||
Iterator<RepositoryTuple> iterator = actualRepositoryTuples.iterator(); | ||
assertAuthority(iterator.next()); | ||
} | ||
|
||
private void assertAuthority(final RepositoryTuple actual) { | ||
assertThat(actual.getKey(), is("authority")); | ||
assertThat(actual.getValue(), is("authenticators:\n fixture:\n type: FIXTURE\ndefaultAuthenticator: fixture\nprivilege:\n type: ALL_PERMITTED\n" | ||
+ "users:\n- admin: true\n password: root\n user: root@%\n- admin: false\n password: sharding\n user: sharding@\n")); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...rc/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationYamlIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.authority.it; | ||
|
||
import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration; | ||
import org.apache.shardingsphere.authority.yaml.config.YamlUserConfiguration; | ||
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration; | ||
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration; | ||
import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class AuthorityRuleConfigurationYamlIT extends YamlRuleConfigurationIT { | ||
|
||
AuthorityRuleConfigurationYamlIT() { | ||
super("yaml/authority-rule.yaml"); | ||
} | ||
|
||
@Override | ||
protected void assertYamlRootConfiguration(final YamlRootConfiguration actual) { | ||
assertAuthorityRule((YamlAuthorityRuleConfiguration) actual.getRules().iterator().next()); | ||
} | ||
|
||
private void assertAuthorityRule(final YamlAuthorityRuleConfiguration actual) { | ||
assertUsers(new ArrayList<>(actual.getUsers())); | ||
assertPrivilege(actual.getPrivilege()); | ||
assertAuthenticators(actual.getAuthenticators()); | ||
assertDefaultAuthenticator(actual.getDefaultAuthenticator()); | ||
} | ||
|
||
private void assertUsers(final List<YamlUserConfiguration> actual) { | ||
assertThat(actual.size(), is(2)); | ||
assertThat(actual.get(0).getUser(), is("root@%")); | ||
assertThat(actual.get(0).getPassword(), is("root")); | ||
assertTrue(actual.get(0).isAdmin()); | ||
assertThat(actual.get(1).getUser(), is("sharding@")); | ||
assertThat(actual.get(1).getPassword(), is("sharding")); | ||
assertFalse(actual.get(1).isAdmin()); | ||
} | ||
|
||
private void assertPrivilege(final YamlAlgorithmConfiguration actual) { | ||
assertThat(actual.getType(), is("ALL_PERMITTED")); | ||
assertTrue(actual.getProps().isEmpty()); | ||
} | ||
|
||
private void assertAuthenticators(final Map<String, YamlAlgorithmConfiguration> actual) { | ||
assertThat(actual.size(), is(1)); | ||
assertThat(actual.get("fixture").getType(), is("FIXTURE")); | ||
assertTrue(actual.get("fixture").getProps().isEmpty()); | ||
} | ||
|
||
private void assertDefaultAuthenticator(final String actual) { | ||
assertThat(actual, is("fixture")); | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
...ngsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapperTest.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
kernel/authority/core/src/test/resources/yaml/authority-rule.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
rules: | ||
- !AUTHORITY | ||
authenticators: | ||
fixture: | ||
type: FIXTURE | ||
defaultAuthenticator: fixture | ||
privilege: | ||
type: ALL_PERMITTED | ||
users: | ||
- admin: true | ||
password: root | ||
user: root@% | ||
- admin: false | ||
password: sharding | ||
user: sharding@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters