use of org.zaproxy.zap.extension.ascan.filters.FilterResult in project zaproxy by zaproxy.
the class HostProcess method filterNode.
private boolean filterNode(StructuralNode node) {
for (ScanFilter scanFilter : parentScanner.getScanFilters()) {
try {
FilterResult filterResult = scanFilter.isFiltered(node);
if (filterResult.isFiltered()) {
try {
HttpMessage msg = node.getHistoryReference().getHttpMessage();
parentScanner.notifyFilteredMessage(msg, filterResult.getReason());
} catch (HttpMalformedHeaderException | DatabaseException e) {
log.warn("Error while getting httpmessage from history reference: " + e.getMessage(), e);
}
if (log.isDebugEnabled()) {
log.debug("Ignoring filtered node: " + node.getName() + " Reason: " + filterResult.getReason());
}
return true;
}
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
}
return false;
}
use of org.zaproxy.zap.extension.ascan.filters.FilterResult in project zaproxy by zaproxy.
the class AbstractGenericScanFilter method isFiltered.
protected FilterResult isFiltered(Collection<V> values) {
Objects.requireNonNull(values);
if (filterData.isEmpty()) {
return FilterResult.NOT_FILTERED;
}
FilterCriteria filterCriteria = this.getFilterCriteria();
switch(filterCriteria) {
case INCLUDE:
if (values.stream().anyMatch(value -> matcher.test(filterData, value))) {
return FilterResult.NOT_FILTERED;
}
return new FilterResult(Constant.messages.getString(INCLUDE_FILTER_CRITERIA_MESSAGE_KEY, this.getFilterType(), filterData));
case EXCLUDE:
for (V value : values) {
if (matcher.test(filterData, value)) {
return new FilterResult(Constant.messages.getString(EXCLUDE_FILTER_CRITERIA_MESSAGE_KEY, this.getFilterType(), "[" + value + "]"));
}
}
return FilterResult.NOT_FILTERED;
default:
return FilterResult.NOT_FILTERED;
}
}
use of org.zaproxy.zap.extension.ascan.filters.FilterResult in project zaproxy by zaproxy.
the class HostProcessUnitTest method shouldNotScanFilteredNode.
@Test
void shouldNotScanFilteredNode() throws Exception {
// Given
ScanFilter scanFilter = mock(ScanFilter.class);
String filteredReason = "reason";
FilterResult filterResult = new FilterResult(filteredReason);
given(scanFilter.isFiltered(any())).willReturn(filterResult);
given(scanner.getScanFilters()).willReturn(asList(scanFilter));
HttpMessage httpMessage = mock(HttpMessage.class);
StructuralNode node = createLeafNode("GET:file", "GET", "http://localhost/file");
given(node.getHistoryReference().getHttpMessage()).willReturn(httpMessage);
hostProcess.setStartNode(node);
// When
hostProcess.run();
// Then
assertThat(hostProcess.getTestTotalCount(), is(equalTo(0)));
verify(scanFilter).isFiltered(node);
verify(scanner).notifyFilteredMessage(httpMessage, filteredReason);
}
use of org.zaproxy.zap.extension.ascan.filters.FilterResult in project zaproxy by zaproxy.
the class GenericFilterUtilityTest method testIncludeCriteriaWithSameValues.
@Test
void testIncludeCriteriaWithSameValues() {
// Given
List<String> genericFilterData = new ArrayList<>();
genericFilterData.add("Dummy");
abstractGenericScanFilter.setFilterData(genericFilterData);
Set<String> values = new HashSet<>();
values.add("Dummy");
// When
FilterResult filterResult = abstractGenericScanFilter.isFiltered(values);
// Then
assertThat(filterResult.isFiltered(), is(false));
}
use of org.zaproxy.zap.extension.ascan.filters.FilterResult in project zaproxy by zaproxy.
the class GenericFilterUtilityTest method testShouldFailWhenExcludeCriteriaWithMoreValues.
@Test
void testShouldFailWhenExcludeCriteriaWithMoreValues() {
// Given
List<String> genericFilterData = new ArrayList<>();
genericFilterData.add("Dummy");
abstractGenericScanFilter.setFilterData(genericFilterData);
abstractGenericScanFilter.setFilterCriteria(FilterCriteria.EXCLUDE);
Set<String> values = new HashSet<>();
values.add("Dummy");
values.add("Dummy1");
// When
FilterResult filterResult = abstractGenericScanFilter.isFiltered(values);
// Then
assertThat(filterResult.isFiltered(), is(true));
}
Aggregations