Skip to content

Commit

Permalink
Merged in feature/SHIBUI-1058 (pull request #299)
Browse files Browse the repository at this point in the history
Feature/SHIBUI-1058
  • Loading branch information
Bill Smith authored and Jonathan Johnson committed Feb 15, 2019
2 parents 192b79c + eb53b69 commit 2dd5be8
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,23 @@ public List<Attribute> getAttributeListFromRelyingPartyOverridesRepresentation(M
RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get();
switch (ModelRepresentationConversions.AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) {
case BOOLEAN:
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean") &&
((entry.getValue() instanceof Boolean && (Boolean)entry.getValue()) || Boolean.valueOf((String)entry.getValue()))) {
list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
overrideProperty.getPersistValue()));
} else {
if (entry.getValue() instanceof String) {
list.add(attributeUtility.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
if ((entry.getValue() instanceof Boolean && (Boolean)entry.getValue()) ||
((entry.getValue() instanceof String) && Boolean.valueOf((String)entry.getValue()))) {
if (overrideProperty.getPersistType() != null &&
!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) {
list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
Boolean.valueOf((String) entry.getValue())));
overrideProperty.getPersistValue()));
} else {
list.add(attributeUtility.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Boolean) entry.getValue()));
if (entry.getValue() instanceof String) {
list.add(attributeUtility.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
Boolean.valueOf((String) entry.getValue())));
} else {
list.add(attributeUtility.createAttributeWithBooleanValue(overrideProperty.getAttributeName(),
overrideProperty.getAttributeFriendlyName(),
(Boolean) entry.getValue()));
}
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package edu.internet2.tier.shibboleth.admin.ui.service

import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.SPSSODescriptor
import edu.internet2.tier.shibboleth.admin.ui.domain.SingleLogoutService
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation
import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.LogoutEndpointRepresentation
import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll

class AuxiliaryJPAEntityDescriptorServiceImplTests extends Specification {
@Shared
def openSAMLObjects = new OpenSamlObjects().with {
it.init()
it
}

@Shared
JPAEntityDescriptorServiceImpl entityDescriptorService

void setup() {
entityDescriptorService = new JPAEntityDescriptorServiceImpl(openSAMLObjects, null, null)
}

def "simple test"() {
assert true
}

@Unroll
def "test #method(#description)"() {
setup:
expected.setResourceId(starter.getResourceId())
entityDescriptorService."$method"(starter, representation)

expect:
assert starter == expected

where:
[method, description, representation, starter, expected] << Data.getData(openSAMLObjects)
}

static class Data {
static def getData(OpenSamlObjects openSAMLObjects) {
def data = []

data << new DataField(
method: 'setupLogout',
description: 'no change',
representation: new EntityDescriptorRepresentation(),
starter: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class),
expected: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class)
)
data << new DataField(
method: 'setupLogout',
description: 'add logout',
representation: new EntityDescriptorRepresentation().with {
it.logoutEndpoints = [new LogoutEndpointRepresentation(bindingType: 'testBinding', url: 'testLocation')]
it
},
starter: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class),
expected: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class).with {
it.getRoleDescriptors().add(
openSAMLObjects.buildDefaultInstanceOfType(SPSSODescriptor.class).with {
it.getSingleLogoutServices().add(
openSAMLObjects.buildDefaultInstanceOfType(SingleLogoutService.class).with {
it.binding = 'testBinding'
it.location = 'testLocation'
it
}
)
it
}
)
it
}
)
data << new DataField(
method: 'setupLogout',
description: 'remove logout',
representation: new EntityDescriptorRepresentation(),
starter: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class).with {
it.getRoleDescriptors().add(
openSAMLObjects.buildDefaultInstanceOfType(SPSSODescriptor.class).with {
it.getSingleLogoutServices().add(
openSAMLObjects.buildDefaultInstanceOfType(SingleLogoutService.class).with {
it.binding = 'testBinding'
it.location = 'testLocation'
it
}
)
it
}
)
it
},
expected: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class).with {
it.getRoleDescriptors().add(openSAMLObjects.buildDefaultInstanceOfType(SPSSODescriptor.class))
it
}
)
data << new DataField(
method: 'setupLogout',
description: 'modify logout',
representation: new EntityDescriptorRepresentation().with {
it.logoutEndpoints = [new LogoutEndpointRepresentation(bindingType: 'testBinding', url: 'testLocation')]
it
},
starter: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class).with {
it.getRoleDescriptors().add(
openSAMLObjects.buildDefaultInstanceOfType(SPSSODescriptor.class).with {
it.getSingleLogoutServices().add(
openSAMLObjects.buildDefaultInstanceOfType(SingleLogoutService.class).with {
it.binding = 'startBinding'
it.location = 'startLocation'
it
}
)
it
}
)
it
},
expected: openSAMLObjects.buildDefaultInstanceOfType(EntityDescriptor.class).with {
it.getRoleDescriptors().add(
openSAMLObjects.buildDefaultInstanceOfType(SPSSODescriptor.class).with {
it.getSingleLogoutServices().add(
openSAMLObjects.buildDefaultInstanceOfType(SingleLogoutService.class).with {
it.binding = 'testBinding'
it.location = 'testLocation'
it
}
)
it
}
)
it
},
)

return data
}

static class DataField implements Iterable {
String method
String description
EntityDescriptorRepresentation representation
EntityDescriptor starter
EntityDescriptor expected

@Override
Iterator iterator() {
return [this.method, this.description, this.representation, this.starter, this.expected].iterator()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class TestHelpers {
count += ((Collection)entry.value).size() != 0 ? 1 : 0
} else if (entry.value instanceof String) {
count += StringUtils.isNotBlank((String)entry.value) ? 1 : 0
} else {
count++
} else if (entry.value instanceof Boolean) {
count += Boolean.valueOf((Boolean)entry.value) ? 1 : 0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class TestObjectGenerator {
override.getPersistType() != override.getDisplayType()) {
attributes.add(attributeUtility.createAttributeWithStringValues(override.getAttributeName(), override.getAttributeFriendlyName(), generator.randomString(30)))
} else {
attributes.add(attributeUtility.createAttributeWithBooleanValue(override.getAttributeName(), override.getAttributeFriendlyName(), generator.randomBoolean()))
attributes.add(attributeUtility.createAttributeWithBooleanValue(override.getAttributeName(), override.getAttributeFriendlyName(), true))
}
break
case ModelRepresentationConversions.AttributeTypes.INTEGER:
Expand Down Expand Up @@ -348,12 +348,7 @@ class TestObjectGenerator {
customPropertiesConfiguration.getOverrides().each { override ->
switch (ModelRepresentationConversions.AttributeTypes.valueOf(override.getDisplayType().toUpperCase())) {
case ModelRepresentationConversions.AttributeTypes.BOOLEAN:
if (override.getPersistType() != null &&
override.getPersistType() != override.getDisplayType()) {
representation.put(override.getName(), generator.randomString(30))
} else {
representation.put(override.getName(), generator.randomBoolean())
}
representation.put(override.getName(), generator.randomBoolean())
break
case ModelRepresentationConversions.AttributeTypes.INTEGER:
representation.put(override.getName(), generator.randomInt(0, 999999))
Expand Down

0 comments on commit 2dd5be8

Please sign in to comment.