Search in sources :

Example 6 with Source

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
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 7 with Source

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"));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 8 with Source

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"));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 9 with Source

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/"));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 10 with Source

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"));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Aggregations

Source (net.htmlparser.jericho.Source)77 HttpMessage (org.parosproxy.paros.network.HttpMessage)73 Test (org.junit.Test)71 SpiderParam (org.zaproxy.zap.spider.SpiderParam)24 DefaultValueGenerator (org.zaproxy.zap.model.DefaultValueGenerator)6 Element (net.htmlparser.jericho.Element)3 Date (java.util.Date)2 DatabaseException (org.parosproxy.paros.db.DatabaseException)2 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)2 Matcher (java.util.regex.Matcher)1 Attribute (net.htmlparser.jericho.Attribute)1 StartTag (net.htmlparser.jericho.StartTag)1 URIException (org.apache.commons.httpclient.URIException)1 HistoryFilter (org.parosproxy.paros.extension.history.HistoryFilter)1 HistoryReference (org.parosproxy.paros.model.HistoryReference)1 HtmlParameter (org.parosproxy.paros.network.HtmlParameter)1 SpiderParser (org.zaproxy.zap.spider.parser.SpiderParser)1