Replace Boolean.getBoolean(..) property resolution for client/server SSL enablement to use Spring's Environment.
Rename spring.boot.data.gemfire.security.ssl.environment.post-processor.disabled to spring.boot.data.gemfire.security.ssl.post-processor.enabled. Resolves GitHub Issue #9.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.geode.boot.autoconfigure.security.ssl;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.geode.boot.autoconfigure.SslAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.SslAutoConfiguration.SslEnvironmentPostProcessor;
|
||||
|
||||
/**
|
||||
* Unit Tests for {@link SslAutoConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.core.env.ConfigurableEnvironment
|
||||
* @see org.springframework.geode.boot.autoconfigure.SslAutoConfiguration
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public class SslAutoConfigurationUnitTests {
|
||||
|
||||
@Test
|
||||
public void sslConfigurationIsDisabled() {
|
||||
|
||||
SslEnvironmentPostProcessor environmentPostProcessor = new SslEnvironmentPostProcessor();
|
||||
|
||||
ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class);
|
||||
|
||||
when(mockEnvironment.getProperty(eq(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY),
|
||||
eq(Boolean.class), eq(true)))
|
||||
.thenReturn(false);
|
||||
|
||||
environmentPostProcessor.postProcessEnvironment(mockEnvironment, null);
|
||||
|
||||
verify(mockEnvironment, times(1))
|
||||
.getProperty(eq(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY),
|
||||
eq(Boolean.class), eq(true));
|
||||
|
||||
verify(mockEnvironment, never()).containsProperty(eq("spring.data.gemfire.security.ssl.keystore"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslConfigurationIsEnabled() {
|
||||
|
||||
SslEnvironmentPostProcessor environmentPostProcessor = new SslEnvironmentPostProcessor();
|
||||
|
||||
ConfigurableEnvironment mockEnvironment = mock(ConfigurableEnvironment.class);
|
||||
|
||||
when(mockEnvironment.getProperty(eq(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY),
|
||||
eq(Boolean.class), eq(true)))
|
||||
.thenReturn(true);
|
||||
|
||||
environmentPostProcessor.postProcessEnvironment(mockEnvironment, null);
|
||||
|
||||
verify(mockEnvironment, times(1))
|
||||
.getProperty(eq(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY),
|
||||
eq(Boolean.class), eq(true));
|
||||
|
||||
verify(mockEnvironment, times(1))
|
||||
.containsProperty(eq("spring.data.gemfire.security.ssl.keystore"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslConfigurationIsEnabledWhenEnabledPropertyNotPresent() {
|
||||
|
||||
SslEnvironmentPostProcessor environmentPostProcessor = new SslEnvironmentPostProcessor();
|
||||
|
||||
ConfigurableEnvironment mockEnvironment = spy(new StandardEnvironment());
|
||||
|
||||
environmentPostProcessor.postProcessEnvironment(mockEnvironment, null);
|
||||
|
||||
verify(mockEnvironment, times(1))
|
||||
.getProperty(eq(SslAutoConfiguration.SECURITY_SSL_ENVIRONMENT_POST_PROCESSOR_ENABLED_PROPERTY),
|
||||
eq(Boolean.class), eq(true));
|
||||
|
||||
verify(mockEnvironment, times(1))
|
||||
.containsProperty(eq("spring.data.gemfire.security.ssl.keystore"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user