Search in sources :

Example 76 with Source

use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.

the class SpiderHtmlFormParserUnitTest method shouldFailToParseAnUndefinedMessage.

@Test(expected = NullPointerException.class)
public void shouldFailToParseAnUndefinedMessage() {
    // Given
    HttpMessage undefinedMessage = null;
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    Source source = createSource(createMessageWith("NoForms.html"));
    // When
    htmlParser.parseResource(undefinedMessage, source, BASE_DEPTH);
// Then = NullPointerException
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 77 with Source

use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.

the class SpiderHtmlFormParserUnitTest method shouldUseAbsolutePathBaseHtmlUrlWhenParsingGetFormWithRelativeAction.

@Test
public void shouldUseAbsolutePathBaseHtmlUrlWhenParsingGetFormWithRelativeAction() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage msg = createMessageWith("GET", "FormWithHtmlBase.html", "action/relative", "/base/absolute/path/", "/a/b.html");
    Source source = createSource(msg);
    // When
    boolean completelyParsed = htmlParser.parseResource(msg, source, BASE_DEPTH);
    // Then
    assertThat(completelyParsed, is(equalTo(false)));
    assertThat(listener.getNumberOfUrlsFound(), is(equalTo(1)));
    assertThat(listener.getUrlsFound(), contains("http://example.com/base/absolute/path/action/relative?q=Search&submit=Submit"));
}
Also used : 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