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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations