/** Test that the condition is properly added if there are multiple assertions in the response. */ @Test public void testMultipleAssertion() throws Exception { final Response response = SAML1ActionTestingSupport.buildResponse(); response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion()); response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion()); response.getAssertions().add(SAML1ActionTestingSupport.buildAssertion()); final ProfileRequestContext prc = new RequestContextBuilder().setOutboundMessage(response).buildProfileRequestContext(); action.execute(prc); ActionTestingSupport.assertProceedEvent(prc); Assert.assertNotNull(response.getAssertions()); Assert.assertEquals(response.getAssertions().size(), 3); for (Assertion assertion : response.getAssertions()) { Assert.assertNotNull(assertion.getConditions()); Assert.assertEquals(assertion.getConditions().getAudienceRestrictionConditions().size(), 1); final AudienceRestrictionCondition audcond = assertion.getConditions().getAudienceRestrictionConditions().get(0); Assert.assertEquals(audcond.getAudiences().size(), 2); Assert.assertEquals(audcond.getAudiences().get(0).getUri(), AUDIENCE1); Assert.assertEquals(audcond.getAudiences().get(1).getUri(), AUDIENCE2); } }
/** Test that an addition condition is not added if an assertion already contains one. */ @Test public void testSingleAssertionWithExistingAudienceCondition() throws Exception { final SAMLObjectBuilder<AudienceRestrictionCondition> conditionBuilder = (SAMLObjectBuilder<AudienceRestrictionCondition>) XMLObjectProviderRegistrySupport.getBuilderFactory() .getBuilder(AudienceRestrictionCondition.DEFAULT_ELEMENT_NAME); final AudienceRestrictionCondition condition = conditionBuilder.buildObject(); final SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) XMLObjectProviderRegistrySupport.getBuilderFactory() .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); final Conditions conditions = conditionsBuilder.buildObject(); conditions.getAudienceRestrictionConditions().add(condition); final Assertion assertion = SAML1ActionTestingSupport.buildAssertion(); assertion.setConditions(conditions); final Response response = SAML1ActionTestingSupport.buildResponse(); response.getAssertions().add(assertion); final ProfileRequestContext prc = new RequestContextBuilder().setOutboundMessage(response).buildProfileRequestContext(); action.execute(prc); ActionTestingSupport.assertProceedEvent(prc); Assert.assertNotNull(assertion.getConditions()); Assert.assertEquals(assertion.getConditions().getAudienceRestrictionConditions().size(), 1); final AudienceRestrictionCondition audcond = assertion.getConditions().getAudienceRestrictionConditions().get(0); Assert.assertEquals(audcond.getAudiences().size(), 2); Assert.assertEquals(audcond.getAudiences().get(0).getUri(), AUDIENCE1); Assert.assertEquals(audcond.getAudiences().get(1).getUri(), AUDIENCE2); }
/** Test that action behaves properly if there is no assertion in the response. */ @Test public void testNoAssertion() throws Exception { final ProfileRequestContext prc = new RequestContextBuilder() .setOutboundMessage(SAML1ActionTestingSupport.buildResponse()) .buildProfileRequestContext(); action.execute(prc); ActionTestingSupport.assertProceedEvent(prc); }