Add Integration Tests for multiple CloudCache Service Instances.

The test cases specifically tests the use case where a user has provisioned mutliple instances of the CloudCache Service in PCF and bound each of them to her deployed Spring Boot, ClientCache app.

Resolves gh-33.
This commit is contained in:
John Blum
2019-06-28 18:58:17 -07:00
parent 4165009501
commit 92463f8527
3 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
/*
* 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.multi;
import java.io.IOException;
import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
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 multiple
* Pivotal Cloud Cache (PCC) services instances exists in a Pivotal CloudFoundry context.
*
* @author John Blum
* @see java.util.Properties
* @see org.junit.Test
* @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 = AutoConfiguredMultiCloudCacheServiceInstanceSecurityContextIntegrationTests.GemFireClientConfiguration.class,
properties = { "spring.boot.data.gemfire.cloud.cloudfoundry.service.cloudcache.name=test-pcc" },
webEnvironment = SpringBootTest.WebEnvironment.NONE
)
public class AutoConfiguredMultiCloudCacheServiceInstanceSecurityContextIntegrationTests
extends AbstractAutoConfiguredSecurityContextIntegrationTests {
private static final String GEMFIRE_LOG_LEVEL = "error";
private static final String VCAP_APPLICATION_PROPERTIES = "application-vcap-multi.properties";
private static Properties vcapApplicationProperties = new Properties();
@BeforeClass
public static void startGemFireServer() throws IOException {
startGemFireServer(GemFireServerConfiguration.class, "-Dspring.profiles.active=security-multi");
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);
}
@SpringBootApplication
@EnableLogging(logLevel = GEMFIRE_LOG_LEVEL)
static class GemFireClientConfiguration extends BaseGemFireClientConfiguration { }
@SpringBootApplication
@EnableLocator(port = 56421)
@CacheServerApplication(name = "AutoConfiguredMultiCloudCacheServiceInstanceSecurityContextIntegrationTests",
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);
}
}
}

View File

@@ -0,0 +1,4 @@
# Spring Boot application.properties used in server for testing Apache Geode/Pivotal GemFire Security in a multi-cloudcache service instance (PCF) context.
test.security.context.username=master
test.security.context.password=p@55w0rd

View File

@@ -0,0 +1,4 @@
# Spring Boot application.properties for testing security in a Pivotal CloudFoundry (PCF) context having multiple Pivotal Cloud Cache (PCC) service instances.
VCAP_APPLICATION={"application_id":"c50bb519-2739-4fa3-8750-02c051e35735","application_name":"boot-test","application_uris":["boot-example.apps.tunis.cf-app.com"],"application_version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa","cf_api":"https://api.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.tunis.cf-app.com"],"version":"d34bbbbd-c35c-4057-baf2-6300cb9aa2aa"}
VCAP_SERVICES={"p-cloudcache":[{ "credentials": { "distributed_system_id": "0", "locators": [ "skullbox.cf-app.com[12345]" ], "urls": { "pulse": "https://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.skullbox.cf-app.com/pulse" }, "users": [{ "password": "vaxAi8UuJkBp9csgDvJ5YA", "roles": [ "cluster_operator" ], "username": "cluster_operator_CQhqoDaEIT1gobjLryfpBg" }, { "password": "egSyyyaM5Q5yUMOVZD6pXA", "roles": [ "developer" ], "username": "cluster_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": [ "gemfire", "cloudcache", "database", "pivotal" ]}, { "credentials": { "distributed_system_id": "0", "locators": [ "localhost[56421]" ], "urls": { "pulse": "https://cloudcache-9defb33a-6b8b-49f0-bd35-cf6f7b2f222f.skullbox.cf-app.com/pulse" }, "users": [{ "password": "p@55w0rd", "roles": [ "cluster_operator" ], "username": "master" }, { "password": "egSyyyaM5Q5yUMOVZD6pXA", "roles": [ "developer" ], "username": "cluster_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": "test-pcc", "tags": [ "gemfire", "cloudcache", "database", "pivotal" ]}]}