use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlFormParserUnitTest method shouldRemoveFragmentFromActionWhenParsingGetForm.
@Test
public 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"));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlFormParserUnitTest method shouldNotParsePostFormIfPostFormProcessingIsDisabled.
@Test
public 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)));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlFormParserUnitTest method shouldParsePostFormWithoutSubmitField.
@Test
public 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")));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlFormParserUnitTest method shouldUseMessageUrlAsActionIfFormHasNoAction.
@Test
public 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"));
}
use of net.htmlparser.jericho.Source in project zaproxy by zaproxy.
the class SpiderHtmlFormParserUnitTest method shouldIgnoreBaseHtmlIfActionIsAbsoluteWhenParsingPostForm.
@Test
public void shouldIgnoreBaseHtmlIfActionIsAbsoluteWhenParsingPostForm() {
// Given
SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
TestSpiderParserListener listener = createTestSpiderParserListener();
htmlParser.addSpiderParserListener(listener);
HttpMessage msg = createMessageWith("POST", "FormWithHtmlBase.html", "https://example.com/search", "http://base.example.com/");
Source source = createSource(msg);
// When
boolean completelyParsed = htmlParser.parseResource(msg, source, BASE_DEPTH);
// Then
assertThat(completelyParsed, is(equalTo(false)));
assertThat(listener.getNumberOfResourcesFound(), is(equalTo(1)));
assertThat(listener.getResourcesFound(), contains(postResource(msg, 1, "https://example.com/search", "q=Search&submit=Submit")));
}
Aggregations