Skip to content

Commit

Permalink
SHIBUI-836: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Sep 12, 2018
1 parent 978a676 commit f070306
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public String resolveValueFromTokenPlaceholder(String potentialTokenPlaceholder)
//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);
String resolved = this.propertyResolver.resolveRequiredPlaceholders(normalizedTokenPlaceholder);

//Indicates that malformed values such as %{incomplete.token are passed. Spring won't resolve and return
//the value as is. Just change it back to the original shib-style token and return.
if(resolved.equals(normalizedTokenPlaceholder)) {
return resolved.replace(STANDART_PLACEHOLDER_PREFIX, SHIB_IDP_PLACEHOLDER_PREEFIX);
}
return resolved;
}
//No token placeholders, just return the given data as is
return potentialTokenPlaceholder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,58 @@ class TokenPlaceholderValueResolvingServiceTests extends Specification {

static final IDP_HOME = '/tmp/test/idp'
static final REFRESH_INTERVAL = 'PT5M'
static final PLAIN_VALUE = 'Plain String value'

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'
when: 'Valid placeholder token is passed in 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
}

def "returns value as is if no well-formed shibboleth idp style placeholder tokens: %{} are passed in"() {
when: 'Plain value without placeholder token is passed in'
def idpHome = serviceUnderTest.resolveValueFromTokenPlaceholder(IDP_HOME)
def plainValue = serviceUnderTest.resolveValueFromTokenPlaceholder(PLAIN_VALUE)

then: 'Value returned as is'
idpHome == IDP_HOME
plainValue == PLAIN_VALUE

when: 'Malformed placeholder value is passed in'
plainValue = serviceUnderTest.resolveValueFromTokenPlaceholder('%{malformed.value')

then:
plainValue == '%{malformed.value'
}

def "Throws IllegalArgumentException for unresolvable properties"() {
when: 'Valid placeholder token is passed in for which property values are undefined'
serviceUnderTest.resolveValueFromTokenPlaceholder("%{i.am.not.defined}")

then:
thrown IllegalArgumentException

when: 'Combination of resolvable and unresolvable tokens are passed in'
serviceUnderTest.resolveValueFromTokenPlaceholder("%{idp.home}/%{i.am.not.defined}")

then:
thrown IllegalArgumentException
}

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

then: 'Correct combined property values resolution is performed'
combinedValue == "$IDP_HOME AND $REFRESH_INTERVAL"
}
}

0 comments on commit f070306

Please sign in to comment.