diff --git a/src/main/java/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStage.java b/src/main/java/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStage.java index 5cb6a45..33c8ede 100644 --- a/src/main/java/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStage.java +++ b/src/main/java/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStage.java @@ -26,10 +26,10 @@ import net.shibboleth.metadata.dom.SimpleDOMTraversalContext; import net.shibboleth.metadata.pipeline.StageProcessingException; import net.shibboleth.metadata.validate.Validator; +import net.shibboleth.metadata.validate.ValidatorSequence; import net.shibboleth.shared.component.ComponentInitializationException; import net.shibboleth.shared.xml.AttributeSupport; import net.shibboleth.shared.xml.ElementSupport; -import uk.org.iay.incommon.mda.validate.ValidatorSequence; /** * Stage to apply a collection of validators to Shibboleth shibmd:Scope diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/AcceptAllValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/AcceptAllValidator.java deleted file mode 100644 index a4be16c..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/AcceptAllValidator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.validate.BaseValidator; -import net.shibboleth.metadata.validate.Validator; - -/** - * A {@link Validator} which accepts any value, returning - * {@link net.shibboleth.metadata.validate.Validator.Action#DONE} - * to terminate any validator sequence. - * - * @param type of the object to be validated - */ -public class AcceptAllValidator extends BaseValidator implements Validator { - - @Override - public @Nonnull Action validate(@Nonnull final V e, @Nonnull final Item item, @Nonnull final String stageId) { - return Action.DONE; - } - -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/BaseAsValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/BaseAsValidator.java index ece4b3d..a90e23d 100644 --- a/src/main/java/uk/org/iay/incommon/mda/validate/BaseAsValidator.java +++ b/src/main/java/uk/org/iay/incommon/mda/validate/BaseAsValidator.java @@ -22,6 +22,7 @@ import net.shibboleth.metadata.pipeline.StageProcessingException; import net.shibboleth.metadata.validate.BaseValidator; import net.shibboleth.metadata.validate.Validator; +import net.shibboleth.metadata.validate.ValidatorSequence; import net.shibboleth.shared.component.ComponentInitializationException; /** diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/RejectAllValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/RejectAllValidator.java deleted file mode 100644 index 0f0db01..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/RejectAllValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.validate.BaseValidator; -import net.shibboleth.metadata.validate.Validator; - -/** - * A {@link Validator} which rejects any value, returning - * {@link net.shibboleth.metadata.validate.Validator.Action#DONE} - * to terminate any validator sequence. - * - * An error status is added using the value of the given property as a format string. - * The message defaults to a simple rejection message including the object's string value. - * - * @param type of the object to be validated - */ -public class RejectAllValidator extends BaseValidator implements Validator { - - @Override - public @Nonnull Action validate(@Nonnull final V e, @Nonnull final Item item, @Nonnull final String stageId) { - addErrorMessage(e, item, stageId); - return Action.DONE; - } - -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/ValidatorSequence.java b/src/main/java/uk/org/iay/incommon/mda/validate/ValidatorSequence.java deleted file mode 100644 index 084a364..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/ValidatorSequence.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate; - -import java.util.List; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.pipeline.StageProcessingException; -import net.shibboleth.metadata.validate.BaseValidator; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.shared.collection.CollectionSupport; -import net.shibboleth.shared.component.ComponentInitializationException; - -/** - * A {@link Validator} implementation which encapsulates the functionality of stepping - * through a sequence of other validators. - * - * The {@link #validate} method of this class returns the - * {@link net.shibboleth.metadata.validate.Validator.Action#DONE} value - * to indicate that one of the called validators returned that value. - * - * @param type of the object to be validated - */ -public class ValidatorSequence extends BaseValidator implements Validator { - - /** The list of validators to apply. */ - @Nonnull - private List> validators = CollectionSupport.listOf(); - - /** - * Set the list of validators to apply to each item. - * - * @param newValidators the list of validators to set - */ - public void setValidators(@Nonnull final List> newValidators) { - checkSetterPreconditions(); - - validators = CollectionSupport.copyToList(newValidators); - } - - /** - * Gets the list of validators being applied to each item. - * - * @return list of validators - */ - public @Nonnull List> getValidators() { - return validators; - } - - @Override - public @Nonnull Action validate(@Nonnull final V value, @Nonnull final Item item, @Nonnull final String stageId) - throws StageProcessingException { - for (final Validator validator: validators) { - final Action action = validator.validate(value, item, stageId); - if (action == Action.DONE) { - return action; - } - } - return Action.CONTINUE; - } - - @Override - protected void doInitialize() throws ComponentInitializationException { - super.doInitialize(); - - for (final Validator validator : validators) { - if (!validator.isInitialized()) { - validator.initialize(); - } - } - } - -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidator.java deleted file mode 100644 index 57ed5a9..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.regex.Matcher; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.validate.Validator; - -/** - * A Validator that accepts {@link String} values matching a regular expression. - * - * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE} - * if the entire value is matched by the regular expression, thus terminating any validator sequence. - */ -public class AcceptStringRegexValidator extends BaseStringRegexValidator implements Validator { - - @Override - public @Nonnull Action validate(@Nonnull final String e, @Nonnull final Item item, @Nonnull final String stageId) { - final Matcher matcher = getPattern().matcher(e); - if (matcher.matches()) { - return Action.DONE; - } else { - return Action.CONTINUE; - } - } -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidator.java deleted file mode 100644 index 6206cb9..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidator.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate.string; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.validate.BaseValidator; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.shared.annotation.constraint.NonnullAfterInit; -import net.shibboleth.shared.component.ComponentInitializationException; - -/** - * A Validator that accepts a fixed {@link String} value. - * - * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE} - * if the value is matched, thus terminating any validator sequence. - */ -public class AcceptStringValueValidator extends BaseValidator implements Validator { - - /** Value to be accepted by this validator. */ - @NonnullAfterInit - private String value; - - /** - * Returns the value. - * - * @return Returns the value. - */ - @NonnullAfterInit - public String getValue() { - return value; - } - - /** - * Sets the value to be accepted. - * - * @param v the value to set. - */ - public void setValue(@Nonnull final String v) { - value = v; - } - - @Override - public @Nonnull Action validate(@Nonnull final String e, @Nonnull final Item item, @Nonnull final String stageId) { - if (e.equals(value)) { - return Action.DONE; - } else { - return Action.CONTINUE; - } - } - - @Override - protected void doInitialize() throws ComponentInitializationException { - super.doInitialize(); - - if (getValue() == null) { - throw new ComponentInitializationException("value to be matched can not be null"); - } - } -} diff --git a/src/main/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidator.java b/src/main/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidator.java deleted file mode 100644 index 4976754..0000000 --- a/src/main/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidator.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.regex.Matcher; - -import javax.annotation.Nonnull; - -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.validate.Validator; - -/** - * A Validator that rejects {@link String} values matching a regular expression. - * - * This validator returns {@link net.shibboleth.metadata.validate.Validator.Action#DONE} - * if the entire value is matched by the regular expression, thus terminating any validator sequence. - */ -public class RejectStringRegexValidator extends BaseStringRegexValidator implements Validator { - - @Override - public @Nonnull Action validate(@Nonnull final String e, @Nonnull final Item item, @Nonnull final String stageId) { - final Matcher matcher = getPattern().matcher(e); - if (matcher.matches()) { - addErrorMessage(e, item, stageId); - return Action.DONE; - } else { - return Action.CONTINUE; - } - } -} diff --git a/src/main/resources/uk/org/iay/incommon/mda/beans.xml b/src/main/resources/uk/org/iay/incommon/mda/beans.xml index ebc34d3..3b733d4 100644 --- a/src/main/resources/uk/org/iay/incommon/mda/beans.xml +++ b/src/main/resources/uk/org/iay/incommon/mda/beans.xml @@ -42,31 +42,16 @@ Validator beans. --> - - - - - - - - - - diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/AcceptAllValidatorTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/AcceptAllValidatorTest.java deleted file mode 100644 index 9187a62..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/AcceptAllValidatorTest.java +++ /dev/null @@ -1,31 +0,0 @@ - -package uk.org.iay.incommon.mda.validate; - -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class AcceptAllValidatorTest { - - @Test - public void validate() throws Exception { - final AcceptAllValidator v = new AcceptAllValidator<>(); - v.setId("comp"); - v.initialize(); - - final Item item = new MockItem("test"); - final Validator.Action action = v.validate("foo", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - -} diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/RejectAllValidatorTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/RejectAllValidatorTest.java deleted file mode 100644 index 97c78a8..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/RejectAllValidatorTest.java +++ /dev/null @@ -1,54 +0,0 @@ - -package uk.org.iay.incommon.mda.validate; - -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class RejectAllValidatorTest { - - @Test - public void validate() throws Exception { - final RejectAllValidator v = new RejectAllValidator<>(); - v.setId("comp"); - v.initialize(); - - final Item item = new MockItem("test"); - final Validator.Action action = v.validate("foo", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 1); - - final ErrorStatus err = errs.get(0); - Assert.assertEquals(err.getComponentId(), "stage/comp"); - Assert.assertEquals(err.getStatusMessage(), "value rejected: 'foo'"); - } - - @Test - public void validateWithMessage() throws Exception { - final RejectAllValidator v = new RejectAllValidator<>(); - v.setId("comp"); - v.setMessage("decimal %.2f"); - v.initialize(); - - final Item item = new MockItem("test"); - final Validator.Action action = v.validate(new Double(1.25), item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 1); - - final ErrorStatus err = errs.get(0); - Assert.assertEquals(err.getComponentId(), "stage/comp"); - Assert.assertEquals(err.getStatusMessage(), "decimal 1.25"); - } - -} diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/ValidatorSequenceTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/ValidatorSequenceTest.java deleted file mode 100644 index 274c0a8..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/ValidatorSequenceTest.java +++ /dev/null @@ -1,89 +0,0 @@ - -package uk.org.iay.incommon.mda.validate; - -import java.util.ArrayList; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class ValidatorSequenceTest { - - @Test - public void testNoValidators() throws Exception { - final ValidatorSequence v = new ValidatorSequence<>(); - v.setId("seq"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("anything", item, "stage"); - Assert.assertEquals(action, Action.CONTINUE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - - @Test - public void testAcceptReject() throws Exception { - final AcceptAllValidator accept = new AcceptAllValidator<>(); - accept.setId("accept"); - accept.initialize(); - - final RejectAllValidator reject = new RejectAllValidator<>(); - reject.setId("reject"); - reject.initialize(); - - final List> vv = new ArrayList<>(); - vv.add(accept); - vv.add(reject); - - final ValidatorSequence v = new ValidatorSequence<>(); - v.setId("seq"); - v.setValidators(vv); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("anything", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - - @Test - public void testRejectAccept() throws Exception { - final AcceptAllValidator accept = new AcceptAllValidator<>(); - accept.setId("accept"); - accept.initialize(); - - final RejectAllValidator reject = new RejectAllValidator<>(); - reject.setId("reject"); - reject.initialize(); - - final List> vv = new ArrayList<>(); - vv.add(reject); - vv.add(accept); - - final ValidatorSequence v = new ValidatorSequence<>(); - v.setId("seq"); - v.setValidators(vv); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("anything", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 1); - final ErrorStatus err = errs.get(0); - Assert.assertEquals(err.getStatusMessage(), "value rejected: 'anything'"); - Assert.assertEquals(err.getComponentId(), "stage/reject"); - } - -} diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidatorTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidatorTest.java deleted file mode 100644 index 9f79d91..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringRegexValidatorTest.java +++ /dev/null @@ -1,47 +0,0 @@ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class AcceptStringRegexValidatorTest { - - @Test - public void validateMatch() throws Exception { - final AcceptStringRegexValidator v = new AcceptStringRegexValidator(); - v.setId("comp"); - v.setRegex("a*b"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("aaaab", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - - @Test - public void validateMismatch() throws Exception { - final AcceptStringValueValidator v = new AcceptStringValueValidator(); - v.setId("comp"); - v.setValue("a*b"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("aaaaaaabc", item, "stage"); - Assert.assertEquals(action, Action.CONTINUE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - -} diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidatorTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidatorTest.java deleted file mode 100644 index 357abbe..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/string/AcceptStringValueValidatorTest.java +++ /dev/null @@ -1,47 +0,0 @@ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class AcceptStringValueValidatorTest { - - @Test - public void validateMatch() throws Exception { - final AcceptStringValueValidator v = new AcceptStringValueValidator(); - v.setId("comp"); - v.setValue("match"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("match", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - - @Test - public void validateMismatch() throws Exception { - final AcceptStringValueValidator v = new AcceptStringValueValidator(); - v.setId("comp"); - v.setValue("match"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("no match", item, "stage"); - Assert.assertEquals(action, Action.CONTINUE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - -} diff --git a/src/test/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidatorTest.java b/src/test/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidatorTest.java deleted file mode 100644 index 73c8c50..0000000 --- a/src/test/java/uk/org/iay/incommon/mda/validate/string/RejectStringRegexValidatorTest.java +++ /dev/null @@ -1,70 +0,0 @@ - -package uk.org.iay.incommon.mda.validate.string; - -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import net.shibboleth.metadata.ErrorStatus; -import net.shibboleth.metadata.Item; -import net.shibboleth.metadata.testing.MockItem; -import net.shibboleth.metadata.validate.Validator; -import net.shibboleth.metadata.validate.Validator.Action; - -public class RejectStringRegexValidatorTest { - - @Test - public void validateMatch() throws Exception { - final RejectStringRegexValidator v = new RejectStringRegexValidator(); - v.setId("comp"); - v.setRegex("a*b"); - v.setMessage("the lazy fox jumped over the %s"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("aaaab", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 1); - final ErrorStatus err = errs.get(0); - Assert.assertTrue(err.getStatusMessage().contains("the lazy fox")); - Assert.assertTrue(err.getStatusMessage().contains("aaaab")); - } - - @Test - public void whitespaceMatch() throws Exception { - final RejectStringRegexValidator v = new RejectStringRegexValidator(); - v.setId("comp"); - v.setRegex(".*\\s.*"); - v.setMessage("the lazy fox jumped over the '%s'"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate(" example.org", item, "stage"); - Assert.assertEquals(action, Action.DONE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 1); - final ErrorStatus err = errs.get(0); - Assert.assertTrue(err.getStatusMessage().contains("the lazy fox")); - Assert.assertTrue(err.getStatusMessage().contains("' example.org'")); - } - - @Test - public void validateMismatch() throws Exception { - final AcceptStringValueValidator v = new AcceptStringValueValidator(); - v.setId("comp"); - v.setValue("a*b"); - v.initialize(); - - final Item item = new MockItem("content"); - final Validator.Action action = v.validate("aaaaaaabc", item, "stage"); - Assert.assertEquals(action, Action.CONTINUE); - - final List errs = item.getItemMetadata().get(ErrorStatus.class); - Assert.assertEquals(errs.size(), 0); - } - -} diff --git a/src/test/resources/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStageLitmusTest-config.xml b/src/test/resources/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStageLitmusTest-config.xml index 3a8c461..2de10cc 100644 --- a/src/test/resources/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStageLitmusTest-config.xml +++ b/src/test/resources/uk/org/iay/incommon/mda/dom/saml/shib/ScopeValidationStageLitmusTest-config.xml @@ -9,6 +9,7 @@ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> + @@ -16,9 +17,9 @@ class="uk.org.iay.incommon.mda.dom.saml.shib.ScopeValidationStage"> - - @@ -36,13 +37,13 @@ - - - -