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

[ES-834] #1206

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,5 +1,6 @@
package io.mosip.authentication.esignet.integration.service;

import io.mosip.kernel.core.exception.ExceptionUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -47,17 +48,20 @@ public class IdaAuditPluginImpl implements AuditPlugin {
@Value("${mosip.esignet.authenticator.ida.audit-manager-url}")
private String auditManagerUrl;

@Value("${mosip.audit.description.max-length:2048}")
private Integer auditDescriptionMaxLength;

@Override
public void logAudit(Action action, ActionStatus status, AuditDTO audit, Throwable t) {
audit(null, action, status, audit);
audit(null, action, status, audit,t);
}

@Override
public void logAudit(String username, Action action, ActionStatus status, AuditDTO audit, Throwable t) {
audit(username, action, status, audit);
audit(username, action, status, audit,t);
}

private void audit(String username, Action action, ActionStatus status, AuditDTO audit) {
private void audit(String username, Action action, ActionStatus status, AuditDTO audit, Throwable t) {
try {
String authToken = authTransactionHelper.getAuthToken();

Expand All @@ -78,7 +82,11 @@ private void audit(String username, Action action, ActionStatus status, AuditDTO
auditRequest.setCreatedBy(this.getClass().getSimpleName());
auditRequest.setModuleName(action.getModule());
auditRequest.setModuleId(action.getModule());
auditRequest.setDescription(getAuditDescription(audit));
String auditDescription = t != null ? ExceptionUtils.getStackTrace(t) : getAuditDescription(audit);
if (auditDescription != null && auditDescription.length() > auditDescriptionMaxLength) {
auditDescription = auditDescription.substring(0, auditDescriptionMaxLength);
}
auditRequest.setDescription(auditDescription);
auditRequest.setId(audit.getTransactionId());

request.setRequest(auditRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public void logAudit_WithValidStatus_ThenPass() throws Exception {
new ParameterizedTypeReference<ResponseWrapper>() {
};
Mockito.when(authTransactionHelper.getAuthToken()).thenReturn("authToken");
Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(responseType)
)).thenReturn(responseEntity);
// Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
// Mockito.when(restTemplate.exchange(
loganathan-sekaran marked this conversation as resolved.
Show resolved Hide resolved
// Mockito.any(RequestEntity.class),
// Mockito.eq(responseType)
// )).thenReturn(responseEntity);
try {
idaAuditPlugin.logAudit(username,action, status, auditDTO, null);
Assert.assertTrue(true);
Expand All @@ -120,11 +120,11 @@ public void logAudit_WithUnauthorizedStatus_ThenPass() throws Exception {
new ParameterizedTypeReference<ResponseWrapper>() {
};
Mockito.when(authTransactionHelper.getAuthToken()).thenReturn("authToken");
Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(responseType)
)).thenReturn(responseEntity);
// Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
// Mockito.when(restTemplate.exchange(
loganathan-sekaran marked this conversation as resolved.
Show resolved Hide resolved
// Mockito.any(RequestEntity.class),
// Mockito.eq(responseType)
// )).thenReturn(responseEntity);
try {
idaAuditPlugin.logAudit(username,action, status, auditDTO, null);
Assert.assertTrue(true);
Expand All @@ -145,11 +145,11 @@ public void logAudit_WithForbiddenStatus_ThenPass() throws Exception {
new ParameterizedTypeReference<ResponseWrapper>() {
};
Mockito.when(authTransactionHelper.getAuthToken()).thenReturn("authToken");
Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(responseType)
)).thenReturn(responseEntity);
// Mockito.when(objectMapper.writeValueAsString(any())).thenReturn("requestBody");
// Mockito.when(restTemplate.exchange(
// Mockito.any(RequestEntity.class),
loganathan-sekaran marked this conversation as resolved.
Show resolved Hide resolved
// Mockito.eq(responseType)
// )).thenReturn(responseEntity);
try {
idaAuditPlugin.logAudit(username,action, status, auditDTO, null);
Assert.assertTrue(true);
Expand Down