Search in sources :

Example 51 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldRemoveFragmentFromActionWhenParsingGetForm.

@Test
public void shouldRemoveFragmentFromActionWhenParsingGetForm() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("GET", "FormActionWithFragment.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.org/?field1=Text+1&field2=Text+2&submit=Submit"));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 52 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldNotParsePostFormIfPostFormProcessingIsDisabled.

@Test
public void shouldNotParsePostFormIfPostFormProcessingIsDisabled() {
    // Given
    SpiderParam spiderOptions = createSpiderParamWithConfig();
    spiderOptions.setProcessForm(true);
    spiderOptions.setPostForm(false);
    SpiderHtmlFormParser htmlParser = new SpiderHtmlFormParser(spiderOptions, new DefaultValueGenerator());
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("POST", "Form.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)));
}
Also used : DefaultValueGenerator(org.zaproxy.zap.model.DefaultValueGenerator) SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 53 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldParsePostFormWithoutSubmitField.

@Test
public void shouldParsePostFormWithoutSubmitField() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage msg = createMessageWith("POST", "FormNoSubmitField.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.getResourcesFound(), contains(postResource(msg, 1, "http://example.org/", "field1=Text+1&field2=Text+2")));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 54 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldUseMessageUrlAsActionIfFormHasNoAction.

@Test
public void shouldUseMessageUrlAsActionIfFormHasNoAction() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("NoActionForm.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/?field1=Text+1&field2=Text+2&submit=Submit"));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 55 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldIgnoreBaseHtmlIfActionIsAbsoluteWhenParsingPostForm.

@Test
public void shouldIgnoreBaseHtmlIfActionIsAbsoluteWhenParsingPostForm() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage msg = createMessageWith("POST", "FormWithHtmlBase.html", "https://example.com/search", "http://base.example.com/");
    Source source = createSource(msg);
    // When
    boolean completelyParsed = htmlParser.parseResource(msg, source, BASE_DEPTH);
    // Then
    assertThat(completelyParsed, is(equalTo(false)));
    assertThat(listener.getNumberOfResourcesFound(), is(equalTo(1)));
    assertThat(listener.getResourcesFound(), contains(postResource(msg, 1, "https://example.com/search", "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