Skip to content

Commit

Permalink
SHIBUI-836: tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Sep 12, 2018
1 parent 31f2fc7 commit 4916b94
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,26 @@ public class ShibbolethPlaceholderTokenAwareValueResolvingService implements Tok

private PropertyResolver propertyResolver;

private static final String SHIB_IDP_PLACEHOLDER_PREEFIX = "%{";

private static final String STANDART_PLACEHOLDER_PREFIX = "${";

ShibbolethPlaceholderTokenAwareValueResolvingService(PropertyResolver propertyResolver) {
this.propertyResolver = propertyResolver;
}

@Override
public String resolveValueFromTokenPlaceholder(String tokenPlaceholder) {
requireNonNull(tokenPlaceholder, "tokenPlaceholder must not be null");
tokenPlaceholder.replace("%{", "${");

return null;
public String resolveValueFromTokenPlaceholder(String potentialTokenPlaceholder) {
requireNonNull(potentialTokenPlaceholder, "potentialTokenPlaceholder must not be null");
if(potentialTokenPlaceholder.contains(SHIB_IDP_PLACEHOLDER_PREEFIX)) {
String normalizedTokenPlaceholder =
potentialTokenPlaceholder.replace(SHIB_IDP_PLACEHOLDER_PREEFIX, STANDART_PLACEHOLDER_PREFIX);
//This call might result in IllegalArgumentException if it's unable to resolve passed in property(ies)
//e.g. due to bad data sent, etc. This is OK, as passing correct data and ensuring that
//property values are correctly set is the responsibility of the software operator
return this.propertyResolver.resolveRequiredPlaceholders(normalizedTokenPlaceholder);
}
//No token placeholders, just return the given data as is
return potentialTokenPlaceholder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@FunctionalInterface
public interface TokenPlaceholderValueResolvingService {

String resolveValueFromTokenPlaceholder(String tokenPlaceholder);
String resolveValueFromTokenPlaceholder(String potentialTokenPlaceholder);

static TokenPlaceholderValueResolvingService shibbolethPlaceholderAware(PropertyResolver propertyResolver) {
return new ShibbolethPlaceholderTokenAwareValueResolvingService(propertyResolver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,47 @@ package edu.internet2.tier.shibboleth.admin.ui.service

import edu.internet2.tier.shibboleth.admin.ui.configuration.PlaceholderResolverComponentsConfiguration
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.util.TestPropertyValues
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.test.context.ContextConfiguration

import spock.lang.Specification
import spock.lang.Subject

@ContextConfiguration(classes=[PlaceholderResolverComponentsConfiguration])
import static edu.internet2.tier.shibboleth.admin.ui.service.TestProps.IDP_HOME
import static edu.internet2.tier.shibboleth.admin.ui.service.TestProps.REFRESH_INTERVAL


/**
* @author Dmitriy Kopylenko
*/
@ContextConfiguration(classes = [PlaceholderResolverComponentsConfiguration])
class TokenPlaceholderValueResolvingServiceTests extends Specification {

@Autowired
@Subject
TokenPlaceholderValueResolvingService placeholderValueResolvingService
TokenPlaceholderValueResolvingService serviceUnderTest

def "resolves correctly existing properties from well-formed shibboleth idp style placeholder tokens: %{}"() {
when:
def idpHome = placeholderValueResolvingService.resolveValueFromTokenPlaceholder('%{idp.home}')
@Autowired
ConfigurableEnvironment environment

then:
idpHome
def setup() {
def propPairs = ["idp.home=$IDP_HOME".toString(), "refresh.interval=$REFRESH_INTERVAL".toString()]
TestPropertyValues.of(propPairs).applyTo(environment)
}

def "resolves correctly existing properties from well-formed shibboleth idp style placeholder tokens: %{}"() {
when: 'Valid placeholder token is passed for which property values are defined'
def idpHome = serviceUnderTest.resolveValueFromTokenPlaceholder('%{idp.home}')
def refreshInterval = serviceUnderTest.resolveValueFromTokenPlaceholder('%{refresh.interval}')

then: 'Correct property value resolution is performed'
idpHome == IDP_HOME
refreshInterval == REFRESH_INTERVAL
}
}

class TestProps {
static final IDP_HOME = '/tmp/test/idp'
static final REFRESH_INTERVAL = 'PT5M'
}

0 comments on commit 4916b94

Please sign in to comment.