@Test @RunWithCustomExecutor public void should_fail_to_parse_invalid_certificate() throws Exception { ArgumentCaptor<LogbookOperationParameters> captor = ArgumentCaptor.forClass(LogbookOperationParameters.class); LogbookOperationsClient logbookOperationsClient = mock(LogbookOperationsClient.class); given(logbookOperationsClientFactory.getClient()).willReturn(logbookOperationsClient); assertThatThrownBy( () -> personalCertificateService.checkPersonalCertificateExistence(new byte[3], TEST_PERMISSION)) .isInstanceOf(PersonalCertificateException.class); verify(logbookOperationsClient).create(captor.capture()); LogbookOperationParameters parameters = captor.getValue(); verifyNoMoreInteractions(personalRepository, logbookOperationsClient); assertThat(parameters.getParameterValue(eventType)).isEqualTo("STP_PERSONAL_CERTIFICATE_CHECK"); assertThat(parameters.getParameterValue(eventTypeProcess)).isEqualTo("CHECK"); assertThat(parameters.getParameterValue(outcome)).isEqualTo("KO"); assertThat(parameters.getParameterValue(eventDetailData)).isEqualTo(evedetDataInvalidCertificate); }
public void checkPersonalCertificateExistence(byte[] certificate, String permission) throws LogbookClientServerException, LogbookClientAlreadyExistsException, LogbookClientBadRequestException, InvalidParseOperationException, PersonalCertificateException { ParsedCertificate parsedCertificate; if (certificate == null) { createNoPersonalCertificateLogbook(permission); throw new PersonalCertificateException(NO_CERTIFICATE_MESSAGE); } try { parsedCertificate = ParsedCertificate.parseCertificate(certificate); } catch (PersonalCertificateException e) { createInvalidPersonalCertificateLogbook(permission); throw e; } Optional<PersonalCertificateModel> model = findPersonalCertificateByHash(parsedCertificate.getCertificateHash()); if (model.isPresent()) { LOGGER.debug("Access OK for permission {0} with valid personal certificate {1}", permission, parsedCertificate.getCertificateHash()); return; } createInvalidPersonalCertificateLogbook(parsedCertificate, permission); throw new PersonalCertificateException(INVALID_CERTIFICATE); }
PersonalCertificateService { public void checkPersonalCertificateExistence(byte[] certificate, String permission) throws LogbookClientServerException, LogbookClientAlreadyExistsException, LogbookClientBadRequestException, InvalidParseOperationException, PersonalCertificateException { ParsedCertificate parsedCertificate; if (certificate == null) { createNoPersonalCertificateLogbook(permission); throw new PersonalCertificateException(NO_CERTIFICATE_MESSAGE); } try { parsedCertificate = ParsedCertificate.parseCertificate(certificate); } catch (PersonalCertificateException e) { createInvalidPersonalCertificateLogbook(permission); throw e; } Optional<PersonalCertificateModel> model = findPersonalCertificateByHash(parsedCertificate.getCertificateHash()); if (model.isPresent()) { LOGGER.debug("Access OK for permission {0} with valid personal certificate {1}", permission, parsedCertificate.getCertificateHash()); return; } createInvalidPersonalCertificateLogbook(parsedCertificate, permission); throw new PersonalCertificateException(INVALID_CERTIFICATE); } }
PersonalCertificateService { public void checkPersonalCertificateExistence(byte[] certificate, String permission) throws LogbookClientServerException, LogbookClientAlreadyExistsException, LogbookClientBadRequestException, InvalidParseOperationException, PersonalCertificateException { ParsedCertificate parsedCertificate; if (certificate == null) { createNoPersonalCertificateLogbook(permission); throw new PersonalCertificateException(NO_CERTIFICATE_MESSAGE); } try { parsedCertificate = ParsedCertificate.parseCertificate(certificate); } catch (PersonalCertificateException e) { createInvalidPersonalCertificateLogbook(permission); throw e; } Optional<PersonalCertificateModel> model = findPersonalCertificateByHash(parsedCertificate.getCertificateHash()); if (model.isPresent()) { LOGGER.debug("Access OK for permission {0} with valid personal certificate {1}", permission, parsedCertificate.getCertificateHash()); return; } createInvalidPersonalCertificateLogbook(parsedCertificate, permission); throw new PersonalCertificateException(INVALID_CERTIFICATE); } PersonalCertificateService(LogbookOperationsClientFactory logbookOperationsClientFactory,
        PersonalRepository personalRepository); }
PersonalCertificateService { public void checkPersonalCertificateExistence(byte[] certificate, String permission) throws LogbookClientServerException, LogbookClientAlreadyExistsException, LogbookClientBadRequestException, InvalidParseOperationException, PersonalCertificateException { ParsedCertificate parsedCertificate; if (certificate == null) { createNoPersonalCertificateLogbook(permission); throw new PersonalCertificateException(NO_CERTIFICATE_MESSAGE); } try { parsedCertificate = ParsedCertificate.parseCertificate(certificate); } catch (PersonalCertificateException e) { createInvalidPersonalCertificateLogbook(permission); throw e; } Optional<PersonalCertificateModel> model = findPersonalCertificateByHash(parsedCertificate.getCertificateHash()); if (model.isPresent()) { LOGGER.debug("Access OK for permission {0} with valid personal certificate {1}", permission, parsedCertificate.getCertificateHash()); return; } createInvalidPersonalCertificateLogbook(parsedCertificate, permission); throw new PersonalCertificateException(INVALID_CERTIFICATE); } PersonalCertificateService(LogbookOperationsClientFactory logbookOperationsClientFactory,
        PersonalRepository personalRepository); void createPersonalCertificateIfNotPresent(byte[] certificate); void deletePersonalCertificateIfPresent(byte[] certificate); void checkPersonalCertificateExistence(byte[] certificate, String permission); }
PersonalCertificateService { public void checkPersonalCertificateExistence(byte[] certificate, String permission) throws LogbookClientServerException, LogbookClientAlreadyExistsException, LogbookClientBadRequestException, InvalidParseOperationException, PersonalCertificateException { ParsedCertificate parsedCertificate; if (certificate == null) { createNoPersonalCertificateLogbook(permission); throw new PersonalCertificateException(NO_CERTIFICATE_MESSAGE); } try { parsedCertificate = ParsedCertificate.parseCertificate(certificate); } catch (PersonalCertificateException e) { createInvalidPersonalCertificateLogbook(permission); throw e; } Optional<PersonalCertificateModel> model = findPersonalCertificateByHash(parsedCertificate.getCertificateHash()); if (model.isPresent()) { LOGGER.debug("Access OK for permission {0} with valid personal certificate {1}", permission, parsedCertificate.getCertificateHash()); return; } createInvalidPersonalCertificateLogbook(parsedCertificate, permission); throw new PersonalCertificateException(INVALID_CERTIFICATE); } PersonalCertificateService(LogbookOperationsClientFactory logbookOperationsClientFactory,
        PersonalRepository personalRepository); void createPersonalCertificateIfNotPresent(byte[] certificate); void deletePersonalCertificateIfPresent(byte[] certificate); void checkPersonalCertificateExistence(byte[] certificate, String permission);  }