Search in sources :

Example 1 with PassportCheckDao

use of uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao in project di-ipv-cri-uk-passport-back by alphagov.

the class IssueCredentialHandlerTest method setUp.

@BeforeEach
void setUp() throws Exception {
    attributes.setDcsResponse(validDcsResponse);
    dcsCredential = new PassportCheckDao(TEST_RESOURCE_ID, attributes, evidence, userId);
    responseBody = new HashMap<>();
    ECDSASigner ecSigner = new ECDSASigner(getPrivateKey());
    issueCredentialHandler = new IssueCredentialHandler(mockDcsPassportCheckService, mockAccessTokenService, mockConfigurationService, mockAuditService, ecSigner);
}
Also used : ECDSASigner(com.nimbusds.jose.crypto.ECDSASigner) PassportCheckDao(uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with PassportCheckDao

use of uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao 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());
}
Also used : DcsSignedEncryptedResponse(uk.gov.di.ipv.cri.passport.library.domain.DcsSignedEncryptedResponse) APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) HashMap(java.util.HashMap) PassportAttributes(uk.gov.di.ipv.cri.passport.library.domain.PassportAttributes) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JWSObject(com.nimbusds.jose.JWSObject) PassportCheckDao(uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao) Test(org.junit.jupiter.api.Test)

Example 3 with PassportCheckDao

use of uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao 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());
}
Also used : DcsSignedEncryptedResponse(uk.gov.di.ipv.cri.passport.library.domain.DcsSignedEncryptedResponse) APIGatewayProxyRequestEvent(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent) HashMap(java.util.HashMap) PassportAttributes(uk.gov.di.ipv.cri.passport.library.domain.PassportAttributes) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JWSObject(com.nimbusds.jose.JWSObject) PassportCheckDao(uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao) Test(org.junit.jupiter.api.Test)

Example 4 with PassportCheckDao

use of uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao in project di-ipv-cri-uk-passport-back by alphagov.

the class DateStorePassportCheckIT method shouldGetPassportCheckDaoFromTable.

@Test
void shouldGetPassportCheckDaoFromTable() throws JsonProcessingException {
    PassportCheckDao passportCheckDao = createPassportCheckDao();
    Item item = Item.fromJSON(OBJECT_MAPPER.writeValueAsString(passportCheckDao));
    tableTestHarness.putItem(item);
    PassportCheckDao result = dcsResponseDataStore.getItem(passportCheckDao.getResourceId());
    assertEquals(passportCheckDao.getResourceId(), result.getResourceId());
    assertEquals(passportCheckDao.getAttributes().toString(), result.getAttributes().toString());
    assertEquals(passportCheckDao.getGpg45Score().toString(), result.getGpg45Score().toString());
    assertEquals(passportCheckDao.getUserId(), result.getUserId());
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) PassportCheckDao(uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao) Test(org.junit.jupiter.api.Test)

Example 5 with PassportCheckDao

use of uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao in project di-ipv-cri-uk-passport-back by alphagov.

the class DateStorePassportCheckIT method shouldPutPassportCheckIntoTable.

@Test
void shouldPutPassportCheckIntoTable() throws JsonProcessingException {
    PassportCheckDao passportCheckDao = createPassportCheckDao();
    dcsResponseDataStore.create(passportCheckDao);
    Item savedPassportCheck = tableTestHarness.getItem(RESOURCE_ID_PARAM, passportCheckDao.getResourceId());
    assertEquals(passportCheckDao.getResourceId(), savedPassportCheck.get(RESOURCE_ID_PARAM));
    String attributesJson = OBJECT_MAPPER.writeValueAsString(savedPassportCheck.get(ATTRIBUTES_PARAM));
    PassportAttributes savedPassportAttributes = OBJECT_MAPPER.readValue(attributesJson, PassportAttributes.class);
    assertEquals(passportCheckDao.getAttributes().toString(), savedPassportAttributes.toString());
    String gpg45ScoreJson = OBJECT_MAPPER.writeValueAsString(savedPassportCheck.get(GPG45_SCORE_PARAM));
    Evidence savedEvidence = OBJECT_MAPPER.readValue(gpg45ScoreJson, Evidence.class);
    assertEquals(passportCheckDao.getGpg45Score().toString(), savedEvidence.toString());
    String userId = savedPassportCheck.getString(USER_ID_PARAM);
    assertEquals(passportCheckDao.getUserId(), userId);
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) PassportAttributes(uk.gov.di.ipv.cri.passport.library.domain.PassportAttributes) Evidence(uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Evidence) PassportCheckDao(uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao) Test(org.junit.jupiter.api.Test)

Aggregations

PassportCheckDao (uk.gov.di.ipv.cri.passport.library.persistence.item.PassportCheckDao)13 Test (org.junit.jupiter.api.Test)9 PassportAttributes (uk.gov.di.ipv.cri.passport.library.domain.PassportAttributes)9 JWSObject (com.nimbusds.jose.JWSObject)5 DcsSignedEncryptedResponse (uk.gov.di.ipv.cri.passport.library.domain.DcsSignedEncryptedResponse)5 APIGatewayProxyRequestEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent)4 HashMap (java.util.HashMap)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Evidence (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.Evidence)4 DcsResponse (uk.gov.di.ipv.cri.passport.library.domain.DcsResponse)3 Item (com.amazonaws.services.dynamodbv2.document.Item)2 ParseException (com.nimbusds.oauth2.sdk.ParseException)2 VerifiableCredential (uk.gov.di.ipv.cri.passport.library.domain.verifiablecredential.VerifiableCredential)2 SqsException (uk.gov.di.ipv.cri.passport.library.exceptions.SqsException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JOSEException (com.nimbusds.jose.JOSEException)1 ECDSASigner (com.nimbusds.jose.crypto.ECDSASigner)1 SignedJWT (com.nimbusds.jwt.SignedJWT)1 AuthorizationCode (com.nimbusds.oauth2.sdk.AuthorizationCode)1 AuthenticationRequest (com.nimbusds.openid.connect.sdk.AuthenticationRequest)1