use of org.zaproxy.zap.spider.filters.ParseFilter.FilterResult in project zaproxy by zaproxy.
the class SpiderTask method runImpl.
private void runImpl() {
// Check if the should stop
if (parent.isStopped()) {
log.debug("Spider process is stopped. Skipping crawling task...");
deleteHistoryReference();
return;
}
// Check if the crawling process is paused and do any "before execution" processing
parent.preTaskExecution();
// Fetch the resource
HttpMessage msg;
try {
msg = prepareHttpMessage();
} catch (Exception e) {
log.error("Failed to prepare HTTP message: ", e);
return;
}
try {
fetchResource(msg);
} catch (Exception e) {
setErrorResponse(msg, e);
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg, getSkippedMessage("ioerror")));
return;
}
// Check if the should stop
if (parent.isStopped()) {
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg, getSkippedMessage("stopped")));
log.debug("Spider process is stopped. Skipping crawling task...");
return;
}
// Check if the crawling process is paused
parent.checkPauseAndWait();
// Check the parse filters to see if the resource should be skipped from parsing
FilterResult filterResult = FilterResult.NOT_FILTERED;
boolean wanted = false;
for (ParseFilter filter : parent.getController().getParseFilters()) {
filterResult = filter.filtered(msg);
if (filterResult.isFiltered()) {
break;
} else if (filterResult == FilterResult.WANTED)
wanted = true;
}
if (!wanted && !filterResult.isFiltered()) {
filterResult = parent.getController().getDefaultParseFilter().filtered(msg);
}
if (filterResult.isFiltered()) {
if (log.isDebugEnabled()) {
log.debug("Resource [" + msg.getRequestHeader().getURI() + "] fetched, but will not be parsed due to a ParseFilter rule: " + filterResult.getReason());
}
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg, filterResult.getReason()));
return;
}
// Check if the should stop
if (parent.isStopped()) {
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg, getSkippedMessage("stopped")));
log.debug("Spider process is stopped. Skipping crawling task...");
return;
}
// Check if the crawling process is paused
parent.checkPauseAndWait();
int maxDepth = parent.getSpiderParam().getMaxDepth();
if (maxDepth == SpiderParam.UNLIMITED_DEPTH || resourceFound.getDepth() < maxDepth) {
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg));
processResource(msg);
} else {
parent.notifyListenersSpiderTaskResult(new SpiderTaskResult(msg, getSkippedMessage("maxdepth")));
}
}
use of org.zaproxy.zap.spider.filters.ParseFilter.FilterResult in project zaproxy by zaproxy.
the class DefaultParseFilterUnitTest method shouldNotFilterHttpMessageWithTextResponse.
@Test
void shouldNotFilterHttpMessageWithTextResponse() throws Exception {
// Given
DefaultParseFilter filter = createDefaultParseFilter();
HttpMessage httpMessage = createDefaultRequest();
httpMessage.setResponseHeader("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n");
// When
FilterResult filterResult = filter.filtered(httpMessage);
// Then
assertThat(filterResult.isFiltered(), is(equalTo(false)));
}
use of org.zaproxy.zap.spider.filters.ParseFilter.FilterResult in project zaproxy by zaproxy.
the class DefaultParseFilterUnitTest method shouldNotFilterHttpMessageWithResponseEqualToMaxParseSize.
@Test
void shouldNotFilterHttpMessageWithResponseEqualToMaxParseSize() throws Exception {
// Given
int maxParseSizeBytes = 2;
DefaultParseFilter filter = new DefaultParseFilter(createSpiderParam(maxParseSizeBytes), resourceBundle);
HttpMessage httpMessage = createHttpMessageWithResponseBody("AB");
// When
FilterResult filterResult = filter.filtered(httpMessage);
// Then
assertThat(filterResult.isFiltered(), is(equalTo(false)));
}
use of org.zaproxy.zap.spider.filters.ParseFilter.FilterResult in project zaproxy by zaproxy.
the class DefaultParseFilterUnitTest method shouldNotFilterHttpMessageWithRobotsTxtRequestEvenWithContentType.
@Test
void shouldNotFilterHttpMessageWithRobotsTxtRequestEvenWithContentType() throws Exception {
// Given
DefaultParseFilter filter = createDefaultParseFilter();
HttpMessage httpMessage = createHttpMessageWithRequestUri("/robots.txt");
httpMessage.getResponseHeader().setHeader(HttpHeader.CONTENT_TYPE, "text/plain");
// When
FilterResult filterResult = filter.filtered(httpMessage);
// Then
assertThat(filterResult.isFiltered(), is(equalTo(false)));
}
use of org.zaproxy.zap.spider.filters.ParseFilter.FilterResult in project zaproxy by zaproxy.
the class DefaultParseFilterUnitTest method shouldNotFilterHttpMessageWithRedirectResponse.
@Test
void shouldNotFilterHttpMessageWithRedirectResponse() throws Exception {
// Given
DefaultParseFilter filter = createDefaultParseFilter();
HttpMessage httpMessage = createDefaultRequest();
httpMessage.setResponseHeader("HTTP/1.1 303 See Other\r\n");
// When
FilterResult filterResult = filter.filtered(httpMessage);
// Then
assertThat(filterResult.isFiltered(), is(equalTo(false)));
}
Aggregations