use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldParseMessageEvenWithoutSource.
@Test
public void shouldParseMessageEvenWithoutSource() {
// Given
Source source = null;
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
HttpMessage messageHtmlResponse = createMessageWith("NoURLsSpiderHtmlParser.html");
// When
htmlParser.parseResource(messageHtmlResponse, source, BASE_DEPTH);
// Then = No exception
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldUseAbsolutePathBaseElement.
@Test
public void shouldUseAbsolutePathBaseElement() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("BaseWithAbsolutePathHrefAElementSpiderHtmlParser.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/base/absolute/path/relative/a/element", "http://example.com/absolute/a/element"));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldIgnoreBaseAndUseMessageUriIfBaseElementHaveEmptyHref.
@Test
public void shouldIgnoreBaseAndUseMessageUriIfBaseElementHaveEmptyHref() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("BaseWithEmptyHrefAElementSpiderHtmlParser.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 net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldFindUrlsInIFrameElements.
@Test
public void shouldFindUrlsInIFrameElements() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("IFrameElementsSpiderHtmlParser.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://iframe.example.com/base/scheme", "http://iframe.example.com:8000/b", "https://iframe.example.com/c?a=b", "http://example.com/sample/iframe/relative", "http://example.com/sample/", "http://example.com/iframe/absolute", "ftp://iframe.example.com/"));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlParserUnitTest method shouldIgnoreBaseAndUseMessageUriIfBaseElementDoesNotHaveHref.
@Test
public void shouldIgnoreBaseAndUseMessageUriIfBaseElementDoesNotHaveHref() {
// Given
SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage messageHtmlResponse = createMessageWith("BaseWithoutHrefAElementSpiderHtmlParser.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"));
}
Aggregations