Search in sources :

Example 46 with SpiderParam

use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldFindUrlsInScriptElements.

@Test
void shouldFindUrlsInScriptElements() {
    // Given
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("ScriptElementsSpiderHtmlParser.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://script.example.com/base/scheme", "http://script.example.com:8000/b", "https://script.example.com/c?a=b", "http://example.com/sample/script/relative", "http://example.com/sample/", "http://example.com/script/absolute", "ftp://script.example.com/"));
}
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 47 with SpiderParam

use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldUseMessageUriIfNoBaseElement.

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

Example 48 with SpiderParam

use of org.zaproxy.zap.spider.SpiderParam in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldFindUrlsInLinkElements.

@Test
void shouldFindUrlsInLinkElements() {
    // Given
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("LinkElementsSpiderHtmlParser.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://link.example.com/base/scheme", "http://link.example.com:8000/b", "https://link.example.com/c?a=b", "http://example.com/sample/link/relative", "http://example.com/sample/", "http://example.com/link/absolute", "ftp://link.example.com/"));
}
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 49 with SpiderParam

use of org.zaproxy.zap.spider.SpiderParam 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 50 with SpiderParam

use of org.zaproxy.zap.spider.SpiderParam 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)

Aggregations

SpiderParam (org.zaproxy.zap.spider.SpiderParam)55 Test (org.junit.jupiter.api.Test)48 HttpMessage (org.parosproxy.paros.network.HttpMessage)36 Source (net.htmlparser.jericho.Source)26 DefaultValueGenerator (org.zaproxy.zap.model.DefaultValueGenerator)5 ArrayList (java.util.ArrayList)2 OptionsParam (org.parosproxy.paros.model.OptionsParam)2 ResourceBundle (java.util.ResourceBundle)1 URI (org.apache.commons.httpclient.URI)1 ScannerParam (org.parosproxy.paros.core.scanner.ScannerParam)1 ConnectionParam (org.parosproxy.paros.network.ConnectionParam)1 AlertAPI (org.zaproxy.zap.extension.alert.AlertAPI)1 AntiCsrfAPI (org.zaproxy.zap.extension.anticsrf.AntiCsrfAPI)1 AntiCsrfParam (org.zaproxy.zap.extension.anticsrf.AntiCsrfParam)1 ActiveScanAPI (org.zaproxy.zap.extension.ascan.ActiveScanAPI)1 AuthenticationAPI (org.zaproxy.zap.extension.authentication.AuthenticationAPI)1 AuthorizationAPI (org.zaproxy.zap.extension.authorization.AuthorizationAPI)1 AutoUpdateAPI (org.zaproxy.zap.extension.autoupdate.AutoUpdateAPI)1 OptionsParamCheckForUpdates (org.zaproxy.zap.extension.autoupdate.OptionsParamCheckForUpdates)1 BreakAPI (org.zaproxy.zap.extension.brk.BreakAPI)1