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"));
}
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;
}
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)));
}
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)));
}
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)));
}
Aggregations