Add Integration Tests for hybrid cloud configuration.
The test cases specifically tests the use case where a user deployed a Spring Boot, ClientCache app to PCF connected to an external, standalone Apache Geode or Pivotal GemFire cluster. Resolves gh-33.
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2019 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
|
||||
*
|
||||
* https://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.auth.hybrid;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.apache.geode.cache.client.ClientCache;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLocator;
|
||||
import org.springframework.data.gemfire.config.annotation.EnableLogging;
|
||||
import org.springframework.geode.boot.autoconfigure.ClientSecurityAutoConfiguration;
|
||||
import org.springframework.geode.boot.autoconfigure.security.auth.AbstractAutoConfiguredSecurityContextIntegrationTests;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Integration Tests testing the functionality and behavior of {@link ClientSecurityAutoConfiguration} when a
|
||||
* Spring Boot app is deployed (pushed) to Pivotal CloudFoundry (PCF), however, the app has not be bound to a
|
||||
* Pivotal Cloud Cache (PCC) service instance.
|
||||
*
|
||||
* This Use Case is common when users want to deploy their Spring Boot, {@link ClientCache} apps to
|
||||
* Pivotal CloudFoundry (PCF) however, want to connect those apps to an external Apache Geode or Pivotal GemFire
|
||||
* cluster.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.util.Properties
|
||||
* @see org.junit.Test
|
||||
* @see org.apache.geode.cache.client.ClientCache
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.builder.SpringApplicationBuilder
|
||||
* @see org.springframework.boot.test.context.SpringBootTest
|
||||
* @see org.springframework.data.gemfire.config.annotation.CacheServerApplication
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableLocator
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableLogging
|
||||
* @see org.springframework.geode.boot.autoconfigure.ClientSecurityAutoConfiguration
|
||||
* @see org.springframework.geode.boot.autoconfigure.security.auth.AbstractAutoConfiguredSecurityContextIntegrationTests
|
||||
* @see org.springframework.test.annotation.DirtiesContext
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@DirtiesContext
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(
|
||||
classes = AutoConfiguredHybridSecurityContextIntegrationTests.GemFireClientConfiguration.class,
|
||||
properties = {
|
||||
"spring.data.gemfire.pool.locators=localhost[54441]",
|
||||
"spring.data.gemfire.security.username=phantom",
|
||||
"spring.data.gemfire.security.password=s3cr3t"
|
||||
},
|
||||
webEnvironment = SpringBootTest.WebEnvironment.NONE
|
||||
)
|
||||
public class AutoConfiguredHybridSecurityContextIntegrationTests
|
||||
extends AbstractAutoConfiguredSecurityContextIntegrationTests {
|
||||
|
||||
private static final String GEMFIRE_LOG_LEVEL = "error";
|
||||
private static final String VCAP_APPLICATION_PROPERTIES = "application-vcap-hybrid.properties";
|
||||
|
||||
private static Properties vcapApplicationProperties = new Properties();
|
||||
|
||||
@BeforeClass
|
||||
public static void startGemFireServer() throws IOException {
|
||||
|
||||
startGemFireServer(GemFireServerConfiguration.class,"-Dspring.profiles.active=security-hybrid");
|
||||
loadVcapApplicationProperties();
|
||||
unsetTestAutoConfiguredPoolServersPortSystemProperty();
|
||||
}
|
||||
|
||||
public static void loadVcapApplicationProperties() throws IOException {
|
||||
|
||||
vcapApplicationProperties.load(new ClassPathResource(VCAP_APPLICATION_PROPERTIES).getInputStream());
|
||||
|
||||
vcapApplicationProperties.stringPropertyNames().forEach(property ->
|
||||
System.setProperty(property, vcapApplicationProperties.getProperty(property)));
|
||||
}
|
||||
|
||||
public static void unsetTestAutoConfiguredPoolServersPortSystemProperty() {
|
||||
System.clearProperty(GEMFIRE_POOL_SERVERS_PROPERTY);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUpUsedResources() {
|
||||
vcapApplicationProperties.stringPropertyNames().forEach(System::clearProperty);
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableLogging(logLevel = GEMFIRE_LOG_LEVEL)
|
||||
static class GemFireClientConfiguration extends BaseGemFireClientConfiguration { }
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableLocator(port = 54441)
|
||||
@CacheServerApplication(name = "AutoConfiguredHybridSecurityContextIntegrationTests", logLevel = GEMFIRE_LOG_LEVEL)
|
||||
static class GemFireServerConfiguration extends BaseGemFireServerConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new SpringApplicationBuilder(GemFireServerConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.build()
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# Spring Boot application.properties used in server for testing Apache Geode/Pivotal GemFire Security in a hybrid cloud context.
|
||||
|
||||
test.security.context.username=phantom
|
||||
test.security.context.password=s3cr3t
|
||||
@@ -0,0 +1,4 @@
|
||||
# Spring Boot application.properties for testing security in a Pivotal CloudFoundry (PCF) context without a Pivotal Cloud Cache (PCC) Service Instance
|
||||
|
||||
VCAP_APPLICATION={"application_id":"c50bb519-2739-4fa3-8750-02c051e35735","application_name":"boot-test","application_uris":["boot-example.apps.skullbox.cf-app.com"],"application_version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa","cf_api":"https://api.sys.skullbox.cf-app.com","host":"0.0.0.0","instance_id":"babcf301-3b34-4dcf-720e-ccfc","instance_index":0,"limits":{"disk":1024,"fds":16384,"mem":1024},"name":"boot-example","port":8080,"space_id":"271cf083-7855-4b5e-be19-65342d099099","space_name":"jblum-space","uris":["boot-example.apps.skullbox.cf-app.com"],"version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa"}
|
||||
VCAP_SERVICES={"p-cloudcache":[{ "credentials": { "distributed_system_id": "0", "locators": [ "localhost[54441]" ], "urls": { "pulse": "https://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.sys.skullbox.cf-app.com/pulse" }, "users": [ { "password": "s3cr3t", "roles": [ "cluster_operator" ], "username": "phantom" }, { "password": "egSyyyaM5Q5yUMOVZD6pXA", "roles": [ "developer" ], "username": "developer_krCFKddILf8EfWs0laUQ" } ], "wan": { "sender_credentials": { "active": { "password": "tYHFwByaMN675FuBWDZQiQ", "username": "gateway_sender_UJ0YO1pJBEnQP03yt7sVXQ" } } } }, "syslog_drain_url": null, "volume_mounts": [ ], "label": "p-cloudcache", "provider": null, "plan": "small", "name": "jblum-pcc", "tags": [ "database", "pivotal" ] }]}
|
||||
Reference in New Issue
Block a user