use of org.opensaml.saml.saml1.core.Assertion in project verify-hub by alphagov.
the class IdaResponseFromIdpUnmarshallerTest method transform_shouldTransformTheSamlResponseToIdaResponseByIdp.
@Test
public void transform_shouldTransformTheSamlResponseToIdaResponseByIdp() {
Assertion mdsAssertion = anAssertion().addAttributeStatement(anAttributeStatement().build()).buildUnencrypted();
Assertion authnStatementAssertion = anAssertion().addAuthnStatement(anAuthnStatement().build()).buildUnencrypted();
when(response.getAssertions()).thenReturn(List.of(mdsAssertion, authnStatementAssertion));
PassthroughAssertion passthroughMdsAssertion = aPassthroughAssertion().buildMatchingDatasetAssertion();
when(passthroughAssertionUnmarshaller.fromAssertion(mdsAssertion)).thenReturn(passthroughMdsAssertion);
PassthroughAssertion passthroughAuthnAssertion = aPassthroughAssertion().buildAuthnStatementAssertion();
when(passthroughAssertionUnmarshaller.fromAssertion(authnStatementAssertion)).thenReturn(passthroughAuthnAssertion);
InboundResponseFromIdp inboundResponseFromIdp = unmarshaller.fromSaml(new ValidatedResponse(response), new ValidatedAssertions(response.getAssertions()));
assertThat(inboundResponseFromIdp.getSignature().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getSignature().get()).isEqualTo(signature);
assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().get()).isEqualTo(passthroughAuthnAssertion);
assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().get()).isEqualTo(passthroughMdsAssertion);
}
use of org.opensaml.saml.saml1.core.Assertion in project verify-hub by alphagov.
the class ResponseAssertionsFromIdpValidatorTest method validate_shouldDelegateToIpAddressValidator.
@Test
public void validate_shouldDelegateToIpAddressValidator() throws Exception {
Assertion authnStatementAssertion = anAssertion().addAuthnStatement(anAuthnStatement().build()).buildUnencrypted();
Response response = aResponse().addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()).addEncryptedAssertion(anAssertion().addAuthnStatement(anAuthnStatement().build()).build()).build();
List<Assertion> assertions = asList(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted(), authnStatementAssertion);
validator.validate(new ValidatedResponse(response), new ValidatedAssertions(assertions));
verify(ipAddressValidator).validate(authnStatementAssertion);
}
use of org.opensaml.saml.saml1.core.Assertion in project verify-hub by alphagov.
the class ResponseAssertionsFromIdpValidatorTest method validate_shouldThrowExceptionIfAuthnStatementAssertionIsMissing.
@Test
public void validate_shouldThrowExceptionIfAuthnStatementAssertionIsMissing() throws Exception {
Response response = aResponse().addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()).addEncryptedAssertion(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).build()).build();
List<Assertion> assertions = asList(anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted(), anAssertion().addAttributeStatement(aMatchingDatasetAttributeStatement_1_1().build()).buildUnencrypted());
validateException(assertThrows(SamlTransformationErrorException.class, () -> validator.validate(new ValidatedResponse(response), new ValidatedAssertions(assertions))), SamlTransformationErrorFactory.missingAuthnStatement());
}
use of org.opensaml.saml.saml1.core.Assertion in project verify-hub by alphagov.
the class IdpAssertionMetricsCollectorTest method shouldGetMaxInNotOnOrAfterFromSubjectConfirmations.
@Test
public void shouldGetMaxInNotOnOrAfterFromSubjectConfirmations() {
DateTimeFreezer.freezeTime();
MetricRegistry metricRegistry = new MetricRegistry();
IdpAssertionMetricsCollector idpAssertionMetricsCollector = new IdpAssertionMetricsCollector(metricRegistry);
DateTime notOnOrAfterSmaller = DateTime.now().plusMinutes(15);
DateTime notOnOrAfterBigger = DateTime.now().plusMinutes(30);
Assertion anAssertion = anAssertion().withIssuer(anIssuer().withIssuerId("testIdP").build()).withSubject(aSubject().withSubjectConfirmation(aSubjectConfirmation().withSubjectConfirmationData(aSubjectConfirmationData().withNotOnOrAfter(notOnOrAfterSmaller).build()).build()).withSubjectConfirmation(aSubjectConfirmation().withSubjectConfirmationData(aSubjectConfirmationData().withNotOnOrAfter(notOnOrAfterBigger).build()).build()).build()).buildUnencrypted();
idpAssertionMetricsCollector.update(anAssertion);
Gauge actual = metricRegistry.getGauges().get("notOnOrAfter.testIdP");
assertThat(actual.getValue()).isEqualTo(30L);
}
use of org.opensaml.saml.saml1.core.Assertion in project verify-hub by alphagov.
the class UnknownMethodAlgorithmLoggerTest method shouldReportUnknownDigestAlgorithmInIDPAssertion.
@Test
public void shouldReportUnknownDigestAlgorithmInIDPAssertion() throws Exception {
Assertion authnStatementAssertion = anAssertion().withId(ID).withIssuer(anIssuer().withIssuerId(ISSUER_IDP).build()).withSignature(signatureWithUnknownDigestAlgorithm.get()).buildUnencrypted();
UnknownMethodAlgorithmLogger.probeAssertionForMethodAlgorithm(authnStatementAssertion, AUTHN_STATEMENT);
verifyLog(mockAppender, captorLoggingEvent, 1, String.format(UnknownMethodAlgorithmLogger.DIGEST_ALGORITHM_MESSAGE, IDP, DIGEST_SHA1_ID, AUTHN_STATEMENT + Assertion.DEFAULT_ELEMENT_LOCAL_NAME));
}
Aggregations