use of uk.gov.di.ipv.cri.address.library.exception.SessionValidationException in project di-ipv-cri-address-api by alphagov.
the class AddressSessionServiceTest method shouldThrowValidationExceptionWhenRequestClientIdIsInvalid.
@Test
void shouldThrowValidationExceptionWhenRequestClientIdIsInvalid() {
SessionRequestBuilder sessionRequestBuilder = new SessionRequestBuilder().withClientId("bad-client-id");
SessionRequestBuilder.SignedJWTBuilder signedJWTBuilder = new SessionRequestBuilder.SignedJWTBuilder();
SessionRequest sessionRequest = sessionRequestBuilder.build(signedJWTBuilder);
when(mockConfigurationService.getParametersForPath("/clients/bad-client-id/jwtAuthentication")).thenReturn(Map.of());
SessionValidationException exception = assertThrows(SessionValidationException.class, () -> {
addressSessionService.validateSessionRequest(marshallToJSON(sessionRequest));
});
assertThat(exception.getMessage(), containsString("no configuration for client id"));
verify(mockConfigurationService).getParametersForPath("/clients/bad-client-id/jwtAuthentication");
}
use of uk.gov.di.ipv.cri.address.library.exception.SessionValidationException in project di-ipv-cri-address-api by alphagov.
the class AddressSessionServiceTest method shouldThrowValidationExceptionWhenSessionRequestIsInvalid.
@Test
void shouldThrowValidationExceptionWhenSessionRequestIsInvalid() {
SessionValidationException exception = assertThrows(SessionValidationException.class, () -> {
addressSessionService.validateSessionRequest(marshallToJSON(Map.of("not", "a-session-request")));
});
assertThat(exception.getMessage(), containsString("could not parse request body"));
verifyNoInteractions(mockConfigurationService);
}
use of uk.gov.di.ipv.cri.address.library.exception.SessionValidationException in project di-ipv-cri-address-api by alphagov.
the class AddressSessionServiceTest method shouldThrowValidationExceptionWhenJWTIsInvalid.
@Test
void shouldThrowValidationExceptionWhenJWTIsInvalid() {
SessionRequestBuilder sessionRequestBuilder = new SessionRequestBuilder();
SessionRequestBuilder.SignedJWTBuilder signedJWTBuilder = new SessionRequestBuilder.SignedJWTBuilder();
SessionRequest sessionRequest = sessionRequestBuilder.build(signedJWTBuilder);
sessionRequest.setRequestJWT(Base64.getEncoder().encodeToString("not a jwt".getBytes(StandardCharsets.UTF_8)));
when(mockConfigurationService.getParametersForPath("/clients/ipv-core/jwtAuthentication")).thenReturn(standardSSMConfigMap(signedJWTBuilder));
SessionValidationException exception = assertThrows(SessionValidationException.class, () -> {
addressSessionService.validateSessionRequest(marshallToJSON(sessionRequest));
});
assertThat(exception.getMessage(), containsString("Could not parse request JWT"));
}
use of uk.gov.di.ipv.cri.address.library.exception.SessionValidationException in project di-ipv-cri-address-api by alphagov.
the class AddressSessionService method verifyRequestUri.
private void verifyRequestUri(SessionRequest sessionRequest, Map<String, String> clientConfig) throws SessionValidationException {
URI configRedirectUri = URI.create(clientConfig.get("redirectUri"));
URI requestRedirectUri = sessionRequest.getRedirectUri();
if (requestRedirectUri == null || !requestRedirectUri.equals(configRedirectUri)) {
throw new SessionValidationException("redirect uri " + requestRedirectUri + " does not match configuration uri " + configRedirectUri);
}
}
use of uk.gov.di.ipv.cri.address.library.exception.SessionValidationException in project di-ipv-cri-address-api by alphagov.
the class AddressSessionService method verifyJWTHeader.
private void verifyJWTHeader(Map<String, String> clientAuthenticationConfig, SignedJWT signedJWT) throws SessionValidationException {
JWSAlgorithm configuredAlgorithm = JWSAlgorithm.parse(clientAuthenticationConfig.get("authenticationAlg"));
JWSAlgorithm jwtAlgorithm = signedJWT.getHeader().getAlgorithm();
if (jwtAlgorithm != configuredAlgorithm) {
throw new SessionValidationException(String.format("jwt signing algorithm %s does not match signing algorithm configured for client: %s", jwtAlgorithm, configuredAlgorithm));
}
}
Aggregations