use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderRobotstxtParserUnitTest method shouldNotBeCompletelyParsedIfParseDisabled.
@Test
void shouldNotBeCompletelyParsedIfParseDisabled() {
// Given
SpiderParam spiderParam = createSpiderParamWithConfig();
spiderParam.setParseRobotsTxt(false);
SpiderRobotstxtParser spiderParser = new SpiderRobotstxtParser(spiderParam);
HttpMessage message = createMessageWith("");
// When
boolean completelyParsed = spiderParser.parseResource(message, null, BASE_DEPTH);
// Then
assertThat(completelyParsed, is(equalTo(false)));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderRobotstxtParserUnitTest method shouldFailToParseAnUndefinedMessage.
@Test
void shouldFailToParseAnUndefinedMessage() {
// Given
HttpMessage undefinedMessage = null;
SpiderRobotstxtParser spiderParser = new SpiderRobotstxtParser(new SpiderParam());
// When / Then
assertThrows(NullPointerException.class, () -> spiderParser.parseResource(undefinedMessage, null, BASE_DEPTH));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldNotFindUrlsInCommentsWithElementsIfNotEnabledToParseComments.
@Test
void shouldNotFindUrlsInCommentsWithElementsIfNotEnabledToParseComments() {
// Given
SpiderParam spiderOptions = createSpiderParamWithConfig();
spiderOptions.setParseComments(false);
SpiderHtmlParser htmlParser = new SpiderHtmlParser(spiderOptions);
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("CommentWithElementsSpiderHtmlParser.html");
Source source = createSource(messageHtmlResponse);
// When
boolean completelyParsed = htmlParser.parseResource(messageHtmlResponse, source, BASE_DEPTH);
// Then
assertThat(completelyParsed, is(equalTo(false)));
assertThat(listener.getNumberOfUrlsFound(), is(equalTo(0)));
assertThat(listener.getUrlsFound(), is(empty()));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldNotParseHtmlResponseIfAlreadyParsed.
@Test
void shouldNotParseHtmlResponseIfAlreadyParsed() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
HttpMessage messageHtmlResponse = createMessageWith("NoURLsSpiderHtmlParser.html");
boolean parsed = true;
// When
boolean canParse = htmlParser.canParseResource(messageHtmlResponse, ROOT_PATH, parsed);
// Then
assertThat(canParse, is(equalTo(false)));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldFindUrlsInAnchorPingElements.
@Test
void shouldFindUrlsInAnchorPingElements() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("AElementsWithPingSpiderHtmlParser.html");
Source source = createSource(messageHtmlResponse);
// When
boolean completelyParsed = htmlParser.parseResource(messageHtmlResponse, source, BASE_DEPTH);
// Then
assertThat(completelyParsed, is(equalTo(false)));
assertThat(listener.getNumberOfUrlsFound(), is(equalTo(23)));
assertThat(listener.getUrlsFound(), contains(// a URLs followed by ping URLs
"http://a.example.com/base/scheme", "http://ping.example.com/base/scheme", "http://a.example.com:8000/b", "http://ping.example.com:8000/b", "https://a.example.com/c?a=b", "https://ping.example.com/c?a=b", "http://example.com/sample/a/relative", "http://example.com/sample/a/relative/ping", "http://example.com/a/absolute", "http://example.com/a/absolute/ping", "ftp://a.example.com/", "https://ping.example.com/ping", // Ping first, is parsed href before ping
"http://b.example.com/", "https://ping.first.com/", // Ignored anchors but picked pings
"http://ping.example.com/mailping", "http://ping.example.com/jsping", "http://ping.example.com/ping", // Multiple ping URLs
"http://a.example.com/", "http://ping.example.com/", "http://pong.example.com/", // Multiple ping URLs with tab in the middle
"http://a.example.com/", "http://ping.example.com/", // Trailing slash is added on host
"http://pong.example.com/"));
}
Aggregations