Search in sources :

Example 16 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method serverSignatureSuccess.

@Test
public void serverSignatureSuccess() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(mockUtkastRepository.save(any(Utkast.class))).thenReturn(completedUtkast);
    // Do the call
    SignaturTicket signatureTicket = intygSignatureService.serverSignature(INTYG_ID, completedUtkast.getVersion());
    verify(intygService).storeIntyg(completedUtkast);
    verify(notificationService).sendNotificationForDraftSigned(any(Utkast.class));
    // Assert pdl log
    verify(logService).logSignIntyg(any(LogRequest.class));
    assertNotNull(signatureTicket);
    assertNotNull(completedUtkast.getSignatur());
    assertEquals(UtkastStatus.SIGNED, completedUtkast.getStatus());
}
Also used : LogRequest(se.inera.intyg.webcert.web.service.log.dto.LogRequest) Utkast(se.inera.intyg.webcert.persistence.utkast.model.Utkast) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 17 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method getSignatureHashReturnsTicket.

@Test
public void getSignatureHashReturnsTicket() throws ModuleNotFoundException, ModuleException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    assertEquals(INTYG_ID, ticket.getIntygsId());
    assertEquals(completedUtkast.getVersion(), ticket.getVersion());
    assertEquals(SignaturTicket.Status.BEARBETAR, ticket.getStatus());
}
Also used : SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 18 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method abortClientSignIfHsaIdOnSigDoesNotMatchSession.

@Test(expected = WebCertServiceException.class)
public void abortClientSignIfHsaIdOnSigDoesNotMatchSession() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    user = createWebCertUser(true);
    user.setAuthenticationMethod(AuthenticationMethod.SITHS);
    when(webcertUserService.getUser()).thenReturn(user);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    String signature = buildSignature();
    intygSignatureService.clientSignature(ticket.getId(), signature);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 19 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method clientSignatureFailsIfIntygWasModified.

@Test(expected = WebCertServiceException.class)
public void clientSignatureFailsIfIntygWasModified() throws IOException {
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    completedUtkast.setModel("{}");
    String signature = buildSignature();
    intygSignatureService.clientSignature(ticket.getId(), signature);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Example 20 with SignaturTicket

use of se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket in project webcert by sklintyg.

the class SignaturServiceImplTest method abortClientSignIfPersonIdOnSigDoesNotMatchSession.

@Test(expected = WebCertServiceException.class)
public void abortClientSignIfPersonIdOnSigDoesNotMatchSession() throws IOException {
    Role role = AUTHORITIES_RESOLVER.getRole(AuthoritiesConstants.ROLE_PRIVATLAKARE);
    user = createWebCertUser(true);
    user.setAuthenticationMethod(AuthenticationMethod.NET_ID);
    user.setRoles(AuthoritiesResolverUtil.toMap(role));
    user.setPrivatLakareAvtalGodkand(true);
    user.setPersonId(PERSON_ID);
    when(mockUtkastRepository.findOne(INTYG_ID)).thenReturn(completedUtkast);
    when(webcertUserService.getUser()).thenReturn(user);
    SignaturTicket ticket = intygSignatureService.createDraftHash(INTYG_ID, completedUtkast.getVersion());
    String signature = buildSignature();
    intygSignatureService.clientSignature(ticket.getId(), signature);
}
Also used : Role(se.inera.intyg.infra.security.common.model.Role) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SignaturTicket(se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket) Test(org.junit.Test)

Aggregations

SignaturTicket (se.inera.intyg.webcert.web.service.signatur.dto.SignaturTicket)28 Test (org.junit.Test)15 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)12 WebCertServiceException (se.inera.intyg.webcert.common.service.exception.WebCertServiceException)10 LogRequest (se.inera.intyg.webcert.web.service.log.dto.LogRequest)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 SignaturTicketResponse (se.inera.intyg.webcert.web.web.controller.moduleapi.dto.SignaturTicketResponse)6 OptimisticLockException (javax.persistence.OptimisticLockException)5 POST (javax.ws.rs.POST)5 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)5 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)3 SignResponse (com.secmaker.netid.nias.v1.SignResponse)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Optional (java.util.Optional)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Transactional (org.springframework.transaction.annotation.Transactional)1