use of org.opensaml.saml.saml2.core.Issuer in project verify-hub by alphagov.
the class IdpResponseValidatorTest method shouldIncrementCounterWheneverADecrypterFailsToDecrypt.
@Test
public void shouldIncrementCounterWheneverADecrypterFailsToDecrypt() throws Exception {
String issuerValue = "issuerValue";
Assertion assertion = mock(Assertion.class);
List<Assertion> assertions = ImmutableList.of(assertion);
ValidatedResponse validatedResponse = mock(ValidatedResponse.class);
Issuer responseIssuer = mock(Issuer.class);
Counter idpDecryptionErrorCounter = mock(Counter.class);
Counter.Child childCounter = mock(Counter.Child.class);
setFinalStatic(IdpResponseValidator.class.getDeclaredField("idpDecryptionErrorCounter"), idpDecryptionErrorCounter);
when(validatedResponse.getIssuer()).thenReturn(responseIssuer);
when(responseIssuer.getValue()).thenReturn(issuerValue);
when(samlResponseSignatureValidator.validate(response, IDPSSODescriptor.DEFAULT_ELEMENT_NAME)).thenReturn(validatedResponse);
when(assertionDecrypter.decryptAssertions(validatedResponse)).thenThrow(SamlFailedToDecryptException.class);
when(badAssertionDecrypter.decryptAssertions(validatedResponse)).thenReturn(assertions);
when(idpDecryptionErrorCounter.labels(anyString())).thenReturn(childCounter);
doNothing().when(childCounter).inc();
validator.validate(response);
String expectedMessage = String.format("IdpResponseValidator failed to decrypt assertions from issuerValue with one of the decrypters", issuerValue);
verify(mockAppender).doAppend(captorLoggingEvent.capture());
LoggingEvent loggingEvent = captorLoggingEvent.getValue();
assertThat(loggingEvent.getLevel()).isEqualTo(Level.WARN);
assertThat(loggingEvent.getFormattedMessage()).isEqualTo(expectedMessage);
verify(idpDecryptionErrorCounter).labels(validatedResponse.getIssuer().getValue());
verify(childCounter).inc();
}
use of org.opensaml.saml.saml2.core.Issuer in project verify-hub by alphagov.
the class EncryptedResponseFromMatchingServiceValidatorTest method validate_shouldThrowInvalidSamlExceptionIfIssuerIdIsMissing.
@Test
public void validate_shouldThrowInvalidSamlExceptionIfIssuerIdIsMissing() throws Exception {
Issuer issuer = anIssuer().withIssuerId(null).build();
Response response = aResponse().withIssuer(issuer).build();
assertValidationFailure(response, emptyIssuer());
}
use of org.opensaml.saml.saml2.core.Issuer in project verify-hub by alphagov.
the class EncryptedResponseFromIdpValidatorTest method validateIssuer_shouldNotErrorIfFormatAttributeIsMissing.
@Test
public void validateIssuer_shouldNotErrorIfFormatAttributeIsMissing() throws Exception {
Issuer issuer = anIssuer().withFormat(null).build();
Response response = getResponseBuilderWithTwoAssertions().withIssuer(issuer).build();
validator.validate(response);
}
use of org.opensaml.saml.saml2.core.Issuer in project verify-hub by alphagov.
the class EncryptedResponseFromIdpValidatorTest method validate_shouldThrowExceptionIfIssuerIdIsMissing.
@Test
public void validate_shouldThrowExceptionIfIssuerIdIsMissing() throws Exception {
Issuer issuer = anIssuer().withIssuerId(null).build();
Response response = aResponse().withIssuer(issuer).build();
assertValidationFailure(response, emptyIssuer());
}
use of org.opensaml.saml.saml2.core.Issuer in project verify-hub by alphagov.
the class EncryptedResponseFromIdpValidatorTest method validateIssuer_shouldThrowExceptionIfFormatAttributeHasInvalidValue.
@Test
public void validateIssuer_shouldThrowExceptionIfFormatAttributeHasInvalidValue() throws Exception {
String invalidFormat = "goo";
Issuer issuer = anIssuer().withFormat(invalidFormat).build();
Response response = aResponse().withIssuer(issuer).build();
assertValidationFailure(response, illegalIssuerFormat(invalidFormat, NameIDType.ENTITY));
}
Aggregations