use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class IssueCredentialHandlerTest method shouldReturnErrorResponseWhenTokenIsMissingBearerPrefix.
@Test
void shouldReturnErrorResponseWhenTokenIsMissingBearerPrefix() throws JsonProcessingException {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
Map<String, String> headers = Collections.singletonMap("Authorization", "11111111");
event.setHeaders(headers);
setRequestBodyAsPlainJWT(event);
APIGatewayProxyResponseEvent response = issueCredentialHandler.handleRequest(event, mockContext);
responseBody = objectMapper.readValue(response.getBody(), new TypeReference<>() {
});
assertEquals(BearerTokenError.INVALID_REQUEST.getHTTPStatusCode(), response.getStatusCode());
assertEquals(BearerTokenError.INVALID_REQUEST.getCode(), responseBody.get("error"));
assertEquals(BearerTokenError.INVALID_REQUEST.getDescription(), responseBody.get("error_description"));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class IssueCredentialHandlerTest method shouldReturnErrorResponseWhenInvalidAccessTokenProvided.
@Test
void shouldReturnErrorResponseWhenInvalidAccessTokenProvided() throws JsonProcessingException {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
AccessToken accessToken = new BearerAccessToken();
Map<String, String> headers = Collections.singletonMap("Authorization", accessToken.toAuthorizationHeader());
event.setHeaders(headers);
setRequestBodyAsPlainJWT(event);
when(mockAccessTokenService.getResourceIdByAccessToken(anyString())).thenReturn(null);
APIGatewayProxyResponseEvent response = issueCredentialHandler.handleRequest(event, mockContext);
Map<String, Object> responseBody = objectMapper.readValue(response.getBody(), new TypeReference<>() {
});
assertEquals(403, response.getStatusCode());
assertEquals(OAuth2Error.ACCESS_DENIED.getCode(), responseBody.get("error"));
assertEquals(OAuth2Error.ACCESS_DENIED.appendDescription(" - The supplied access token was not found in the database").getDescription(), responseBody.get("error_description"));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-ipv-cri-uk-passport-back by alphagov.
the class IssueCredentialHandlerTest method shouldReturn200OnSuccessfulDcsCredentialRequest.
@Test
void shouldReturn200OnSuccessfulDcsCredentialRequest() throws SqsException {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
AccessToken accessToken = new BearerAccessToken();
Map<String, String> headers = Collections.singletonMap("Authorization", accessToken.toAuthorizationHeader());
event.setHeaders(headers);
setRequestBodyAsPlainJWT(event);
when(mockAccessTokenService.getResourceIdByAccessToken(anyString())).thenReturn(TEST_RESOURCE_ID);
when(mockDcsPassportCheckService.getDcsPassportCheck(anyString())).thenReturn(dcsCredential);
APIGatewayProxyResponseEvent response = issueCredentialHandler.handleRequest(event, mockContext);
verify(mockAuditService).sendAuditEvent(AuditEventTypes.PASSPORT_CREDENTIAL_ISSUED);
assertEquals(200, response.getStatusCode());
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent 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.APIGatewayProxyResponseEvent 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