Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K1J-232: Updated so additional info only is added to logs if user has authentication context. #1121

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PDLLogServiceTest {
@InjectMocks
PDLLogService pdlLogService;


@BeforeEach
void setUp() {
CERTIFICATE.setMetadata(
Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -451,18 +464,19 @@ 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);

verify(logService).logRevokeIntyg(captor.capture());
assertEquals(expectedLogRequest, captor.getValue());
}


@Test
void shouldLogCreateMessage() {
final var webCertUser = new WebCertUser();
doReturn(webCertUser).when(webCertUserService).getUser();

pdlLogService.logCreateMessage(
PERSON_ID, CERTIFICATE_ID
);
Expand Down
Loading