Search in sources :

Example 1 with HttpSender

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

the class AbstractPluginUnitTest method shouldSendMessageWithoutScanRuleIdHeaderIfDisabled.

@Test
void shouldSendMessageWithoutScanRuleIdHeaderIfDisabled() throws IOException {
    // Given
    AbstractPlugin plugin = createDefaultPlugin();
    ScannerParam scannerParam = mock(ScannerParam.class);
    given(scannerParam.isInjectPluginIdInHeader()).willReturn(false);
    given(parent.getScannerParam()).willReturn(scannerParam);
    HttpSender httpSender = mock(HttpSender.class);
    given(parent.getHttpSender()).willReturn(httpSender);
    plugin.init(message, parent);
    HttpMessage message = new HttpMessage(new URI("http://example.com/", true));
    // When
    plugin.sendAndReceive(message, true, true);
    // Then
    assertThat(message.getRequestHeader().getHeader(HttpHeader.X_ZAP_SCAN_ID), is(nullValue()));
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender) HttpMessage(org.parosproxy.paros.network.HttpMessage) URI(org.apache.commons.httpclient.URI) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HttpSender

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

the class HttpPanelSender method getDelegate.

private HttpSender getDelegate() {
    if (delegate == null) {
        delegate = new HttpSender(Model.getSingleton().getOptionsParam().getConnectionParam(), getButtonUseTrackingSessionState().isSelected(), HttpSender.MANUAL_REQUEST_INITIATOR);
        delegate.setUseCookies(getButtonUseCookies().isSelected());
    }
    return delegate;
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender)

Example 3 with HttpSender

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

the class Spider method start.

/* SPIDER PROCESS maintenance - pause, resume, shutdown, etc. */
/**
 * Starts the Spider crawling.
 */
public void start() {
    log.info("Starting spider...");
    this.timeStarted = System.currentTimeMillis();
    fetchFilterSeeds();
    // seeds and will not stop.
    if (seedList == null || seedList.isEmpty()) {
        log.warn("No seeds available for the Spider. Cancelling scan...");
        notifyListenersSpiderComplete(false);
        notifyListenersSpiderProgress(100, 0, 0);
        return;
    }
    if (scanUser != null)
        log.info("Scan will be performed from the point of view of User: " + scanUser.getName());
    this.controller.init();
    this.stopped = false;
    this.paused = false;
    this.initialized = false;
    // Initialize the thread pool
    this.threadPool = Executors.newFixedThreadPool(spiderParam.getThreadCount(), new SpiderThreadFactory("ZAP-SpiderThreadPool-" + id + "-thread-"));
    // Initialize the HTTP sender
    httpSender = new HttpSender(connectionParam, connectionParam.isHttpStateEnabled() ? true : !spiderParam.isAcceptCookies(), HttpSender.SPIDER_INITIATOR);
    // Do not follow redirections because the request is not updated, the redirections will be
    // handled manually.
    httpSender.setFollowRedirect(false);
    // Add the seeds
    for (URI uri : seedList) {
        if (log.isDebugEnabled()) {
            log.debug("Adding seed for spider: " + uri);
        }
        controller.addSeed(uri, HttpRequestHeader.GET);
    }
    // Mark the process as completely initialized
    initialized = true;
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender) URI(org.apache.commons.httpclient.URI)

Example 4 with HttpSender

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

the class CoreAPI method sendRequest.

private static void sendRequest(HttpMessage request, boolean followRedirects, Processor<HttpMessage> processor) throws IOException, ApiException {
    HttpSender sender = null;
    try {
        sender = createHttpSender();
        if (followRedirects) {
            ModeRedirectionValidator redirector = new ModeRedirectionValidator(processor);
            sender.sendAndReceive(request, HttpRequestConfig.builder().setRedirectionValidator(redirector).build());
            if (!redirector.isRequestValid()) {
                throw new ApiException(ApiException.Type.MODE_VIOLATION);
            }
        } else {
            sender.sendAndReceive(request, false);
            persistMessage(request);
            processor.process(request);
        }
    } finally {
        if (sender != null) {
            sender.shutdown();
        }
    }
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender)

Example 5 with HttpSender

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

the class AbstractPluginUnitTest method shouldSendMessageWithScanRuleIdHeaderIfEnabled.

@Test
void shouldSendMessageWithScanRuleIdHeaderIfEnabled() throws IOException {
    // Given
    AbstractPlugin plugin = createDefaultPlugin();
    ScannerParam scannerParam = mock(ScannerParam.class);
    given(scannerParam.isInjectPluginIdInHeader()).willReturn(true);
    given(parent.getScannerParam()).willReturn(scannerParam);
    HttpSender httpSender = mock(HttpSender.class);
    given(parent.getHttpSender()).willReturn(httpSender);
    plugin.init(message, parent);
    HttpMessage message = new HttpMessage(new URI("http://example.com/", true));
    // When
    plugin.sendAndReceive(message, true, true);
    // Then
    assertThat(message.getRequestHeader().getHeader(HttpHeader.X_ZAP_SCAN_ID), is(equalTo("123456789")));
}
Also used : HttpSender(org.parosproxy.paros.network.HttpSender) HttpMessage(org.parosproxy.paros.network.HttpMessage) URI(org.apache.commons.httpclient.URI) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpSender (org.parosproxy.paros.network.HttpSender)5 URI (org.apache.commons.httpclient.URI)3 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 HttpMessage (org.parosproxy.paros.network.HttpMessage)2