Search in sources :

Example 96 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldSetValuesToFieldsWithNoValueWhenParsingGetForm.

@Test
void shouldSetValuesToFieldsWithNoValueWhenParsingGetForm() {
    // Given
    DefaultValueGenerator valueGenerator = new DefaultValueGenerator();
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser(valueGenerator);
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    Date date = new Date(1474370354555L);
    valueGenerator.setDefaultDate(date);
    HttpMessage msg = createMessageWith("GET", "FormNoDefaultValues.html");
    Source source = createSource(msg);
    // When
    boolean completelyParsed = htmlParser.parseResource(msg, source, BASE_DEPTH);
    // Then
    assertThat(completelyParsed, is(equalTo(false)));
    assertThat(listener.getNumberOfResourcesFound(), is(equalTo(8)));
    assertThat(listener.getUrlsFound(), contains("http://example.org/?_file=test_file.txt&_hidden&_no-type=ZAP&_password=ZAP&_text=ZAP&submit=Submit", "http://example.org/html5/number?_number=1&_number-max=2&_number-min=1&submit=Submit", "http://example.org/html5/range?_range=1&_range-max=4&_range-min=3&submit=Submit", "http://example.org/html5/misc?_color=%23ffffff&_email=foo-bar%40example.com&_tel=9999999999&_url=http%3A%2F%2Fwww.example.com&submit=Submit", "http://example.org/unknown?_unknown&submit=Submit", "http://example.org/selects?_select-one-option=first-option&_select-selected-option=selected-option&_select-two-options=last-option&submit=Submit", "http://example.org/checkbox?_checkbox=first-checkbox&submit=Submit", "http://example.org/html5/date-time?" + params(param("_date", formattedDate("yyyy-MM-dd", date)), param("_datetime", formattedDate("yyyy-MM-dd'T'HH:mm:ss'Z'", date)), param("_datetime-local", formattedDate("yyyy-MM-dd'T'HH:mm:ss", date)), param("_month", formattedDate("yyyy-MM", date)), param("_time", formattedDate("HH:mm:ss", date)), param("_week", formattedDate("yyyy-'W'ww", date)), param("submit", "Submit"))));
}
Also used : DefaultValueGenerator(org.zaproxy.zap.model.DefaultValueGenerator) HttpMessage(org.parosproxy.paros.network.HttpMessage) Date(java.util.Date) Source(net.htmlparser.jericho.Source) Test(org.junit.jupiter.api.Test)

Example 97 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldUseMessageUrlAsActionIfFormHasNoAction.

@Test
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.jupiter.api.Test)

Example 98 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldUseAbsolutePathBaseHtmlUrlWhenParsingGetFormWithRelativeAction.

@Test
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.jupiter.api.Test)

Example 99 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldRemoveFragmentFromActionWhenParsingGetForm.

@Test
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.jupiter.api.Test)

Example 100 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldNotParsePostFormIfPostFormProcessingIsDisabled.

@Test
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.jupiter.api.Test)

Aggregations

Source (net.htmlparser.jericho.Source)108 HttpMessage (org.parosproxy.paros.network.HttpMessage)87 Test (org.junit.jupiter.api.Test)84 SpiderParam (org.zaproxy.zap.spider.SpiderParam)26 Element (net.htmlparser.jericho.Element)16 DownloadService (delta.games.lotro.utils.DownloadService)11 URI (org.apache.commons.httpclient.URI)9 InputSource (org.xml.sax.InputSource)6 DefaultValueGenerator (org.zaproxy.zap.model.DefaultValueGenerator)6 HistoryReference (org.parosproxy.paros.model.HistoryReference)4 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Attribute (net.htmlparser.jericho.Attribute)2 OutputDocument (net.htmlparser.jericho.OutputDocument)2 DatabaseException (org.parosproxy.paros.db.DatabaseException)2 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)2 TemplateParserResult (com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult)1 KBArticle (com.liferay.knowledgebase.model.KBArticle)1