use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantMultipartFormParametersUnitTest method shouldFailToExtractParametersFromUndefinedMessage.
@Test
void shouldFailToExtractParametersFromUndefinedMessage() {
// Given
VariantMultipartFormParameters variant = new VariantMultipartFormParameters();
HttpMessage undefinedMessage = null;
// Then = IllegalArgumentException
// When / Then
assertThrows(IllegalArgumentException.class, () -> variant.setMessage(undefinedMessage));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantMultipartFormParametersUnitTest method shouldInjectParamValueModificationInFileContentTypeParam.
@Test
void shouldInjectParamValueModificationInFileContentTypeParam() {
// Given
VariantMultipartFormParameters variant = new VariantMultipartFormParameters();
HttpMessage message = createMessage();
String paramName = "somefile";
String newValue = "injected";
variant.setMessage(message);
// When
variant.setParameter(message, new NameValuePair(NameValuePair.TYPE_MULTIPART_DATA_FILE_CONTENTTYPE, paramName, DEFAULT_CONTENT_TYPE, 3), paramName, newValue);
HttpMessage newMsg = createMessage(DEFAULT_PARAM_CONTENT, DEFAULT_FILE_NAME, newValue, DEFAULT_FILE_PARAM_CONTENT);
// Then
assertThat(message.getRequestBody().toString(), equalTo(newMsg.getRequestBody().toString()));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantMultipartFormParametersUnitTest method shouldExtractParametersFromAllPartsEventIfTheyContainRegexChars.
@Test
void shouldExtractParametersFromAllPartsEventIfTheyContainRegexChars() {
// Given
VariantMultipartFormParameters variant = new VariantMultipartFormParameters();
HttpMessage message = createBaseMessage();
StringBuilder bodySb = new StringBuilder(320);
bodySb.append("--------------------------d74496d66958873e").append(CRLF);
bodySb.append("Content-Disposition: form-data; name=\"param[]\"").append(CRLF);
bodySb.append(CRLF);
bodySb.append("paramContent[]").append(CRLF);
bodySb.append("--------------------------d74496d66958873e").append(CRLF);
bodySb.append("Content-Disposition: form-data; name=\"somefile[]\"; filename=\"file[]\"").append(CRLF);
bodySb.append("Content-Type: ContentType[]").append(CRLF);
bodySb.append(CRLF);
bodySb.append("filecontent[]").append(CRLF);
bodySb.append("--------------------------d74496d66958873e--").append(CRLF);
message.setRequestBody(bodySb.toString());
// When
variant.setMessage(message);
// Then
assertThat(variant.getParamList().size(), is(equalTo(4)));
assertThat(variant.getParamList().get(0).getPosition(), is(equalTo(1)));
assertThat(variant.getParamList().get(0).getName(), is(equalTo("param[]")));
assertThat(variant.getParamList().get(0).getValue(), is(equalTo("paramContent[]")));
assertThat(variant.getParamList().get(0).getType(), is(equalTo(NameValuePair.TYPE_MULTIPART_DATA_PARAM)));
assertThat(variant.getParamList().get(1).getPosition(), is(equalTo(2)));
assertThat(variant.getParamList().get(1).getName(), is(equalTo("somefile[]")));
assertThat(variant.getParamList().get(1).getValue(), is(equalTo("file[]")));
assertThat(variant.getParamList().get(1).getType(), is(equalTo(NameValuePair.TYPE_MULTIPART_DATA_FILE_NAME)));
assertThat(variant.getParamList().get(2).getPosition(), is(equalTo(3)));
assertThat(variant.getParamList().get(2).getName(), is(equalTo("somefile[]")));
assertThat(variant.getParamList().get(2).getValue(), is(equalTo("ContentType[]")));
assertThat(variant.getParamList().get(2).getType(), is(equalTo(NameValuePair.TYPE_MULTIPART_DATA_FILE_CONTENTTYPE)));
assertThat(variant.getParamList().get(3).getPosition(), is(equalTo(4)));
assertThat(variant.getParamList().get(3).getName(), is(equalTo("somefile[]")));
assertThat(variant.getParamList().get(3).getValue(), is(equalTo("filecontent[]")));
assertThat(variant.getParamList().get(3).getType(), is(equalTo(NameValuePair.TYPE_MULTIPART_DATA_FILE_PARAM)));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantMultipartFormParametersUnitTest method createBaseMessage.
private static HttpMessage createBaseMessage() {
HttpMessage message = new HttpMessage();
try {
message.setRequestHeader("GET / HTTP/1.1\r\n");
message.getRequestHeader().setHeader(HttpHeader.CONTENT_TYPE, "multipart/form-data; boundary=------------------------d74496d66958873e");
} catch (HttpMalformedHeaderException e) {
throw new RuntimeException(e);
}
return message;
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class VariantCookieUnitTest method shouldNotDecodeNameFromExtractedParameters.
@Test
void shouldNotDecodeNameFromExtractedParameters() {
// Given
VariantCookie variantCookie = new VariantCookie();
HttpMessage messageWithCookies = createMessageWithCookies("%29=b; c=d; e=f", "%26=");
// When
variantCookie.setMessage(messageWithCookies);
// Then
assertThat(variantCookie.getParamList().size(), is(equalTo(4)));
assertThat(variantCookie.getParamList(), contains(cookie("%29", "b", 0), cookie("c", "d", 1), cookie("e", "f", 2), cookie("%26", "", 3)));
}
Aggregations