Search in sources :

Example 56 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class VariantCookieUnitTest method shouldIgnorePreviouslyInjectCookieModifications.

@Test
void shouldIgnorePreviouslyInjectCookieModifications() {
    // Given
    VariantCookie variantCookie = new VariantCookie();
    HttpMessage message = createMessageWithCookies("a=b; c=d; e=f");
    variantCookie.setMessage(message);
    // When
    String previouslyInjectedCookie = variantCookie.setParameter(message, cookie("a", "b", 0), "y", "z");
    String injectedCookie = variantCookie.setParameter(message, cookie("e", "f", 2), "i", "j");
    // Then
    assertThat(previouslyInjectedCookie, is(equalTo("y=z")));
    assertThat(injectedCookie, is(equalTo("i=j")));
    assertThat(message, containsCookieHeader("a=b; c=d; i=j"));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 57 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class VariantCookieUnitTest method createMessageWithCookies.

private static HttpMessage createMessageWithCookies(String... cookieHeaders) {
    HttpMessage message = new HttpMessage();
    try {
        StringBuilder requestHeaderBuilder = new StringBuilder("GET / HTTP/1.1\r\nHost: example.com\r\n");
        for (String cookieHeader : cookieHeaders) {
            requestHeaderBuilder.append("Cookie: ");
            requestHeaderBuilder.append(cookieHeader);
            requestHeaderBuilder.append("\r\n");
        }
        message.setRequestHeader(requestHeaderBuilder.toString());
    } catch (HttpMalformedHeaderException e) {
        throw new RuntimeException(e);
    }
    return message;
}
Also used : HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 58 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class VariantCookieUnitTest method shouldExtractParametersFromWellformedCookieHeaders.

@Test
void shouldExtractParametersFromWellformedCookieHeaders() {
    // Given
    VariantCookie variantCookie = new VariantCookie();
    HttpMessage messageWithCookies = createMessageWithCookies("a=b; c=d; e=f", "g=h; i=j; k=l");
    // When
    variantCookie.setMessage(messageWithCookies);
    // Then
    assertThat(variantCookie.getParamList().size(), is(equalTo(6)));
    assertThat(variantCookie.getParamList(), contains(cookie("a", "b", 0), cookie("c", "d", 1), cookie("e", "f", 2), cookie("g", "h", 3), cookie("i", "j", 4), cookie("k", "l", 5)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 59 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class VariantCookieUnitTest method shouldExtractParametersFromWellformedCookieHeader.

@Test
void shouldExtractParametersFromWellformedCookieHeader() {
    // Given
    VariantCookie variantCookie = new VariantCookie();
    HttpMessage messageWithCookies = createMessageWithCookies("a=b; c=\"d\"; e=f");
    // When
    variantCookie.setMessage(messageWithCookies);
    // Then
    assertThat(variantCookie.getParamList().size(), is(equalTo(3)));
    assertThat(variantCookie.getParamList(), contains(cookie("a", "b", 0), cookie("c", "\"d\"", 1), cookie("e", "f", 2)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 60 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class VariantHeaderUnitTest method shouldExtractParametersFromInjectableHeadersEvenIfThereAreNoInjectableHeaders.

@Test
void shouldExtractParametersFromInjectableHeadersEvenIfThereAreNoInjectableHeaders() {
    // Given
    VariantHeader variantHeader = new VariantHeader();
    HttpMessage messageWithHeaders = createMessageWithHeaders(header(HttpRequestHeader.CONTENT_LENGTH, "A"), header("X-Header-A", "X"), header(HttpRequestHeader.CONNECTION, "D"), header("X-Header-B", "Y"), header(HttpRequestHeader.PROXY_AUTHORIZATION, "5"), header("X-Header-C", "Z"));
    // When
    variantHeader.setMessage(messageWithHeaders);
    // Then
    assertThat(variantHeader.getParamList().size(), is(equalTo(3)));
    assertThat(variantHeader.getParamList(), contains(header("X-Header-A", "X", 0), header("X-Header-B", "Y", 1), header("X-Header-C", "Z", 2)));
}
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