Search in sources :

Example 66 with HttpMessage

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));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with HttpMessage

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()));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 68 with HttpMessage

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)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 69 with HttpMessage

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;
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 70 with HttpMessage

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)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

HttpMessage (org.parosproxy.paros.network.HttpMessage)460 Test (org.junit.jupiter.api.Test)360 Source (net.htmlparser.jericho.Source)86 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)86 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)57 CustomPage (org.zaproxy.zap.extension.custompages.CustomPage)48 SpiderParam (org.zaproxy.zap.spider.SpiderParam)36 URI (org.apache.commons.httpclient.URI)34 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)32 IOException (java.io.IOException)26 DatabaseException (org.parosproxy.paros.db.DatabaseException)26 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)17 FilterResult (org.zaproxy.zap.spider.filters.ParseFilter.FilterResult)17 HistoryReference (org.parosproxy.paros.model.HistoryReference)14 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)14 AuthenticationState (org.zaproxy.zap.users.AuthenticationState)14 URIException (org.apache.commons.httpclient.URIException)13 User (org.zaproxy.zap.users.User)13 IHTTPSession (fi.iki.elonen.NanoHTTPD.IHTTPSession)11