|
|
|
|
@@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2013-2014 the original author or authors.
|
|
|
|
|
* Copyright 2013-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.
|
|
|
|
|
@@ -13,20 +13,21 @@
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.springframework.cloud.cloudfoundry.environment;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.context.properties.bind.Binder;
|
|
|
|
|
import org.springframework.boot.test.util.TestPropertyValues;
|
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
import org.springframework.core.env.StandardEnvironment;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.springframework.cloud.cloudfoundry.environment.VcapServiceCredentialsEnvironmentPostProcessor.STRING_OBJECT_MAP;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -42,66 +43,85 @@ public class VcapServiceCredentialsEnvironmentPostProcessorTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void noop() {
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
Map<String, Object> properties = Binder.get(environment)
|
|
|
|
|
.bind("security.oauth2", STRING_OBJECT_MAP).orElseGet(Collections::emptyMap);
|
|
|
|
|
assertTrue(properties.isEmpty());
|
|
|
|
|
Map<String, Object> properties = Binder.get(this.environment)
|
|
|
|
|
.bind("security.oauth2", STRING_OBJECT_MAP)
|
|
|
|
|
.orElseGet(Collections::emptyMap);
|
|
|
|
|
assertThat(properties.isEmpty()).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addClientId() {
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.clientId:foo")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("foo", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.client-id}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.client-id}"))
|
|
|
|
|
.isEqualTo("foo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addClientIdUnderscores() {
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.client-id:foo")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("foo", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.client-id}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.client-id}"))
|
|
|
|
|
.isEqualTo("foo");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addTokenUri() {
|
|
|
|
|
TestPropertyValues.of( "vcap.services.sso.credentials.accessTokenUri:http://example.com").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("vcap.services.sso.credentials.accessTokenUri:http://example.com")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("http://example.com", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
|
|
|
|
.isEqualTo("http://example.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addTokenUriAuthDomain() {
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.auth-domain:http://example.com").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("vcap.services.sso.credentials.auth-domain:http://example.com")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("http://example.com/oauth/token", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
|
|
|
|
.isEqualTo("http://example.com/oauth/token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addUserInfoUri() {
|
|
|
|
|
TestPropertyValues.of( "vcap.services.sso.credentials.userInfoUri:http://example.com").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("vcap.services.sso.credentials.userInfoUri:http://example.com")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("http://example.com", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.resource.user-info-uri}"))
|
|
|
|
|
.isEqualTo("http://example.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addServiceId() {
|
|
|
|
|
TestPropertyValues.of("vcap.services.my.credentials.accessTokenUri:http://example.com",
|
|
|
|
|
"security.oauth2.sso.serviceId:my").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues
|
|
|
|
|
.of("vcap.services.my.credentials.accessTokenUri:http://example.com",
|
|
|
|
|
"security.oauth2.sso.serviceId:my")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("http://example.com", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.client.access-token-uri}"))
|
|
|
|
|
.isEqualTo("http://example.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addJwtKeyUri() {
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://example.com").applyTo(this.environment);
|
|
|
|
|
TestPropertyValues.of("vcap.services.sso.credentials.keyUri:http://example.com")
|
|
|
|
|
.applyTo(this.environment);
|
|
|
|
|
this.listener.postProcessEnvironment(this.environment, new SpringApplication());
|
|
|
|
|
assertEquals("http://example.com", this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"));
|
|
|
|
|
assertThat(this.environment
|
|
|
|
|
.resolvePlaceholders("${security.oauth2.resource.jwt.key-uri}"))
|
|
|
|
|
.isEqualTo("http://example.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|