Skip to content

Commit

Permalink
fix(spring-boot): avoid logging admin user information on INFO (#3957)
Browse files Browse the repository at this point in the history
related to #3956
  • Loading branch information
tasso94 authored Nov 22, 2023
1 parent d99d34b commit 9f3e0d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,4 @@ static User createUser(final IdentityService identityService, final User adminUs
return newUser;
}

@Override
public String toString() {
return createToString(Collections.singletonMap("adminUser", adminUser));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class SpringBootProcessEngineLogger extends BaseLogger {
public static final SpringBootProcessEngineLogger LOG = createLogger(SpringBootProcessEngineLogger.class, PROJECT_CODE, PACKAGE, PROJECT_ID);

public void creatingInitialAdminUser(User adminUser) {
logInfo("010", "Creating initial Admin User: {}", adminUser);
logDebug("010", "Creating initial Admin User: {}", adminUser);
}

public void skipAdminUserCreation(User existingUser) {
logInfo("011", "Skip creating initial Admin User, user does exist: {}", existingUser);
logDebug("011", "Skip creating initial Admin User, user does exist: {}", existingUser);
}

public void createInitialFilter(Filter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
package org.camunda.bpm.spring.boot.starter.configuration.impl.custom;


import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.camunda.bpm.engine.identity.User;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.camunda.bpm.spring.boot.starter.property.CamundaBpmProperties;
import org.camunda.bpm.spring.boot.starter.test.helper.StandaloneInMemoryTestConfiguration;
import org.camunda.bpm.spring.boot.starter.util.SpringBootProcessEngineLogger;
import org.camunda.commons.testing.ProcessEngineLoggingRule;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class CreateAdminUserConfigurationTest {
Expand All @@ -47,10 +53,28 @@ public class CreateAdminUserConfigurationTest {
@Rule
public final ProcessEngineRule processEngineRule = new ProcessEngineRule(processEngineConfiguration.buildProcessEngine());

@Rule
public ProcessEngineLoggingRule loggingRule = new ProcessEngineLoggingRule()
.watch(SpringBootProcessEngineLogger.PACKAGE);

@Test
public void createAdminUser() throws Exception {
public void createAdminUser() {
User user = processEngineRule.getIdentityService().createUserQuery().userId("admin").singleResult();
assertThat(user).isNotNull();
assertThat(user.getEmail()).isEqualTo("admin@localhost");
}

@Test
public void shouldLogInitialAdminUserCreationOnDebug() {
processEngineConfiguration.buildProcessEngine();
verifyLogs(Level.DEBUG, "STARTER-SB010 Creating initial Admin User: AdminUserProperty[id=admin, firstName=Admin, lastName=Admin, email=admin@localhost, password=******]");
}

protected void verifyLogs(Level logLevel, String message) {
List<ILoggingEvent> logs = loggingRule.getLog();
assertThat(logs).hasSize(1);
assertThat(logs.get(0).getLevel()).isEqualTo(logLevel);
assertThat(logs.get(0).getFormattedMessage()).containsIgnoringCase(message);
}

}

0 comments on commit 9f3e0d0

Please sign in to comment.