Search in sources :

Example 16 with HttpRequestHeader

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

the class ScriptsActiveScannerUnitTest method setUp.

@BeforeEach
void setUp() throws Exception {
    extensionScript = mock(ExtensionScript.class);
    parent = mock(HostProcess.class);
    message = new HttpMessage(new HttpRequestHeader("GET / HTTP/1.1"));
    given(extensionLoader.getExtension(ExtensionScript.class)).willReturn(extensionScript);
}
Also used : HostProcess(org.parosproxy.paros.core.scanner.HostProcess) ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with HttpRequestHeader

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

the class APIUnitTest method isApiNonceValid.

private static boolean isApiNonceValid(API api, String requestPath, String nonce) {
    try {
        URI requestUri = Mockito.mock(URI.class);
        when(requestUri.getPath()).thenReturn(requestPath);
        HttpRequestHeader request = Mockito.mock(HttpRequestHeader.class, withSettings().lenient());
        when(request.getURI()).thenReturn(requestUri);
        when(request.getHeader(HttpHeader.X_ZAP_API_NONCE)).thenReturn(nonce);
        when(request.getSenderAddress()).thenReturn(Inet4Address.getByAddress(new byte[] { 127, 0, 0, 1 }));
        return api.hasValidKey(request, new JSONObject());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONObject(net.sf.json.JSONObject) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI)

Example 18 with HttpRequestHeader

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

the class APIUnitTest method createApiRequest.

private static HttpRequestHeader createApiRequest(byte[] remoteAddress, String hostname, String requestUri) throws Exception {
    HttpRequestHeader httpRequestHeader = new HttpRequestHeader("GET " + requestUri + " HTTP/1.1\r\n" + "Host: " + hostname + "\r\n");
    httpRequestHeader.setSenderAddress(Inet4Address.getByAddress(remoteAddress));
    return httpRequestHeader;
}
Also used : HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader)

Example 19 with HttpRequestHeader

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

the class HarUtils method createHarRequest.

public static HarRequest createHarRequest(HttpMessage httpMessage) {
    HttpRequestHeader requestHeader = httpMessage.getRequestHeader();
    HarCookies harCookies = new HarCookies();
    try {
        for (HttpCookie cookie : requestHeader.getHttpCookies()) {
            harCookies.addCookie(new HarCookie(cookie.getName(), cookie.getValue()));
        }
    } catch (IllegalArgumentException e) {
        LOGGER.warn("Ignoring cookies for HAR (\"request\") \"cookies\" list. Request contains invalid cookie: " + e.getMessage());
    }
    HarQueryString harQueryString = new HarQueryString();
    for (HtmlParameter param : httpMessage.getUrlParams()) {
        harQueryString.addQueryParam(new HarQueryParam(param.getName(), param.getValue()));
    }
    HarPostData harPostData = null;
    HttpRequestBody requestBody = httpMessage.getRequestBody();
    if (requestBody.length() >= 0) {
        HarPostDataParams params = new HarPostDataParams();
        String text = "";
        String contentType = requestHeader.getHeader(HttpHeader.CONTENT_TYPE);
        if (contentType == null) {
            contentType = "";
            text = requestBody.toString();
        } else {
            if (StringUtils.startsWithIgnoreCase(contentType.trim(), HttpHeader.FORM_URLENCODED_CONTENT_TYPE)) {
                for (HtmlParameter param : httpMessage.getFormParams()) {
                    params.addPostDataParam(new HarPostDataParam(param.getName(), param.getValue()));
                }
            } else {
                text = requestBody.toString();
            }
        }
        harPostData = new HarPostData(contentType, params, text, null);
    }
    return new HarRequest(requestHeader.getMethod(), requestHeader.getURI().toString(), requestHeader.getVersion(), harCookies, createHarHeaders(requestHeader), harQueryString, harPostData, requestHeader.toString().length(), httpMessage.getRequestBody().length(), null);
}
Also used : HarCookie(edu.umass.cs.benchlab.har.HarCookie) HarQueryString(edu.umass.cs.benchlab.har.HarQueryString) HarCookies(edu.umass.cs.benchlab.har.HarCookies) HarQueryString(edu.umass.cs.benchlab.har.HarQueryString) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) HarQueryParam(edu.umass.cs.benchlab.har.HarQueryParam) HarPostData(edu.umass.cs.benchlab.har.HarPostData) HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) HarRequest(edu.umass.cs.benchlab.har.HarRequest) HtmlParameter(org.parosproxy.paros.network.HtmlParameter) HarPostDataParams(edu.umass.cs.benchlab.har.HarPostDataParams) HttpCookie(java.net.HttpCookie) HarPostDataParam(edu.umass.cs.benchlab.har.HarPostDataParam)

Example 20 with HttpRequestHeader

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

the class HarUtils method createHttpMessage.

public static HttpMessage createHttpMessage(HarRequest harRequest) throws HttpMalformedHeaderException {
    StringBuilder strBuilderReqHeader = new StringBuilder();
    strBuilderReqHeader.append(harRequest.getMethod()).append(' ').append(harRequest.getUrl()).append(' ').append(harRequest.getHttpVersion()).append("\r\n");
    for (HarHeader harHeader : harRequest.getHeaders().getHeaders()) {
        strBuilderReqHeader.append(harHeader.getName()).append(": ").append(harHeader.getValue()).append("\r\n");
    }
    strBuilderReqHeader.append("\r\n");
    StringBuilder strBuilderReqBody = new StringBuilder();
    final HarPostData harPostData = harRequest.getPostData();
    if (harPostData != null) {
        final String text = harPostData.getText();
        if (text != null && !text.isEmpty()) {
            strBuilderReqBody.append(harRequest.getPostData().getText());
        } else if (harPostData.getParams() != null && !harPostData.getParams().getPostDataParams().isEmpty()) {
            for (HarPostDataParam param : harRequest.getPostData().getParams().getPostDataParams()) {
                if (strBuilderReqBody.length() > 0) {
                    strBuilderReqBody.append('&');
                }
                strBuilderReqBody.append(param.getName()).append('=').append(param.getValue());
            }
        }
    }
    return new HttpMessage(new HttpRequestHeader(strBuilderReqHeader.toString()), new HttpRequestBody(strBuilderReqBody.toString()));
}
Also used : HarPostData(edu.umass.cs.benchlab.har.HarPostData) HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) HarHeader(edu.umass.cs.benchlab.har.HarHeader) HarQueryString(edu.umass.cs.benchlab.har.HarQueryString) HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) HarPostDataParam(edu.umass.cs.benchlab.har.HarPostDataParam)

Aggregations

HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)23 HttpMessage (org.parosproxy.paros.network.HttpMessage)13 URI (org.apache.commons.httpclient.URI)11 HttpRequestBody (org.zaproxy.zap.network.HttpRequestBody)4 IOException (java.io.IOException)3 URIException (org.apache.commons.httpclient.URIException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)3 HarPostData (edu.umass.cs.benchlab.har.HarPostData)2 HarPostDataParam (edu.umass.cs.benchlab.har.HarPostDataParam)2 HarQueryString (edu.umass.cs.benchlab.har.HarQueryString)2 Test (org.junit.jupiter.api.Test)2 HttpResponseHeader (org.parosproxy.paros.network.HttpResponseHeader)2 SSLContextManager (ch.csnc.extension.httpclient.SSLContextManager)1 HarCookie (edu.umass.cs.benchlab.har.HarCookie)1 HarCookies (edu.umass.cs.benchlab.har.HarCookies)1 HarHeader (edu.umass.cs.benchlab.har.HarHeader)1 HarPostDataParams (edu.umass.cs.benchlab.har.HarPostDataParams)1 HarQueryParam (edu.umass.cs.benchlab.har.HarQueryParam)1 HarRequest (edu.umass.cs.benchlab.har.HarRequest)1