Search in sources :

Example 31 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method createMessageWith.

private static HttpMessage createMessageWith(String filename, String requestUri) {
    HttpMessage message = new HttpMessage();
    try {
        String fileContents = readFile(BASE_DIR_HTML_FILES.resolve(filename));
        message.setRequestHeader("GET " + requestUri + " HTTP/1.1\r\nHost: example.com\r\n");
        message.setResponseHeader("HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=UTF-8\r\n" + "Content-Length: " + fileContents.length());
        message.setResponseBody(fileContents);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return message;
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage)

Example 32 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldIgnoreBaseAndUseMessageUriIfBaseElementHaveEmptyHref.

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

Example 33 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldFailToEvaluateAnUndefinedMessage.

@Test(expected = NullPointerException.class)
public void shouldFailToEvaluateAnUndefinedMessage() {
    // Given
    HttpMessage undefinedMessage = null;
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    // When
    htmlParser.canParseResource(undefinedMessage, ROOT_PATH, false);
// Then = NullPointerException
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test)

Example 34 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldParseHtmlResponseEvenIfProvidedPathIsNull.

@Test
public void shouldParseHtmlResponseEvenIfProvidedPathIsNull() {
    // Given
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    HttpMessage messageHtmlResponse = createMessageWith("NoURLsSpiderHtmlParser.html");
    boolean parsed = false;
    // When
    boolean canParse = htmlParser.canParseResource(messageHtmlResponse, null, parsed);
    // Then
    assertThat(canParse, is(equalTo(true)));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test)

Example 35 with HttpMessage

use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.

the class SpiderHtmlParserUnitTest method shouldFindUrlsInIFrameElements.

@Test
public void shouldFindUrlsInIFrameElements() {
    // Given
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("IFrameElementsSpiderHtmlParser.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://iframe.example.com/base/scheme", "http://iframe.example.com:8000/b", "https://iframe.example.com/c?a=b", "http://example.com/sample/iframe/relative", "http://example.com/sample/", "http://example.com/iframe/absolute", "ftp://iframe.example.com/"));
}
Also used : SpiderParam(org.zaproxy.zap.spider.SpiderParam) HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Aggregations

HttpMessage (org.parosproxy.paros.network.HttpMessage)205 Test (org.junit.Test)144 Source (net.htmlparser.jericho.Source)73 SpiderParam (org.zaproxy.zap.spider.SpiderParam)29 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)22 DatabaseException (org.parosproxy.paros.db.DatabaseException)19 IOException (java.io.IOException)14 URI (org.apache.commons.httpclient.URI)10 URIException (org.apache.commons.httpclient.URIException)10 HttpException (org.apache.commons.httpclient.HttpException)7 HistoryReference (org.parosproxy.paros.model.HistoryReference)6 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)6 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)6 DefaultValueGenerator (org.zaproxy.zap.model.DefaultValueGenerator)6 SocketTimeoutException (java.net.SocketTimeoutException)5 RecordHistory (org.parosproxy.paros.db.RecordHistory)4 HttpResponseHeader (org.parosproxy.paros.network.HttpResponseHeader)4 File (java.io.File)3 SocketException (java.net.SocketException)3 UnknownHostException (java.net.UnknownHostException)3