diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java index 7c2f23f6315..b01f16fb3d6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/RandomValuePropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.env; +import java.util.HexFormat; import java.util.OptionalInt; import java.util.OptionalLong; import java.util.Random; @@ -31,7 +32,6 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.log.LogMessage; import org.springframework.util.Assert; -import org.springframework.util.DigestUtils; import org.springframework.util.StringUtils; /** @@ -58,6 +58,7 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @author Matt Benson * @author Madhura Bhave + * @author Moritz Halbritter * @since 1.0.0 */ public class RandomValuePropertySource extends PropertySource { @@ -136,9 +137,9 @@ public class RandomValuePropertySource extends PropertySource { } private Object getRandomBytes() { - byte[] bytes = new byte[32]; + byte[] bytes = new byte[16]; getSource().nextBytes(bytes); - return DigestUtils.md5DigestAsHex(bytes); + return HexFormat.of().withLowerCase().formatHex(bytes); } public static void addToEnvironment(ConfigurableEnvironment environment) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java index 77732be5dbd..1fb9ad176d8 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/RandomValuePropertySourceTests.java @@ -37,6 +37,7 @@ import static org.mockito.Mockito.spy; * * @author Dave Syer * @author Matt Benson + * @author Moritz Halbritter */ class RandomValuePropertySourceTests { @@ -192,4 +193,9 @@ class RandomValuePropertySourceTests { RandomValuePropertySource.RANDOM_PROPERTY_SOURCE_NAME, "mockProperties"); } + @Test + void randomStringIs32CharsLong() { + assertThat(this.source.getProperty("random.string")).asString().hasSize(32); + } + }