diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2024-10-07 18:13:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-14 20:03:03 +0000 |
commit | 1ad3667d30dd82213ae47bea2c267188f003b2c7 (patch) | |
tree | 422f1f66b48114de0e79de9f7bd53aceff3f7c91 /server/sonar-process | |
parent | ce2e686a3e269f937ffb51635928cd1a597b2d07 (diff) | |
download | sonarqube-1ad3667d30dd82213ae47bea2c267188f003b2c7.tar.gz sonarqube-1ad3667d30dd82213ae47bea2c267188f003b2c7.zip |
NO-JIRA Stop using deprecated methods from RandomStringUtils
Diffstat (limited to 'server/sonar-process')
9 files changed, 69 insertions, 69 deletions
diff --git a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsImplTest.java index d9d22a09d03..fee3eb21507 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsImplTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/NetworkUtilsImplTest.java @@ -29,7 +29,7 @@ import java.util.Set; import org.hamcrest.CoreMatchers; import org.junit.Test; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeThat; @@ -110,7 +110,7 @@ public class NetworkUtilsImplTest { @Test public void toInetAddress_returns_empty_on_unvalid_IP_and_hostname() { - assertThat(underTest.toInetAddress(randomAlphabetic(32))).isEmpty(); + assertThat(underTest.toInetAddress(secure().nextAlphabetic(32))).isEmpty(); } @Test diff --git a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java index bed9daa475f..e271ae24d25 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java @@ -45,8 +45,8 @@ public class PropsTest { @UseDataProvider("beforeAndAfterBlanks") public void constructor_trims_key_and_values_from_Properties_argument(String blankBefore, String blankAfter) { Properties properties = new Properties(); - String key = RandomStringUtils.randomAlphanumeric(3); - String value = RandomStringUtils.randomAlphanumeric(3); + String key = RandomStringUtils.secure().nextAlphanumeric(3); + String value = RandomStringUtils.secure().nextAlphanumeric(3); properties.put(blankBefore + key + blankAfter, blankBefore + value + blankAfter); Props underTest = new Props(properties); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java index 83be9bcb570..afcae5f8ffe 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTest.java @@ -25,7 +25,7 @@ import java.io.ObjectInputStream; import java.util.Random; import org.junit.Test; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder; @@ -121,7 +121,7 @@ public class NodeDetailsTest { public void build_throws_NPE_if_host_is_null() { builderUnderTest .setType(randomType) - .setName(randomAlphanumeric(2)); + .setName(secure().nextAlphanumeric(2)); assertThatThrownBy(() -> builderUnderTest.build()) .isInstanceOf(NullPointerException.class) @@ -132,8 +132,8 @@ public class NodeDetailsTest { public void build_throws_IAE_if_setPort_not_called() { builderUnderTest .setType(randomType) - .setName(randomAlphanumeric(2)) - .setHost(randomAlphanumeric(3)); + .setName(secure().nextAlphanumeric(2)) + .setHost(secure().nextAlphanumeric(3)); assertThatThrownBy(() -> builderUnderTest.build()) .isInstanceOf(IllegalArgumentException.class) @@ -144,8 +144,8 @@ public class NodeDetailsTest { public void build_throws_IAE_if_setStarted_not_called() { builderUnderTest .setType(randomType) - .setName(randomAlphanumeric(2)) - .setHost(randomAlphanumeric(3)) + .setName(secure().nextAlphanumeric(2)) + .setHost(secure().nextAlphanumeric(3)) .setPort(1 + random.nextInt(33)); assertThatThrownBy(() -> builderUnderTest.build()) @@ -190,8 +190,8 @@ public class NodeDetailsTest { @Test public void verify_toString() { - String name = randomAlphanumeric(3); - String host = randomAlphanumeric(10); + String name = secure().nextAlphanumeric(3); + String host = secure().nextAlphanumeric(10); int port = 1 + random.nextInt(10); long startedAt = 1 + random.nextInt(666); @@ -209,8 +209,8 @@ public class NodeDetailsTest { @Test public void verify_getters() { - String name = randomAlphanumeric(3); - String host = randomAlphanumeric(10); + String name = secure().nextAlphanumeric(3); + String host = secure().nextAlphanumeric(10); int port = 1 + random.nextInt(10); long startedAt = 1 + random.nextInt(666); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTestSupport.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTestSupport.java index 191b10bf346..b1da9f7cea3 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTestSupport.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeDetailsTestSupport.java @@ -25,7 +25,7 @@ import java.io.ObjectOutputStream; import java.util.Random; import java.util.stream.IntStream; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.sonar.process.cluster.health.NodeDetails.newNodeDetailsBuilder; import static org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder; @@ -56,7 +56,7 @@ public class NodeDetailsTestSupport { NodeHealth.Builder builder = newNodeHealthBuilder() .setStatus(randomStatus()) .setDetails(randomNodeDetails()); - IntStream.range(0, minCauseCount + random.nextInt(2)).mapToObj(i -> randomAlphanumeric(4)).forEach(builder::addCause); + IntStream.range(0, minCauseCount + random.nextInt(2)).mapToObj(i -> secure().nextAlphanumeric(4)).forEach(builder::addCause); return builder; } @@ -68,8 +68,8 @@ public class NodeDetailsTestSupport { NodeDetails.Builder randomNodeDetailsBuilder() { return newNodeDetailsBuilder() .setType(randomType()) - .setName(randomAlphanumeric(3)) - .setHost(randomAlphanumeric(10)) + .setName(secure().nextAlphanumeric(3)) + .setHost(secure().nextAlphanumeric(10)) .setPort(1 + random.nextInt(10)) .setStartedAt(1 + random.nextInt(666)); } diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java index 129b9b72812..f098069944d 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/NodeHealthTest.java @@ -27,7 +27,7 @@ import java.util.Random; import java.util.stream.IntStream; import org.junit.Test; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.process.cluster.health.NodeHealth.newNodeHealthBuilder; @@ -73,7 +73,7 @@ public class NodeHealthTest { public void clearClauses_clears_clauses_of_builder() { NodeHealth.Builder underTest = testSupport.randomBuilder(); NodeHealth original = underTest - .addCause(randomAlphanumeric(3)) + .addCause(secure().nextAlphanumeric(3)) .build(); underTest.clearCauses(); @@ -96,7 +96,7 @@ public class NodeHealthTest { .clearCauses() .setStatus(newRandomStatus) .setDetails(newNodeDetails); - String[] newCauses = IntStream.range(0, 1 + random.nextInt(2)).mapToObj(i -> randomAlphanumeric(4)).toArray(String[]::new); + String[] newCauses = IntStream.range(0, 1 + random.nextInt(2)).mapToObj(i -> secure().nextAlphanumeric(4)).toArray(String[]::new); Arrays.stream(newCauses).forEach(builder::addCause); NodeHealth newNodeHealth = builder.build(); @@ -158,7 +158,7 @@ public class NodeHealthTest { @Test public void verify_toString() { NodeDetails nodeDetails = testSupport.randomNodeDetails(); - String cause = randomAlphanumeric(4); + String cause = secure().nextAlphanumeric(4); NodeHealth.Builder builder = builderUnderTest .setStatus(randomStatus) .setDetails(nodeDetails) @@ -176,7 +176,7 @@ public class NodeHealthTest { NodeHealth.Builder builder = builderUnderTest .setStatus(randomStatus) .setDetails(nodeDetails); - String[] causes = IntStream.range(0, random.nextInt(10)).mapToObj(i -> randomAlphanumeric(4)).toArray(String[]::new); + String[] causes = IntStream.range(0, random.nextInt(10)).mapToObj(i -> secure().nextAlphanumeric(4)).toArray(String[]::new); Arrays.stream(causes).forEach(builder::addCause); NodeHealth underTest = builder.build(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java index 00e60860b77..85f151bce87 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/cluster/health/SharedHealthStateImplTest.java @@ -32,7 +32,7 @@ import org.sonar.process.LoggingRule; import org.sonar.process.cluster.hz.HazelcastMember; import static java.util.Collections.singleton; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.doReturn; @@ -83,7 +83,7 @@ public class SharedHealthStateImplTest { logging.setLevel(Level.TRACE); NodeHealth newNodeHealth = randomNodeHealth(); Map<String, TimestampedNodeHealth> map = new HashMap<>(); - map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); + map.put(secure().nextAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); doReturn(new HashMap<>(map)).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); UUID uuid = UUID.randomUUID(); when(hazelcastMember.getUuid()).thenReturn(uuid); @@ -165,8 +165,8 @@ public class SharedHealthStateImplTest { public void readAll_logs_message_for_each_non_existing_member_ignored_if_TRACE() { logging.setLevel(Level.TRACE); Map<String, TimestampedNodeHealth> map = new HashMap<>(); - String memberUuid1 = randomAlphanumeric(44); - String memberUuid2 = randomAlphanumeric(44); + String memberUuid1 = secure().nextAlphanumeric(44); + String memberUuid2 = secure().nextAlphanumeric(44); map.put(memberUuid1, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 1)); map.put(memberUuid2, new TimestampedNodeHealth(randomNodeHealth(), clusterTime - 1)); when(hazelcastMember.getClusterTime()).thenReturn(clusterTime); @@ -238,8 +238,8 @@ public class SharedHealthStateImplTest { .setStatus(NodeHealth.Status.values()[random.nextInt(NodeHealth.Status.values().length)]) .setDetails(newNodeDetailsBuilder() .setType(random.nextBoolean() ? NodeDetails.Type.SEARCH : NodeDetails.Type.APPLICATION) - .setName(randomAlphanumeric(30)) - .setHost(randomAlphanumeric(10)) + .setName(secure().nextAlphanumeric(30)) + .setHost(secure().nextAlphanumeric(10)) .setPort(1 + random.nextInt(666)) .setStartedAt(1 + random.nextInt(852)) .build()) diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java index eda1a1708fa..084169a70ee 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java @@ -39,7 +39,7 @@ import org.sonar.process.ProcessId; import org.sonar.process.Props; import static java.lang.String.valueOf; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertThrows; @@ -65,7 +65,7 @@ public class Log4JPropertiesBuilderTest { @Test public void constructor_sets_status_to_ERROR() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Properties properties = newLog4JPropertiesBuilder().rootLoggerConfig(esRootLoggerConfig).logDir(logDir).logPattern(logPattern).build(); assertThat(properties.getProperty("status")).isEqualTo("ERROR"); @@ -79,7 +79,7 @@ public class Log4JPropertiesBuilderTest { @Test public void get_always_returns_a_new_object() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Properties previous = newLog4JPropertiesBuilder().rootLoggerConfig(esRootLoggerConfig).logDir(logDir).logPattern(logPattern).build(); for (int i = 0; i < 2 + new Random().nextInt(5); i++) { @@ -100,7 +100,7 @@ public class Log4JPropertiesBuilderTest { @Test public void buildLogPattern_puts_threadIdFieldPattern_from_RootLoggerConfig_non_null() { - String threadIdFieldPattern = RandomStringUtils.randomAlphabetic(5); + String threadIdFieldPattern = RandomStringUtils.secure().nextAlphabetic(5); String pattern = newLog4JPropertiesBuilder().buildLogPattern( newRootLoggerConfigBuilder() @@ -135,7 +135,7 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_daily_time_rolling_policy_with_max_7_files_for_empty_props() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); var underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) .logDir(logDir) @@ -209,8 +209,8 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_throws_MessageException_when_property_is_not_supported() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); - String invalidPropertyValue = randomAlphanumeric(3); + String logPattern = secure().nextAlphanumeric(15); + String invalidPropertyValue = secure().nextAlphanumeric(3); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( ROLLING_POLICY_PROPERTY, invalidPropertyValue) .rootLoggerConfig(esRootLoggerConfig) @@ -225,8 +225,8 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_with_max_7_files_when_property_starts_with_time_colon() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); - String timePattern = randomAlphanumeric(6); + String logPattern = secure().nextAlphanumeric(15); + String timePattern = secure().nextAlphanumeric(6); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( ROLLING_POLICY_PROPERTY, "time:" + timePattern) @@ -240,8 +240,8 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_when_property_starts_with_time_colon_and_specified_max_number_of_files() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); - String timePattern = randomAlphanumeric(6); + String logPattern = secure().nextAlphanumeric(15); + String timePattern = secure().nextAlphanumeric(6); int maxFile = 1 + new Random().nextInt(10); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( @@ -257,8 +257,8 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_with_max_7_files_when_property_starts_with_size_colon() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); - String sizePattern = randomAlphanumeric(6); + String logPattern = secure().nextAlphanumeric(15); + String sizePattern = secure().nextAlphanumeric(6); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( ROLLING_POLICY_PROPERTY, "size:" + sizePattern) .rootLoggerConfig(esRootLoggerConfig) @@ -271,8 +271,8 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_when_property_starts_with_size_colon_and_specified_max_number_of_files() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); - String sizePattern = randomAlphanumeric(6); + String logPattern = secure().nextAlphanumeric(15); + String sizePattern = secure().nextAlphanumeric(6); int maxFile = 1 + new Random().nextInt(10); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( ROLLING_POLICY_PROPERTY, "size:" + sizePattern, @@ -287,7 +287,7 @@ public class Log4JPropertiesBuilderTest { @Test public void configureGlobalFileLog_sets_properties_for_no_rolling_policy_when_property_is_none() throws Exception { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( ROLLING_POLICY_PROPERTY, "none") .rootLoggerConfig(esRootLoggerConfig) @@ -306,7 +306,7 @@ public class Log4JPropertiesBuilderTest { @Test public void enable_all_logs_to_stdout_write_additionally_Console_appender() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder(ROLLING_POLICY_PROPERTY, "none") .enableAllLogsToConsole(true) @@ -384,9 +384,9 @@ public class Log4JPropertiesBuilderTest { @Test public void apply_fails_with_IAE_if_LogLevelConfig_does_not_have_rootLoggerName_of_Log4J() throws IOException { - LogLevelConfig logLevelConfig = LogLevelConfig.newBuilder(randomAlphanumeric(2)).build(); + LogLevelConfig logLevelConfig = LogLevelConfig.newBuilder(secure().nextAlphanumeric(2)).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -403,7 +403,7 @@ public class Log4JPropertiesBuilderTest { public void apply_fails_with_IAE_if_global_property_has_unsupported_level() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level", "ERROR") .rootLoggerConfig(esRootLoggerConfig) @@ -420,7 +420,7 @@ public class Log4JPropertiesBuilderTest { public void apply_fails_with_IAE_if_process_property_has_unsupported_level() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level.web", "ERROR") .rootLoggerConfig(esRootLoggerConfig) @@ -437,7 +437,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_root_logger_to_INFO_if_no_property_is_set() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -454,7 +454,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_root_logger_to_global_property_if_set() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level", "TRACE") .rootLoggerConfig(esRootLoggerConfig) @@ -469,7 +469,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_root_logger_to_process_property_if_set() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level.web", "DEBUG") .rootLoggerConfig(esRootLoggerConfig) @@ -484,7 +484,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_root_logger_to_process_property_over_global_property_if_both_set() throws IOException { LogLevelConfig config = newLogLevelConfig().rootLevelFor(ProcessId.WEB_SERVER).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level", "DEBUG", "sonar.log.level.web", "TRACE") @@ -500,7 +500,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_domain_property_over_process_and_global_property_if_all_set() throws IOException { LogLevelConfig config = newLogLevelConfig().levelByDomain("foo", ProcessId.WEB_SERVER, LogDomain.ES).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( "sonar.log.level", "DEBUG", @@ -518,7 +518,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_domain_property_over_process_property_if_both_set() throws IOException { LogLevelConfig config = newLogLevelConfig().levelByDomain("foo", ProcessId.WEB_SERVER, LogDomain.ES).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( "sonar.log.level.web", "DEBUG", @@ -535,7 +535,7 @@ public class Log4JPropertiesBuilderTest { public void apply_sets_domain_property_over_global_property_if_both_set() throws IOException { LogLevelConfig config = newLogLevelConfig().levelByDomain("foo", ProcessId.WEB_SERVER, LogDomain.ES).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( "sonar.log.level", "DEBUG", @@ -551,7 +551,7 @@ public class Log4JPropertiesBuilderTest { @Test public void apply_fails_with_IAE_if_domain_property_has_unsupported_level() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); LogLevelConfig config = newLogLevelConfig().levelByDomain("foo", ProcessId.WEB_SERVER, LogDomain.JMX).build(); @@ -571,7 +571,7 @@ public class Log4JPropertiesBuilderTest { public void apply_accepts_any_level_as_hardcoded_level(Level level) throws IOException { LogLevelConfig config = newLogLevelConfig().immutableLevel("bar", level).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -585,7 +585,7 @@ public class Log4JPropertiesBuilderTest { @Test public void apply_set_level_to_OFF_if_sonar_global_level_is_not_set() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -637,7 +637,7 @@ public class Log4JPropertiesBuilderTest { public void apply_does_not_create_loggers_property_if_only_root_level_is_defined() throws IOException { LogLevelConfig logLevelConfig = newLogLevelConfig().rootLevelFor(ProcessId.APP).build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -660,7 +660,7 @@ public class Log4JPropertiesBuilderTest { .build(); File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder() .rootLoggerConfig(esRootLoggerConfig) @@ -674,7 +674,7 @@ public class Log4JPropertiesBuilderTest { @Test public void apply_does_not_set_level_if_sonar_global_level_is_TRACE() throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level", Level.TRACE.toString()) .rootLoggerConfig(esRootLoggerConfig) @@ -687,7 +687,7 @@ public class Log4JPropertiesBuilderTest { private void setLevelToOff(Level globalLogLevel) throws IOException { File logDir = temporaryFolder.newFolder(); - String logPattern = randomAlphanumeric(15); + String logPattern = secure().nextAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder("sonar.log.level", globalLogLevel.toString()) .rootLoggerConfig(esRootLoggerConfig) diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java index df79c5b4d8e..4f1a23c04e7 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/LogLevelConfigTest.java @@ -32,7 +32,7 @@ import static org.sonar.process.logging.LogLevelConfig.newBuilder; public class LogLevelConfigTest { - private final String rootLoggerName = RandomStringUtils.randomAlphabetic(20); + private final String rootLoggerName = RandomStringUtils.secure().nextAlphabetic(20); private LogLevelConfig.Builder underTest = newBuilder(rootLoggerName); @Test @@ -44,7 +44,7 @@ public class LogLevelConfigTest { @Test public void getLoggerName_returns_name_passed_to_builder() { - String rootLoggerName = RandomStringUtils.randomAlphabetic(32); + String rootLoggerName = RandomStringUtils.secure().nextAlphabetic(32); LogLevelConfig logLevelConfig = newBuilder(rootLoggerName).build(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java index 7cd6f7eb572..d807d723b7c 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/LogbackHelperTest.java @@ -56,7 +56,7 @@ import org.sonar.process.ProcessId; import org.sonar.process.Props; import static java.util.stream.Collectors.toList; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; +import static org.apache.commons.lang3.RandomStringUtils.secure; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.fail; @@ -111,7 +111,7 @@ public class LogbackHelperTest { @Test public void buildLogPattern_puts_threadIdFieldPattern_from_RootLoggerConfig_non_null() { - String threadIdFieldPattern = RandomStringUtils.randomAlphabetic(5); + String threadIdFieldPattern = RandomStringUtils.secure().nextAlphabetic(5); String pattern = underTest.buildLogPattern( newRootLoggerConfigBuilder() .setProcessId(ProcessId.APP) @@ -305,7 +305,7 @@ public class LogbackHelperTest { @Test public void apply_fails_with_IAE_if_LogLevelConfig_does_not_have_ROOT_LOGGER_NAME_of_LogBack() { - LogLevelConfig logLevelConfig = LogLevelConfig.newBuilder(randomAlphanumeric(2)).build(); + LogLevelConfig logLevelConfig = LogLevelConfig.newBuilder(secure().nextAlphanumeric(2)).build(); assertThatThrownBy(() -> underTest.apply(logLevelConfig, props)) .isInstanceOf(IllegalArgumentException.class) |