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;
}
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"));
}
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
}
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)));
}
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/"));
}
Aggregations