Search in sources :

Example 1 with NotifyRequest

use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.

the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidMfaRequestIsAddedToQueue.

@Test
void shouldCallNotifyWhenValidMfaRequestIsAddedToQueue() throws JsonProcessingException {
    handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_PHONE_NUMBER, MFA_SMS, CODE)), mock(Context.class));
    JsonNode request = notifyStub.waitForRequest(60);
    assertThat(request, hasFieldWithValue("phone_number", equalTo(TEST_PHONE_NUMBER)));
    assertThat(request, hasField("personalisation"));
    JsonNode personalisation = request.get("personalisation");
    assertThat(personalisation, hasFieldWithValue("validation-code", equalTo(CODE)));
    assertThat(personalisation, hasFieldWithValue("validation-code", withLength(equalTo(VERIFICATION_CODE_LENGTH))));
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotifyRequest(uk.gov.di.authentication.shared.entity.NotifyRequest) Test(org.junit.jupiter.api.Test) NotifyIntegrationTest(uk.gov.di.authentication.sharedtest.basetest.NotifyIntegrationTest)

Example 2 with NotifyRequest

use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.

the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidAccountCreatedRequestIsAddedToQueue.

@Test
void shouldCallNotifyWhenValidAccountCreatedRequestIsAddedToQueue() throws JsonProcessingException {
    handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_EMAIL_ADDRESS, ACCOUNT_CREATED_CONFIRMATION)), mock(Context.class));
    JsonNode request = notifyStub.waitForRequest(60);
    assertThat(request, hasFieldWithValue("email_address", equalTo(TEST_EMAIL_ADDRESS)));
    assertThat(request, hasField("personalisation"));
    JsonNode personalisation = request.get("personalisation");
    assertThat(personalisation, hasFieldWithValue("contact-us-link", equalTo("http://localhost:3000/frontend/contact-us")));
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotifyRequest(uk.gov.di.authentication.shared.entity.NotifyRequest) Test(org.junit.jupiter.api.Test) NotifyIntegrationTest(uk.gov.di.authentication.sharedtest.basetest.NotifyIntegrationTest)

Example 3 with NotifyRequest

use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.

the class NotificationHandlerIntegrationTest method shouldCallNotifyWhenValidEmailRequestIsAddedToQueue.

@Test
void shouldCallNotifyWhenValidEmailRequestIsAddedToQueue() throws JsonProcessingException {
    handler.handleRequest(createSqsEvent(new NotifyRequest(TEST_EMAIL_ADDRESS, VERIFY_EMAIL, CODE)), mock(Context.class));
    JsonNode request = notifyStub.waitForRequest(60);
    assertThat(request, hasFieldWithValue("email_address", equalTo(TEST_EMAIL_ADDRESS)));
    assertThat(request, hasField("personalisation"));
    JsonNode personalisation = request.get("personalisation");
    assertThat(personalisation, hasFieldWithValue("email-address", equalTo(TEST_EMAIL_ADDRESS)));
    assertThat(personalisation, hasFieldWithValue("validation-code", equalTo(CODE)));
    assertThat(personalisation, hasFieldWithValue("validation-code", withLength(equalTo(VERIFICATION_CODE_LENGTH))));
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotifyRequest(uk.gov.di.authentication.shared.entity.NotifyRequest) Test(org.junit.jupiter.api.Test) NotifyIntegrationTest(uk.gov.di.authentication.sharedtest.basetest.NotifyIntegrationTest)

Example 4 with NotifyRequest

use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.

the class ResetPasswordRequestHandlerTest method shouldReturn200AndPutMessageOnQueueForAValidRequest.

@Test
void shouldReturn200AndPutMessageOnQueueForAValidRequest() throws JsonProcessingException {
    String persistentId = "some-persistent-id-value";
    Map<String, String> headers = new HashMap<>();
    headers.put(PersistentIdHelper.PERSISTENT_ID_HEADER_NAME, persistentId);
    headers.put("Session-Id", session.getSessionId());
    Subject subject = new Subject("subject_1");
    when(validationService.validateEmailAddress(eq(TEST_EMAIL_ADDRESS))).thenReturn(Optional.empty());
    when(authenticationService.getSubjectFromEmail(TEST_EMAIL_ADDRESS)).thenReturn(subject);
    when(resetPasswordService.buildResetPasswordLink(TEST_SIX_DIGIT_CODE, session.getSessionId(), persistentId)).thenReturn(TEST_RESET_PASSWORD_LINK);
    NotifyRequest notifyRequest = new NotifyRequest(TEST_EMAIL_ADDRESS, RESET_PASSWORD, TEST_RESET_PASSWORD_LINK);
    ObjectMapper objectMapper = new ObjectMapper();
    String serialisedRequest = objectMapper.writeValueAsString(notifyRequest);
    usingValidSession();
    APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
    event.setRequestContext(contextWithSourceIp("123.123.123.123"));
    event.setHeaders(headers);
    event.setBody(format("{ \"email\": \"%s\" }", TEST_EMAIL_ADDRESS));
    APIGatewayProxyResponseEvent result = handler.handleRequest(event, context);
    assertEquals(204, result.getStatusCode());
    verify(awsSqsClient).send(serialisedRequest);
    verify(codeStorageService).savePasswordResetCode(subject.getValue(), TEST_SIX_DIGIT_CODE, CODE_EXPIRY_TIME, RESET_PASSWORD);
    verify(sessionService).save(argThat(this::isSessionWithEmailSent));
    verify(auditService).submitAuditEvent(FrontendAuditableEvent.PASSWORD_RESET_REQUESTED, context.getAwsRequestId(), session.getSessionId(), AuditService.UNKNOWN, AuditService.UNKNOWN, TEST_EMAIL_ADDRESS, "123.123.123.123", AuditService.UNKNOWN, persistentId);
}
Also used : APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NotifyRequest(uk.gov.di.authentication.shared.entity.NotifyRequest) APIGatewayProxyResponseEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent) Subject(com.nimbusds.oauth2.sdk.id.Subject) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 5 with NotifyRequest

use of uk.gov.di.authentication.shared.entity.NotifyRequest in project di-authentication-api by alphagov.

the class NotificationHandlerTest method shouldSuccessfullyProcessMfaessageFromSQSQueue.

@Test
void shouldSuccessfullyProcessMfaessageFromSQSQueue() throws JsonProcessingException, NotificationClientException {
    NotifyRequest notifyRequest = new NotifyRequest(TEST_PHONE_NUMBER, MFA_SMS, "654321");
    String notifyRequestString = objectMapper.writeValueAsString(notifyRequest);
    SQSEvent sqsEvent = generateSQSEvent(notifyRequestString);
    handler.handleRequest(sqsEvent, context);
    Map<String, Object> personalisation = new HashMap<>();
    personalisation.put("validation-code", "654321");
    verify(notificationService).sendText(notifyRequest.getDestination(), personalisation, MFA_SMS);
}
Also used : SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) HashMap(java.util.HashMap) NotifyRequest(uk.gov.di.authentication.shared.entity.NotifyRequest) Test(org.junit.jupiter.api.Test)

Aggregations

NotifyRequest (uk.gov.di.authentication.shared.entity.NotifyRequest)48 Test (org.junit.jupiter.api.Test)39 HashMap (java.util.HashMap)23 APIGatewayProxyRequestEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent)17 APIGatewayProxyResponseEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent)17 SQSEvent (com.amazonaws.services.lambda.runtime.events.SQSEvent)12 Context (com.amazonaws.services.lambda.runtime.Context)7 Subject (com.nimbusds.oauth2.sdk.id.Subject)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 NotifyIntegrationTest (uk.gov.di.authentication.sharedtest.basetest.NotifyIntegrationTest)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ClientRegistry (uk.gov.di.authentication.shared.entity.ClientRegistry)4 ErrorResponse (uk.gov.di.authentication.shared.entity.ErrorResponse)4 ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse (uk.gov.di.authentication.shared.helpers.ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse)4 JsonException (uk.gov.di.authentication.shared.serialization.Json.JsonException)4 ApiGatewayHandlerIntegrationTest (uk.gov.di.authentication.sharedtest.basetest.ApiGatewayHandlerIntegrationTest)3 JsonArgumentMatcher.containsJsonString (uk.gov.di.authentication.sharedtest.matchers.JsonArgumentMatcher.containsJsonString)3 SQSMessage (com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2