use of org.zaproxy.zap.spider.parser.SpiderResourceFound in project zaproxy by zaproxy.
the class SpiderController method addSeed.
/**
* Adds a new seed, if it wasn't already processed.
*
* @param uri the uri
* @param method the http method used for fetching the resource
*/
protected void addSeed(URI uri, String method) {
SpiderResourceFound resourceFound = SpiderResourceFound.builder().setUri(uri.toString()).setMethod(method).build();
// Check if the uri was processed already
String resourceIdentifier = "";
try {
resourceIdentifier = buildCanonicalResourceIdentifier(uri, resourceFound);
} catch (URIException e) {
return;
}
synchronized (visitedResources) {
if (visitedResources.contains(resourceIdentifier)) {
log.debug("URI already visited: " + uri);
return;
} else {
visitedResources.add(resourceIdentifier);
}
}
// Create and submit the new task
SpiderTask task = new SpiderTask(spider, resourceFound, uri);
spider.submitTask(task);
// Add the uri to the found list
spider.notifyListenersFoundURI(uri.toString(), method, FetchStatus.SEED);
}
use of org.zaproxy.zap.spider.parser.SpiderResourceFound in project zaproxy by zaproxy.
the class SpiderControllerUnitTest method shouldNotSubmitSamePostTaskWithDifferentDepthAndIgnore.
@Test
void shouldNotSubmitSamePostTaskWithDifferentDepthAndIgnore() {
// Given
SpiderResourceFound spiderResourceFoundDepth1 = createPostSpiderResourceFoundWithHeaders("https://example.com/test.html", "body", 1, false, Collections.emptyList());
SpiderResourceFound spiderResourceFoundDepth2Ignore = createPostSpiderResourceFoundWithHeaders("https://example.com/test.html", "body", 2, true, Collections.emptyList());
// When
spiderController.resourceFound(spiderResourceFoundDepth1);
spiderController.resourceFound(spiderResourceFoundDepth1);
spiderController.resourceFound(spiderResourceFoundDepth2Ignore);
// Then
verify(spider).submitTask(any());
}
use of org.zaproxy.zap.spider.parser.SpiderResourceFound in project zaproxy by zaproxy.
the class SpiderControllerUnitTest method shouldNotSubmitSameGetTaskWithDifferentHeaderWhitespaces.
@Test
void shouldNotSubmitSameGetTaskWithDifferentHeaderWhitespaces() {
// Given
List<HttpHeaderField> requestHeadersWithoutWS = new ArrayList<>();
requestHeadersWithoutWS.add(new HttpHeaderField("X-Custom-Header-1", "xyz"));
List<HttpHeaderField> requestHeadersWithWS = new ArrayList<>();
requestHeadersWithWS.add(new HttpHeaderField("\tX-Custom-Header-1 ", "\nxyz "));
SpiderResourceFound spiderResourceFound1 = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 2, false, requestHeadersWithoutWS);
SpiderResourceFound spiderResourceFound2 = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 2, false, requestHeadersWithWS);
// When
spiderController.resourceFound(spiderResourceFound1);
spiderController.resourceFound(spiderResourceFound2);
// Then
verify(spider).submitTask(any());
}
use of org.zaproxy.zap.spider.parser.SpiderResourceFound in project zaproxy by zaproxy.
the class SpiderControllerUnitTest method shouldNotSubmitSameGetTaskWithDifferentHeaderCases.
@Test
void shouldNotSubmitSameGetTaskWithDifferentHeaderCases() {
// Given
List<HttpHeaderField> requestHeadersUpperCase = new ArrayList<>();
requestHeadersUpperCase.add(new HttpHeaderField("X-CUSTOM-HEADER-1", "XYZ"));
List<HttpHeaderField> requestHeadersLowerCase = new ArrayList<>();
requestHeadersLowerCase.add(new HttpHeaderField("x-custom-header-1", "xyz"));
SpiderResourceFound spiderResourceFound1 = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 2, false, requestHeadersUpperCase);
SpiderResourceFound spiderResourceFound2 = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 2, false, requestHeadersLowerCase);
// When
spiderController.resourceFound(spiderResourceFound1);
spiderController.resourceFound(spiderResourceFound2);
// Then
verify(spider).submitTask(any());
}
use of org.zaproxy.zap.spider.parser.SpiderResourceFound in project zaproxy by zaproxy.
the class SpiderControllerUnitTest method shouldNotSubmitSameGetTaskWithDifferentDepthAndIgnore.
@Test
void shouldNotSubmitSameGetTaskWithDifferentDepthAndIgnore() {
// Given
SpiderResourceFound spiderResourceFoundDepth1 = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 1, false, Collections.emptyList());
SpiderResourceFound spiderResourceFoundDepth2Ignore = createGetSpiderResourceFoundWithHeaders("https://example.com/test.html", 2, true, Collections.emptyList());
// When
spiderController.resourceFound(spiderResourceFoundDepth1);
spiderController.resourceFound(spiderResourceFoundDepth1);
spiderController.resourceFound(spiderResourceFoundDepth2Ignore);
// Then
verify(spider).submitTask(any());
}
Aggregations