From 20cfe539d38b1e776816486ff7db9861eecf497b Mon Sep 17 00:00:00 2001 From: cigerhed Date: Wed, 18 Sep 2024 08:55:34 +0200 Subject: [PATCH] K1J-232: Updated so additional info only is added to logs if user har authentication context. --- .../web/csintegration/util/PDLLogService.java | 2 +- .../csintegration/util/PDLLogServiceTest.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/web/src/main/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogService.java b/web/src/main/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogService.java index 8b082e9d7d..65bbf6828d 100644 --- a/web/src/main/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogService.java +++ b/web/src/main/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogService.java @@ -123,7 +123,7 @@ public void logCreateMessage(String personId, String certificateId) { } private String additionalInfo() { - final var user = webCertUserService.getUser(); + final var user = webCertUserService.hasAuthenticationContext() ? webCertUserService.getUser() : null; if (user == null) { return null; } diff --git a/web/src/test/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogServiceTest.java b/web/src/test/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogServiceTest.java index 7a9d2736e5..be24bc808a 100644 --- a/web/src/test/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogServiceTest.java +++ b/web/src/test/java/se/inera/intyg/webcert/web/csintegration/util/PDLLogServiceTest.java @@ -66,6 +66,7 @@ class PDLLogServiceTest { @InjectMocks PDLLogService pdlLogService; + @BeforeEach void setUp() { CERTIFICATE.setMetadata( @@ -85,6 +86,7 @@ void shouldLogCreateCertificate() { final var captor = ArgumentCaptor.forClass(LogRequest.class); doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, null); + doReturn(false).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logCreated(CERTIFICATE); @@ -102,6 +104,7 @@ void shouldLogCreateCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logCreated(CERTIFICATE); @@ -134,6 +137,7 @@ void shouldLogReadCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logRead(CERTIFICATE); @@ -165,6 +169,7 @@ void shouldLogSavedCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logSaved(CERTIFICATE); @@ -196,6 +201,7 @@ void shouldLogDeletedCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logDeleted(CERTIFICATE); @@ -236,6 +242,7 @@ void shouldLogForDraftWithSjf() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logPrinted(CERTIFICATE); @@ -272,6 +279,7 @@ void shouldLogForLockedDraftWithSjf() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logPrinted(CERTIFICATE); @@ -308,6 +316,7 @@ void shouldLogForSignedWithSjf() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logPrinted(CERTIFICATE); @@ -344,6 +353,7 @@ void shouldLogForRevokedWithSjf() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logPrinted(CERTIFICATE); @@ -375,6 +385,7 @@ void shouldLogSignCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logSign(CERTIFICATE); @@ -406,6 +417,7 @@ void shouldLogSentCertificateWithAdditionalInfo() { .createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO + ". " + ADDITIONAL_WITH_RECIPIENT_MESSAGE + RECIPIENT_NAME); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logSent(CERTIFICATE); @@ -423,6 +435,7 @@ void shouldLogSentCertificateWithAdditionalInfoWithRecipient() { .createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO + ". " + ADDITIONAL_WITH_RECIPIENT_MESSAGE + RECIPIENT_NAME); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logSent(CERTIFICATE); @@ -451,6 +464,7 @@ void shouldLogRevokeCertificateWithAdditionalInfo() { doReturn(expectedLogRequest).when(logRequestFactory).createLogRequestFromCertificate(CERTIFICATE, ADDITIONAL_INFO); doReturn(mockedUser).when(webCertUserService).getUser(); doReturn(additionalInfoIntegrationParameter()).when(mockedUser).getParameters(); + doReturn(true).when(webCertUserService).hasAuthenticationContext(); pdlLogService.logRevoke(CERTIFICATE); @@ -458,11 +472,11 @@ void shouldLogRevokeCertificateWithAdditionalInfo() { assertEquals(expectedLogRequest, captor.getValue()); } + @Test void shouldLogCreateMessage() { final var webCertUser = new WebCertUser(); doReturn(webCertUser).when(webCertUserService).getUser(); - pdlLogService.logCreateMessage( PERSON_ID, CERTIFICATE_ID );