use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturnEmailCodeNotValidStateIfRequestCodeDoesNotMatchStoredCode.
@Test
void shouldReturnEmailCodeNotValidStateIfRequestCodeDoesNotMatchStoredCode() {
when(configurationService.getCodeMaxRetries()).thenReturn(5);
when(codeStorageService.getOtpCode(TEST_EMAIL_ADDRESS, VERIFY_EMAIL)).thenReturn(Optional.of(CODE));
APIGatewayProxyResponseEvent result = makeCallWithCode(INVALID_CODE, VERIFY_EMAIL.toString());
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1036));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturn204ForValidMfaSmsRequest.
@Test
void shouldReturn204ForValidMfaSmsRequest() {
when(configurationService.getCodeMaxRetries()).thenReturn(5);
when(codeStorageService.getOtpCode(TEST_EMAIL_ADDRESS, MFA_SMS)).thenReturn(Optional.of(CODE));
APIGatewayProxyResponseEvent result = makeCallWithCode(CODE, MFA_SMS.toString());
verify(codeStorageService).deleteOtpCode(TEST_EMAIL_ADDRESS, MFA_SMS);
assertThat(result, hasStatus(204));
verify(auditService).submitAuditEvent(FrontendAuditableEvent.CODE_VERIFIED, context.getAwsRequestId(), session.getSessionId(), CLIENT_ID, "test-subject-id", TEST_EMAIL_ADDRESS, "123.123.123.123", AuditService.UNKNOWN, PersistentIdHelper.PERSISTENT_ID_UNKNOWN_VALUE, pair("notification-type", MFA_SMS.name()));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturn204ForValidVerifyEmailRequestUsingTestClient.
@Test
void shouldReturn204ForValidVerifyEmailRequestUsingTestClient() {
when(configurationService.isTestClientsEnabled()).thenReturn(true);
when(configurationService.getCodeMaxRetries()).thenReturn(5);
when(configurationService.getTestClientVerifyEmailOTP()).thenReturn(Optional.of(TEST_CLIENT_CODE));
when(codeStorageService.getOtpCode(TEST_CLIENT_EMAIL, VERIFY_EMAIL)).thenReturn(Optional.of(CODE));
APIGatewayProxyResponseEvent result = makeCallWithCode(TEST_CLIENT_CODE, VERIFY_EMAIL.toString(), Optional.of(testClientSession), TEST_CLIENT_ID);
verify(codeStorageService).deleteOtpCode(TEST_CLIENT_EMAIL, VERIFY_EMAIL);
assertThat(result, hasStatus(204));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturnMaxReachedWhenMfaCodeIsBlocked.
@Test
void shouldReturnMaxReachedWhenMfaCodeIsBlocked() {
when(codeStorageService.isBlockedForEmail(TEST_EMAIL_ADDRESS, CODE_BLOCKED_KEY_PREFIX)).thenReturn(true);
APIGatewayProxyResponseEvent result = makeCallWithCode(CODE, MFA_SMS.toString());
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1027));
verify(codeStorageService, never()).getOtpCode(session.getEmailAddress(), MFA_SMS);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturn400IfRequestIsMissingNotificationType.
@Test
void shouldReturn400IfRequestIsMissingNotificationType() {
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(Map.of("Session-Id", "a-session-id"));
event.setBody(format("{ \"code\": \"%s\"}", CODE));
when(sessionService.getSessionFromRequestHeaders(event.getHeaders())).thenReturn(Optional.of(session));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1001));
}
Aggregations