Search in sources :

Example 6 with HttpResponseHeader

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

the class HttpBreakpointManagementDaemonImplUnitTest method shouldBreakOnJustHttpResponses.

@Test
public void shouldBreakOnJustHttpResponses() throws HttpMalformedHeaderException {
    impl.setBreakAllResponses(true);
    HttpMessage msg = new HttpMessage();
    assertFalse(impl.isHoldMessage(msg));
    HttpResponseHeader resHeader = new HttpResponseHeader(OK_RESPONSE);
    msg.setResponseHeader(resHeader);
    assertTrue(impl.isHoldMessage(msg));
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 7 with HttpResponseHeader

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

the class FilterDetectSetCookie method onHttpResponseReceive.

@Override
public void onHttpResponseReceive(HttpMessage msg) {
    HttpResponseHeader resHeader = msg.getResponseHeader();
    if (resHeader == null || resHeader.isEmpty()) {
        return;
    }
    if (resHeader.getHeader("Set-cookie") != null) {
        Matcher matcher = pattern.matcher(resHeader.toString());
        List<String> result = new LinkedList<>();
        while (matcher.find()) {
            String cookie = matcher.group(1);
            if (cookie != null) {
                // Modal dialog with OK/cancel and a text field
                getView().getMainFrame().toFront();
                String text = JOptionPane.showInputDialog(getView().getMainFrame(), "Accept the following cookie (Ok=Accept, Cancel=Reject)?", cookie);
                // text == null means cancel pressed.  If cancel, cookie rejected 
                if ((text != null && !text.equals(""))) {
                    resHeader.setHeader("Set-cookie", null);
                    result.add(text);
                } else if (text == null) {
                    resHeader.setHeader("Set-cookie", null);
                }
            }
        }
        if (result.size() > 0) {
            StringBuilder sbContent = new StringBuilder(matcher.replaceAll(""));
            Iterator<String> it = result.iterator();
            while (it.hasNext()) {
                sbContent.append("Set-Cookie: ").append(it.next()).append(CRLF);
            }
            try {
                //	resHeader = new HttpResponseHeader(content);
                resHeader.setMessage(sbContent.toString());
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList)

Example 8 with HttpResponseHeader

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

the class HttpBreakpointManagementDaemonImplUnitTest method shouldStep.

@Test
public void shouldStep() throws HttpMalformedHeaderException {
    impl.setBreakAll(true);
    HttpMessage msg = new HttpMessage();
    assertTrue(impl.isHoldMessage(msg));
    impl.step();
    assertTrue(impl.isStepping());
    // False the first time
    assertFalse(impl.isHoldMessage(msg));
    // Then true for subsequent times
    assertTrue(impl.isHoldMessage(msg));
    assertTrue(impl.isStepping());
    HttpResponseHeader resHeader = new HttpResponseHeader(OK_RESPONSE);
    msg.setResponseHeader(resHeader);
    impl.step();
    assertTrue(impl.isStepping());
    // False the first time
    assertFalse(impl.isHoldMessage(msg));
    // Then true for subsequent times
    assertTrue(impl.isHoldMessage(msg));
    assertTrue(impl.isStepping());
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Example 9 with HttpResponseHeader

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

the class HttpBreakpointManagementDaemonImplUnitTest method shouldBreakOnJustHttpRequests.

@Test
public void shouldBreakOnJustHttpRequests() throws HttpMalformedHeaderException {
    impl.setBreakAllRequests(true);
    HttpMessage msg = new HttpMessage();
    assertTrue(impl.isHoldMessage(msg));
    HttpResponseHeader resHeader = new HttpResponseHeader(OK_RESPONSE);
    msg.setResponseHeader(resHeader);
    assertFalse(impl.isHoldMessage(msg));
}
Also used : HttpResponseHeader(org.parosproxy.paros.network.HttpResponseHeader) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Aggregations

HttpResponseHeader (org.parosproxy.paros.network.HttpResponseHeader)9 HttpMessage (org.parosproxy.paros.network.HttpMessage)5 Test (org.junit.Test)4 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)4 HarContent (edu.umass.cs.benchlab.har.HarContent)1 HarCookie (edu.umass.cs.benchlab.har.HarCookie)1 HarCookies (edu.umass.cs.benchlab.har.HarCookies)1 HarQueryString (edu.umass.cs.benchlab.har.HarQueryString)1 HarResponse (edu.umass.cs.benchlab.har.HarResponse)1 HttpCookie (java.net.HttpCookie)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Before (org.junit.Before)1 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)1 HttpResponseBody (org.zaproxy.zap.network.HttpResponseBody)1