use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturnMaxReachedWhenPhoneNumberCodeIsBlocked.
@Test
void shouldReturnMaxReachedWhenPhoneNumberCodeIsBlocked() {
when(codeStorageService.isBlockedForEmail(TEST_EMAIL_ADDRESS, CODE_BLOCKED_KEY_PREFIX)).thenReturn(true);
APIGatewayProxyResponseEvent result = makeCallWithCode(CODE, VERIFY_PHONE_NUMBER.toString());
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1034));
verify(codeStorageService, never()).getOtpCode(session.getEmailAddress(), VERIFY_PHONE_NUMBER);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturnMaxReachedWhenEmailCodeIsBlocked.
@Test
void shouldReturnMaxReachedWhenEmailCodeIsBlocked() {
when(codeStorageService.isBlockedForEmail(TEST_EMAIL_ADDRESS, CODE_BLOCKED_KEY_PREFIX)).thenReturn(true);
APIGatewayProxyResponseEvent result = makeCallWithCode(CODE, VERIFY_EMAIL.toString());
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1033));
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class VerifyCodeHandlerTest method shouldReturnPhoneNumberCodeNotValidStateIfRequestCodeDoesNotMatchStoredCode.
@Test
void shouldReturnPhoneNumberCodeNotValidStateIfRequestCodeDoesNotMatchStoredCode() {
when(configurationService.getCodeMaxRetries()).thenReturn(5);
when(codeStorageService.getOtpCode(TEST_EMAIL_ADDRESS, VERIFY_PHONE_NUMBER)).thenReturn(Optional.of(CODE));
APIGatewayProxyResponseEvent result = makeCallWithCode(INVALID_CODE, VERIFY_PHONE_NUMBER.toString());
assertThat(result, hasStatus(400));
assertThat(result, hasJsonBody(ErrorResponse.ERROR_1037));
verify(authenticationService, never()).updatePhoneNumberVerifiedStatus(TEST_EMAIL_ADDRESS, true);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class ResetPasswordHandlerTest method shouldReturn204ForSuccessfulRequestWithNoCode.
@Test
public void shouldReturn204ForSuccessfulRequestWithNoCode() throws Json.JsonException {
when(authenticationService.getUserCredentialsFromEmail(EMAIL)).thenReturn(generateUserCredentials());
usingValidSession();
NotifyRequest notifyRequest = new NotifyRequest(EMAIL, NotificationType.PASSWORD_RESET_CONFIRMATION);
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, PERSISTENT_ID);
headers.put("Session-Id", session.getSessionId());
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setHeaders(headers);
event.setBody(format("{ \"password\": \"%s\"}", NEW_PASSWORD));
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(204));
verify(sqsClient, times(1)).send(objectMapper.writeValueAsString(notifyRequest));
verify(authenticationService, times(1)).updatePassword(EMAIL, NEW_PASSWORD);
verify(auditService).submitAuditEvent(FrontendAuditableEvent.PASSWORD_RESET_SUCCESSFUL, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, EMAIL, "123.123.123.123", AuditService.UNKNOWN, PERSISTENT_ID);
}
use of com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent in project di-authentication-api by alphagov.
the class ResetPasswordHandlerTest method shouldReturn204ForSuccessfulMigratedUserRequest.
@Test
public void shouldReturn204ForSuccessfulMigratedUserRequest() throws Json.JsonException {
when(codeStorageService.getSubjectWithPasswordResetCode(CODE)).thenReturn(Optional.of(SUBJECT));
when(authenticationService.getUserCredentialsFromSubject(SUBJECT)).thenReturn(generateMigratedUserCredentials());
usingValidSession();
NotifyRequest notifyRequest = new NotifyRequest(EMAIL, NotificationType.PASSWORD_RESET_CONFIRMATION);
Map<String, String> headers = new HashMap<>();
headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, PERSISTENT_ID);
headers.put("Session-Id", session.getSessionId());
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
event.setBody(format("{ \"code\": \"%s\", \"password\": \"%s\"}", CODE, NEW_PASSWORD));
event.setHeaders(headers);
event.setRequestContext(contextWithSourceIp("123.123.123.123"));
APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
assertThat(result, hasStatus(204));
verify(sqsClient, times(1)).send(objectMapper.writeValueAsString(notifyRequest));
verify(authenticationService, times(1)).updatePassword(EMAIL, NEW_PASSWORD);
verify(codeStorageService, times(1)).deleteSubjectWithPasswordResetCode(CODE);
verify(auditService).submitAuditEvent(FrontendAuditableEvent.PASSWORD_RESET_SUCCESSFUL, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, EMAIL, "123.123.123.123", AuditService.UNKNOWN, PERSISTENT_ID);
}
Aggregations