Skip to content

Commit

Permalink
SHIBUI-1478
Browse files Browse the repository at this point in the history
  • Loading branch information
dima767 committed Sep 11, 2019
1 parent e4fdcc3 commit 91d6abb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocati
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.entityAttributesFiltersSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.filesystemMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.localDynamicMetadataProviderSchema
import static edu.internet2.tier.shibboleth.admin.ui.jsonschema.JsonSchemaLocationLookup.nameIdFormatFilterSchema

/**
* Currently uses mjson library.
Expand Down Expand Up @@ -56,6 +57,9 @@ class LowLevelJsonSchemaValidator {
case 'EntityAttributes':
schemaUri = entityAttributesFiltersSchema(schemaRegistry).uri
break
case 'NameIDFormat':
schemaUri = nameIdFormatFilterSchema(schemaRegistry).uri
break
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.controller

import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.DynamicHttpMetadataResolver
import edu.internet2.tier.shibboleth.admin.ui.domain.resolvers.FileBackedHttpMetadataResolver
import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -35,7 +36,7 @@ class MetadataFiltersControllerSchemaValidationIntegrationTests extends Specific

def 'POST for EntityAttributesFilter with invalid payload according to schema validation'() {
given:
def resolver = metadataResolverRepository.save(new FileBackedHttpMetadataResolver(name: 'fbmr', backingFile: '/tmp/metadata.xml'))
def resolver = metadataResolverRepository.save(new DynamicHttpMetadataResolver(name: 'dmr'))
def postedJsonBody = """
{
"name" : "EntityAttributes",
Expand Down Expand Up @@ -68,6 +69,29 @@ class MetadataFiltersControllerSchemaValidationIntegrationTests extends Specific

}

def 'POST for NameIdFormatFilter with invalid payload according to schema validation'() {
given:
def resolver = metadataResolverRepository.save(new FileBackedHttpMetadataResolver(name: 'fbmr', backingFile: '/tmp/metadata.xml'))
def postedJsonBody = """
{
"name" : null,
"filterEnabled" : "not-a-boolean",
"removeExistingFormats" : false,
"formats" : [ "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent" ],
"nameIdFormatFilterTarget" : {
"nameIdFormatFilterTargetType" : "ENTITY",
"value" : [ "https://sp1.example.org" ]
},
"@type" : "NameIDFormat"
}"""

when:
def result = HTTP_POST(postedJsonBody, resolver.resourceId)

then:
checkJsonValidationIsPerformed(result)
}

private static HttpEntity<String> createRequestHttpEntityFor(String jsonBody) {
new HttpEntity<String>(jsonBody, ['Content-Type': 'application/json'] as HttpHeaders)
}
Expand Down

0 comments on commit 91d6abb

Please sign in to comment.