use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class AuthorizationCodeHandlerTest method shouldPersistPassportCheckDaoWithInValidGpg45Score.
@Test
void shouldPersistPassportCheckDaoWithInValidGpg45Score() throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, JOSEException, ParseException, EmptyDcsResponseException {
DcsSignedEncryptedResponse dcsSignedEncryptedResponse = new DcsSignedEncryptedResponse("TEST_PAYLOAD");
when(passportService.dcsPassportCheck(any(JWSObject.class))).thenReturn(dcsSignedEncryptedResponse);
when(dcsCryptographyService.preparePayload(any(PassportAttributes.class))).thenReturn(jwsObject);
when(dcsCryptographyService.unwrapDcsResponse(any(DcsSignedEncryptedResponse.class))).thenReturn(invalidDcsResponse);
when(authorizationCodeService.generateAuthorizationCode()).thenReturn(authorizationCode);
when(authRequestValidator.validateRequest(anyMap(), anyString())).thenReturn(Optional.empty());
var event = new APIGatewayProxyRequestEvent();
Map<String, String> params = new HashMap<>();
params.put(OAuth2RequestParams.REDIRECT_URI, "http://example.com");
params.put(OAuth2RequestParams.CLIENT_ID, "12345");
params.put(OAuth2RequestParams.RESPONSE_TYPE, "code");
params.put(OAuth2RequestParams.SCOPE, "openid");
event.setQueryStringParameters(params);
event.setHeaders(Map.of("user_id", "test-user-id"));
event.setBody(objectMapper.writeValueAsString(validPassportFormData));
underTest.handleRequest(event, context);
ArgumentCaptor<PassportCheckDao> persistedPassportCheckDao = ArgumentCaptor.forClass(PassportCheckDao.class);
verify(passportService).persistDcsResponse(persistedPassportCheckDao.capture());
assertEquals(validPassportFormData.get("passportNumber"), persistedPassportCheckDao.getValue().getAttributes().getPassportNumber());
assertEquals(INVALID_GPG45_SCORE.getStrength(), persistedPassportCheckDao.getValue().getGpg45Score().getStrength());
assertEquals(INVALID_GPG45_SCORE.getValidity(), persistedPassportCheckDao.getValue().getGpg45Score().getValidity());
assertEquals(invalidDcsResponse, persistedPassportCheckDao.getValue().getAttributes().getDcsResponse());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class AuthorizationCodeHandlerTest method shouldReturn200WithCorrectFormData.
@Test
void shouldReturn200WithCorrectFormData() throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, JOSEException, ParseException, EmptyDcsResponseException, SqsException {
DcsSignedEncryptedResponse dcsSignedEncryptedResponse = new DcsSignedEncryptedResponse("TEST_PAYLOAD");
when(passportService.dcsPassportCheck(any(JWSObject.class))).thenReturn(dcsSignedEncryptedResponse);
when(dcsCryptographyService.preparePayload(any(PassportAttributes.class))).thenReturn(jwsObject);
when(dcsCryptographyService.unwrapDcsResponse(any(DcsSignedEncryptedResponse.class))).thenReturn(validDcsResponse);
when(authorizationCodeService.generateAuthorizationCode()).thenReturn(authorizationCode);
when(authRequestValidator.validateRequest(any(), anyString())).thenReturn(Optional.empty());
var event = new APIGatewayProxyRequestEvent();
Map<String, String> params = new HashMap<>();
params.put(OAuth2RequestParams.REDIRECT_URI, "http://example.com");
params.put(OAuth2RequestParams.CLIENT_ID, "12345");
params.put(OAuth2RequestParams.RESPONSE_TYPE, "code");
params.put(OAuth2RequestParams.SCOPE, "openid");
event.setQueryStringParameters(params);
event.setHeaders(Map.of("user_id", "test-user-id"));
event.setBody(objectMapper.writeValueAsString(validPassportFormData));
var response = underTest.handleRequest(event, context);
verify(auditService).sendAuditEvent(AuditEventTypes.PASSPORT_REQUEST_SENT_TO_DCS);
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class AuthorizationCodeHandlerTest method shouldPersistPassportCheckDaoWithValidGpg45Score.
@Test
void shouldPersistPassportCheckDaoWithValidGpg45Score() throws IOException, CertificateException, NoSuchAlgorithmException, InvalidKeySpecException, JOSEException, ParseException, EmptyDcsResponseException {
DcsSignedEncryptedResponse dcsSignedEncryptedResponse = new DcsSignedEncryptedResponse("TEST_PAYLOAD");
when(passportService.dcsPassportCheck(any(JWSObject.class))).thenReturn(dcsSignedEncryptedResponse);
when(dcsCryptographyService.preparePayload(any(PassportAttributes.class))).thenReturn(jwsObject);
when(dcsCryptographyService.unwrapDcsResponse(any(DcsSignedEncryptedResponse.class))).thenReturn(validDcsResponse);
when(authorizationCodeService.generateAuthorizationCode()).thenReturn(authorizationCode);
when(authRequestValidator.validateRequest(anyMap(), anyString())).thenReturn(Optional.empty());
var event = new APIGatewayProxyRequestEvent();
Map<String, String> params = new HashMap<>();
params.put(OAuth2RequestParams.REDIRECT_URI, "http://example.com");
params.put(OAuth2RequestParams.CLIENT_ID, "12345");
params.put(OAuth2RequestParams.RESPONSE_TYPE, "code");
params.put(OAuth2RequestParams.SCOPE, "openid");
event.setQueryStringParameters(params);
event.setHeaders(Map.of("user_id", "test-user-id"));
event.setBody(objectMapper.writeValueAsString(validPassportFormData));
underTest.handleRequest(event, context);
ArgumentCaptor<PassportCheckDao> persistedPassportCheckDao = ArgumentCaptor.forClass(PassportCheckDao.class);
verify(passportService).persistDcsResponse(persistedPassportCheckDao.capture());
assertEquals(validPassportFormData.get("passportNumber"), persistedPassportCheckDao.getValue().getAttributes().getPassportNumber());
assertEquals(VALID_GPG45_SCORE.getStrength(), persistedPassportCheckDao.getValue().getGpg45Score().getStrength());
assertEquals(VALID_GPG45_SCORE.getValidity(), persistedPassportCheckDao.getValue().getGpg45Score().getValidity());
assertEquals(validDcsResponse, persistedPassportCheckDao.getValue().getAttributes().getDcsResponse());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class AccessTokenHandlerTest method shouldReturn400WhenInvalidTokenRequestProvided.
@Test
void shouldReturn400WhenInvalidTokenRequestProvided() throws Exception {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
String invalidTokenRequest = "invalid-token-request";
event.setBody(invalidTokenRequest);
APIGatewayProxyResponseEvent response = handler.handleRequest(event, context);
ErrorObject errorResponse = createErrorObjectFromResponse(response.getBody());
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
assertEquals(OAuth2Error.INVALID_REQUEST.getCode(), errorResponse.getCode());
assertEquals(OAuth2Error.INVALID_REQUEST.getDescription() + ": Missing grant_type parameter", errorResponse.getDescription());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class AccessTokenHandlerTest method shouldReturn400IfAccessTokenServiceDeemsRequestInvalid.
@Test
void shouldReturn400IfAccessTokenServiceDeemsRequestInvalid() throws ParseException {
when(mockAccessTokenService.validateTokenRequest(any())).thenReturn(new ValidationResult<>(false, OAuth2Error.UNSUPPORTED_GRANT_TYPE));
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
String tokenRequestBody = "code=12345&redirect_uri=http://test.com&grant_type=authorization_code&client_id=test_client_id";
event.setBody(tokenRequestBody);
APIGatewayProxyResponseEvent response = handler.handleRequest(event, context);
ErrorObject errorResponse = createErrorObjectFromResponse(response.getBody());
assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode());
assertEquals(OAuth2Error.UNSUPPORTED_GRANT_TYPE.getCode(), errorResponse.getCode());
assertEquals(OAuth2Error.UNSUPPORTED_GRANT_TYPE.getDescription(), errorResponse.getDescription());
}
Aggregations