Search in sources :

Example 26 with HttpMessage

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

the class SpiderTextParserUnitTest method shouldNeverConsiderCompletelyParsed.

@Test
public void shouldNeverConsiderCompletelyParsed() {
    // Given
    SpiderTextParser spiderParser = new SpiderTextParser();
    HttpMessage message = createMessageWith("Non Empty Body...");
    Source source = createSource(message);
    // When
    boolean completelyParsed = spiderParser.parseResource(message, source, BASE_DEPTH);
    // Then
    assertThat(completelyParsed, is(equalTo(false)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Source(net.htmlparser.jericho.Source) Test(org.junit.Test)

Example 27 with HttpMessage

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

the class SpiderTextParserUnitTest method shouldFailToEvaluateAnUndefinedMessage.

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

Example 28 with HttpMessage

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

the class UserUnitTest method shouldRequireAuthenticationAfterResetWithOlderMessage.

@Test
public void shouldRequireAuthenticationAfterResetWithOlderMessage() {
    // Given
    User u = spy(new User(CONTEXT_ID, USER_NAME));
    u.setAuthenticatedSession(Mockito.mock(WebSession.class));
    doReturn(3500l).when(u).getLastSuccessfulAuthTime();
    // When
    HttpMessage msg = Mockito.mock(HttpMessage.class);
    when(msg.getTimeSentMillis()).thenReturn(3200l);
    u.queueAuthentication(msg);
    // Then
    verify(msg).getTimeSentMillis();
    assertFalse(u.requiresAuthentication());
}
Also used : WebSession(org.zaproxy.zap.session.WebSession) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.Test)

Example 29 with HttpMessage

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

the class SpiderHtmlFormParserUnitTest method shouldParseFormAsGetIfNeitherGetNorPostForm.

@Test
public void shouldParseFormAsGetIfNeitherGetNorPostForm() {
    // Given
    SpiderHtmlFormParser htmlParser = createSpiderHtmlFormParser();
    TestSpiderParserListener listener = createTestSpiderParserListener();
    htmlParser.addSpiderParserListener(listener);
    HttpMessage messageHtmlResponse = createMessageWith("NonGetPostForm.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.Test)

Example 30 with HttpMessage

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

the class SpiderHtmlParserUnitTest method shouldParseMessageEvenWithoutSource.

@Test
public void shouldParseMessageEvenWithoutSource() {
    // Given
    Source source = null;
    SpiderHtmlParser htmlParser = new SpiderHtmlParser(new SpiderParam());
    HttpMessage messageHtmlResponse = createMessageWith("NoURLsSpiderHtmlParser.html");
    // When
    htmlParser.parseResource(messageHtmlResponse, source, BASE_DEPTH);
// Then = No exception
}
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