Repository: incubator-geode Updated Branches: refs/heads/feature/GEM-1032 61fe7c647 -> f1a030749
Add DistributionConfigGetSecurityPropsTest Move getSecurityProps tests from DistributionConfigJUnitTest to DistributionConfigGetSecurityPropsTest. Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f1a03074 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f1a03074 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f1a03074 Branch: refs/heads/feature/GEM-1032 Commit: f1a0307491111fa4632e71b14e88258fde742b0d Parents: 61fe7c6 Author: Kirk Lund <[email protected]> Authored: Thu Oct 6 14:52:06 2016 -0700 Committer: Kirk Lund <[email protected]> Committed: Thu Oct 6 14:52:06 2016 -0700 ---------------------------------------------------------------------- .../DistributionConfigGetSecurityPropsTest.java | 150 +++++++++++++++++++ .../internal/DistributionConfigJUnitTest.java | 29 ---- 2 files changed, 150 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f1a03074/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigGetSecurityPropsTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigGetSecurityPropsTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigGetSecurityPropsTest.java new file mode 100644 index 0000000..9fe7b29 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigGetSecurityPropsTest.java @@ -0,0 +1,150 @@ +/* + * 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.geode.distributed.internal; + +import static org.apache.geode.distributed.ConfigurationProperties.*; +import static org.apache.geode.distributed.internal.DistributionConfig.*; +import static org.assertj.core.api.Assertions.*; + +import java.util.Map; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; + +import org.apache.geode.internal.logging.LogWriterImpl; +import org.apache.geode.security.templates.SamplePostProcessor; +import org.apache.geode.security.templates.SampleSecurityManager; +import org.apache.geode.test.junit.categories.UnitTest; + +@Category(UnitTest.class) +public class DistributionConfigGetSecurityPropsTest { + + @Rule + public TestName testName = new TestName(); + + @Test + public void shouldReturnMultipleSecurityProps() { + Properties props = new Properties(); + props.put(SECURITY_MANAGER, SampleSecurityManager.class.getName()); + props.put(SECURITY_POST_PROCESSOR, SamplePostProcessor.class.getName()); + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + + assertThat(securityProps).containsOnlyKeys(SECURITY_MANAGER, SECURITY_POST_PROCESSOR); + assertThat(securityProps).containsAllEntriesOf(props); + } + + @Test + public void shouldConvertSecurityLogLevel() { + String value = "config"; + Properties props = new Properties(); + props.put(SECURITY_LOG_LEVEL, value); + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + + String logLevelCode = String.valueOf(LogWriterImpl.levelNameToCode(value)); + assertThat(securityProps).containsOnlyKeys(SECURITY_LOG_LEVEL); + assertThat(securityProps.getProperty(SECURITY_LOG_LEVEL)).isEqualTo(logLevelCode); + } + + @Test + public void shouldNotReturnNonSecurityProps() { + Properties props = new Properties(); + props.put(ACK_WAIT_THRESHOLD, 2); + props.put(NAME, this.testName.getMethodName()); + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + + assertThat(securityProps).isEmpty(); + } + + @Test + public void shouldReturnOnlySecurityProps() { + Properties props = new Properties(); + props.put(ACK_WAIT_THRESHOLD, 2); + props.put(NAME, this.testName.getMethodName()); + props.put(SECURITY_MANAGER, SampleSecurityManager.class.getName()); + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + + assertThat(securityProps).containsOnlyKeys(SECURITY_MANAGER); + assertThat(securityProps.getProperty(SECURITY_MANAGER)).isEqualTo(SampleSecurityManager.class.getName()); + } + + @Test + public void shouldReturnCustomSecurityProps() { + String customKey = "security-username"; + String customValue = this.testName.getMethodName(); + Properties props = new Properties(); + props.put(customKey, customValue); + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + + assertThat(securityProps).containsOnlyKeys(customKey); + assertThat(securityProps.getProperty(customKey)).isEqualTo(customValue); + } + + @Test + public void shouldAllowDistributionConfigKeys() { + Properties props = new Properties(); + + props.setProperty(SECURITY_CLIENT_ACCESSOR_NAME, SECURITY_CLIENT_ACCESSOR_NAME_VALUE); + props.setProperty(SECURITY_CLIENT_ACCESSOR_PP_NAME, DEFAULT_SECURITY_CLIENT_ACCESSOR_PP); // default + props.setProperty(SECURITY_CLIENT_AUTH_INIT_NAME, SECURITY_CLIENT_AUTH_INIT_NAME_VALUE); + props.setProperty(SECURITY_CLIENT_AUTHENTICATOR_NAME, SECURITY_CLIENT_AUTHENTICATOR_NAME_VALUE); + //addProperties(getClientExtraProperties(), props); + + //props.setProperty(SECURITY_LOG_FILE_NAME, getSecurityLogFileName(gfd)); + //props.setProperty(SECURITY_LOG_LEVEL_NAME, getLogLevel()); + + props.setProperty(SECURITY_PEER_AUTH_INIT_NAME, SECURITY_PEER_AUTH_INIT_NAME_VALUE); + props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, SECURITY_PEER_AUTHENTICATOR_NAME_VALUE); + props.setProperty(SECURITY_PEER_VERIFYMEMBER_TIMEOUT_NAME, String.valueOf(DEFAULT_SECURITY_PEER_VERIFYMEMBER_TIMEOUT)); // default + //addProperties(getPeerExtraProperties(), props); + + DistributionConfig config = new DistributionConfigImpl(props); + + Properties securityProps = config.getSecurityProps(); + assertThat(securityProps).containsOnlyKeys(SECURITY_CLIENT_ACCESSOR_NAME, SECURITY_CLIENT_ACCESSOR_PP_NAME, SECURITY_CLIENT_AUTH_INIT_NAME, SECURITY_CLIENT_AUTHENTICATOR_NAME, SECURITY_PEER_AUTH_INIT_NAME, SECURITY_PEER_AUTHENTICATOR_NAME, SECURITY_PEER_VERIFYMEMBER_TIMEOUT_NAME); + assertThat(securityProps.getProperty(SECURITY_CLIENT_ACCESSOR_NAME)).isEqualTo(SECURITY_CLIENT_ACCESSOR_NAME_VALUE); + assertThat(securityProps.getProperty(SECURITY_CLIENT_ACCESSOR_PP_NAME)).isEqualTo(DEFAULT_SECURITY_CLIENT_ACCESSOR_PP); + assertThat(securityProps.getProperty(SECURITY_CLIENT_AUTH_INIT_NAME)).isEqualTo(SECURITY_CLIENT_AUTH_INIT_NAME_VALUE); + assertThat(securityProps.getProperty(SECURITY_CLIENT_AUTHENTICATOR_NAME)).isEqualTo(SECURITY_CLIENT_AUTHENTICATOR_NAME_VALUE); + assertThat(securityProps.getProperty(SECURITY_PEER_AUTH_INIT_NAME)).isEqualTo(SECURITY_PEER_AUTH_INIT_NAME_VALUE); + assertThat(securityProps.getProperty(SECURITY_PEER_AUTHENTICATOR_NAME)).isEqualTo(SECURITY_PEER_AUTHENTICATOR_NAME_VALUE); + assertThat(securityProps.getProperty(SECURITY_PEER_VERIFYMEMBER_TIMEOUT_NAME)).isEqualTo(String.valueOf(DEFAULT_SECURITY_PEER_VERIFYMEMBER_TIMEOUT)); + } + + private static final String SECURITY_PEER_AUTH_INIT_NAME_VALUE = "org.apache.geode.security.templates.UserPasswordAuthInit.create"; + private static final String SECURITY_PEER_AUTHENTICATOR_NAME_VALUE = "org.apache.geode.security.templates.DummyAuthenticator.create"; + private static final String SECURITY_CLIENT_AUTH_INIT_NAME_VALUE = "org.apache.geode.security.templates.UserPasswordAuthInit.create"; + private static final String SECURITY_CLIENT_AUTHENTICATOR_NAME_VALUE = "org.apache.geode.security.templates.DummyAuthenticator.create"; + private static final String SECURITY_PEER_VERIFYMEMBER_TIMEOUT_NAME_VALUE = ""; + private static final String SECURITY_LOG_FILE_NAME_VALUE = ""; + private static final String SECURITY_LOG_LEVEL_NAME_VALUE = ""; + private static final String SECURITY_CLIENT_ACCESSOR_NAME_VALUE = "org.apache.geode.security.templates.XmlAuthorization.create"; + private static final String SECURITY_CLIENT_ACCESSOR_PP_NAME_VALUE = ""; +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f1a03074/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigJUnitTest.java b/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigJUnitTest.java index 04bfad6..8e6968f 100644 --- a/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/distributed/internal/DistributionConfigJUnitTest.java @@ -329,35 +329,6 @@ public class DistributionConfigJUnitTest { } @Test - public void testSecurityProps() { - Properties props = new Properties(); - props.put(SECURITY_MANAGER, SampleSecurityManager.class.getName()); - props.put(SECURITY_POST_PROCESSOR, SamplePostProcessor.class.getName()); - props.put(SECURITY_LOG_LEVEL, "config"); - // add another non-security property to verify it won't get put in the security properties - props.put(ACK_WAIT_THRESHOLD, 2); - - DistributionConfig config = new DistributionConfigImpl(props); - // SECURITY_ENABLED_COMPONENTS is automatically added to getSecurityProps - assertEquals(config.getSecurityProps().size(), 3); - } - - @Test - public void testSecurityPropsWithNoSetter() { - Properties props = new Properties(); - props.put(SECURITY_MANAGER, SampleSecurityManager.class.getName()); - props.put(SECURITY_POST_PROCESSOR, SamplePostProcessor.class.getName()); - props.put(SECURITY_LOG_LEVEL, "config"); - // add another non-security property to verify it won't get put in the security properties - props.put(ACK_WAIT_THRESHOLD, 2); - props.put("security-username", "testName"); - - DistributionConfig config = new DistributionConfigImpl(props); - // SECURITY_ENABLED_COMPONENTS is automatically added to getSecurityProps - assertEquals(config.getSecurityProps().size(), 4); - } - - @Test public void testSSLEnabledComponents() { Properties props = new Properties(); props.put(MCAST_PORT, "0");
