use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldFindUrlsInScriptElements.
@Test
void shouldFindUrlsInScriptElements() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("ScriptElementsSpiderHtmlParser.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(7)));
assertThat(listener.getUrlsFound(), contains("http://script.example.com/base/scheme", "http://script.example.com:8000/b", "https://script.example.com/c?a=b", "http://example.com/sample/script/relative", "http://example.com/sample/", "http://example.com/script/absolute", "ftp://script.example.com/"));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldUseMessageUriIfNoBaseElement.
@Test
void shouldUseMessageUriIfNoBaseElement() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("NoBaseWithAElementSpiderHtmlParser.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(1)));
assertThat(listener.getUrlsFound(), contains("http://example.com/relative/no/base"));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldFindUrlsInLinkElements.
@Test
void shouldFindUrlsInLinkElements() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("LinkElementsSpiderHtmlParser.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(7)));
assertThat(listener.getUrlsFound(), contains("http://link.example.com/base/scheme", "http://link.example.com:8000/b", "https://link.example.com/c?a=b", "http://example.com/sample/link/relative", "http://example.com/sample/", "http://example.com/link/absolute", "ftp://link.example.com/"));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldUseRelativePathBaseElement.
@Test
void shouldUseRelativePathBaseElement() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("BaseWithRelativePathHrefAElementSpiderHtmlParser.html", "/a/b");
Source source = createSource(messageHtmlResponse);
// When
boolean completelyParsed = htmlParser.parseResource(messageHtmlResponse, source, BASE_DEPTH);
// Then
assertThat(completelyParsed, is(equalTo(false)));
assertThat(listener.getNumberOfUrlsFound(), is(equalTo(2)));
assertThat(listener.getUrlsFound(), contains("http://example.com/a/base/relative/path/relative/a/element", "http://example.com/absolute/a/element"));
}
use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldFailToParseAnUndefinedMessage.
@Test
void shouldFailToParseAnUndefinedMessage() {
// Given
HttpMessage undefinedMessage = null;
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
Source source = createSource(createMessageWith("NoURLsSpiderHtmlParser.html"));
// When / Then
assertThrows(NullPointerException.class, () -> htmlParser.parseResource(undefinedMessage, source, BASE_DEPTH));
}
Aggregations