Search in sources :

Example 86 with Source

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

the class SpiderHtmlParserUnitTest method shouldUseRelativePathBaseElement.

@Test
void shouldUseRelativePathBaseElement() {
    // Given
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("BaseWithRelativePathHrefAElementSpiderHtmlParser.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/a/base/relative/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.jupiter.api.Test)

Example 87 with Source

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

the class SpiderHtmlParserUnitTest method shouldFailToParseAnUndefinedMessage.

@Test
void shouldFailToParseAnUndefinedMessage() {
    // Given
    HttpMessage undefinedMessage = null;
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    Source source = createSource(createMessageWith("NoURLsSpiderHtmlParser.html"));
    // When / Then
    assertThrows(NullPointerException.class, () -> htmlParser.parseResource(undefinedMessage, source, BASE_DEPTH));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.jupiter.api.Test)

Example 88 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldParseSingleGetForm.

@Test
void shouldParseSingleGetForm() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("GET", "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(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 89 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldFailToParseAnUndefinedMessage.

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

Example 90 with Source

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

the class SpiderHtmlFormParserUnitTest method shouldParsePostFormWithoutSubmitField.

@Test
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.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