|
@@ -44,6 +44,7 @@ import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
@@ -51,7 +52,6 @@ import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
|
public class RequestLoggerTests extends RestClientTestCase {
|
|
|
-
|
|
|
public void testTraceRequest() throws IOException, URISyntaxException {
|
|
|
HttpHost host = new HttpHost("localhost", 9200, randomBoolean() ? "http" : "https");
|
|
|
String expectedEndpoint = "/index/type/_api";
|
|
@@ -69,7 +69,7 @@ public class RequestLoggerTests extends RestClientTestCase {
|
|
|
expected += " -d '" + requestBody + "'";
|
|
|
HttpEntityEnclosingRequest enclosingRequest = (HttpEntityEnclosingRequest) request;
|
|
|
HttpEntity entity;
|
|
|
- switch(randomIntBetween(0, 3)) {
|
|
|
+ switch(randomIntBetween(0, 4)) {
|
|
|
case 0:
|
|
|
entity = new StringEntity(requestBody, StandardCharsets.UTF_8);
|
|
|
break;
|
|
@@ -82,6 +82,10 @@ public class RequestLoggerTests extends RestClientTestCase {
|
|
|
case 3:
|
|
|
entity = new NByteArrayEntity(requestBody.getBytes(StandardCharsets.UTF_8));
|
|
|
break;
|
|
|
+ case 4:
|
|
|
+ // Evil entity without a charset
|
|
|
+ entity = new StringEntity(requestBody, (Charset) null);
|
|
|
+ break;
|
|
|
default:
|
|
|
throw new UnsupportedOperationException();
|
|
|
}
|
|
@@ -116,11 +120,20 @@ public class RequestLoggerTests extends RestClientTestCase {
|
|
|
expected += "\n# \"field\": \"value\"";
|
|
|
expected += "\n# }";
|
|
|
HttpEntity entity;
|
|
|
- if (getRandom().nextBoolean()) {
|
|
|
+ switch(randomIntBetween(0, 2)) {
|
|
|
+ case 0:
|
|
|
entity = new StringEntity(responseBody, StandardCharsets.UTF_8);
|
|
|
- } else {
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
//test a non repeatable entity
|
|
|
entity = new InputStreamEntity(new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)));
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // Evil entity without a charset
|
|
|
+ entity = new StringEntity(responseBody, (Charset) null);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
}
|
|
|
httpResponse.setEntity(entity);
|
|
|
}
|