mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Merge branch '3.1.x'
This commit is contained in:
commit
169070ea1b
|
@ -16,7 +16,7 @@
|
|||
|
||||
package smoketest.jetty.service;
|
||||
|
||||
import smoketest.jetty.util.RandomStringUtil;
|
||||
import smoketest.jetty.util.StringUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -28,16 +28,12 @@ public class HttpHeaderService {
|
|||
private int maxHttpResponseHeaderSize;
|
||||
|
||||
/**
|
||||
* Generates random data. The data is:
|
||||
* <ol>
|
||||
* <li>is longer than configured
|
||||
* <code>server.jetty.max-http-response-header-size</code></li>
|
||||
* <li>is url encoded by base 64 encode the random value</li>
|
||||
* </ol>
|
||||
* @return a base64 encoded string of random bytes
|
||||
* Generates a header value, which is longer than
|
||||
* 'server.jetty.max-http-response-header-size'.
|
||||
* @return the header value
|
||||
*/
|
||||
public String getHeaderValue() {
|
||||
return RandomStringUtil.getRandomBase64EncodedString(this.maxHttpResponseHeaderSize + 1);
|
||||
return StringUtil.repeat('A', this.maxHttpResponseHeaderSize + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,18 +16,17 @@
|
|||
|
||||
package smoketest.jetty.util;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.Random;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class RandomStringUtil {
|
||||
public final class StringUtil {
|
||||
|
||||
private RandomStringUtil() {
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
public static String getRandomBase64EncodedString(int length) {
|
||||
byte[] responseHeader = new byte[length];
|
||||
new Random().nextBytes(responseHeader);
|
||||
return Base64.getEncoder().encodeToString(responseHeader);
|
||||
public static String repeat(char c, int length) {
|
||||
char[] chars = new char[length];
|
||||
Arrays.fill(chars, c);
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,14 +17,12 @@
|
|||
package smoketest.jetty;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import smoketest.jetty.util.RandomStringUtil;
|
||||
import smoketest.jetty.util.StringUtil;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -41,9 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Andy Wilkinson
|
||||
* @author Florian Storz
|
||||
* @author Michael Weidmann
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "logging.level.org.eclipse:trace")
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class SampleJettyApplicationTests {
|
||||
|
||||
@Autowired
|
||||
|
@ -77,7 +75,7 @@ class SampleJettyApplicationTests {
|
|||
|
||||
@Test
|
||||
void testMaxHttpRequestHeaderSize() {
|
||||
String headerValue = RandomStringUtil.getRandomBase64EncodedString(this.maxHttpRequestHeaderSize + 1);
|
||||
String headerValue = StringUtil.repeat('A', this.maxHttpRequestHeaderSize + 1);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("x-max-request-header", headerValue);
|
||||
HttpEntity<?> httpEntity = new HttpEntity<>(headers);
|
||||
|
|
Loading…
Reference in New Issue
Block a user