Search in sources :

Example 46 with HttpMessage

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

the class AbstractPluginUnitTest method isPage500ShouldReturnFalseIfNoStatusCodeOrCustomPageMatches.

@Test
void isPage500ShouldReturnFalseIfNoStatusCodeOrCustomPageMatches() {
    // Given
    CustomPage.Type type = CustomPage.Type.ERROR_500;
    HttpMessage message = new HttpMessage();
    message.getResponseHeader().setStatusCode(200);
    given(parent.isCustomPage(message, type)).willReturn(false);
    plugin.init(message, parent);
    // When
    boolean result = plugin.isPage500(message);
    // Then
    assertThat(result, is(equalTo(false)));
    verify(parent).isCustomPage(message, CustomPage.Type.OK_200);
    verify(parent).isCustomPage(message, CustomPage.Type.NOTFOUND_404);
    verify(parent).isCustomPage(message, type);
}
Also used : CustomPage(org.zaproxy.zap.extension.custompages.CustomPage) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with HttpMessage

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

the class AbstractPluginUnitTest method isClientErrorShouldReturnTrueIfStatusCodeMatches.

@Test
void isClientErrorShouldReturnTrueIfStatusCodeMatches() {
    // Given
    CustomPage.Type type = CustomPage.Type.NOTFOUND_404;
    HttpMessage message = new HttpMessage();
    message.getResponseHeader().setStatusCode(403);
    plugin.init(message, parent);
    given(parent.isCustomPage(message, type)).willReturn(false);
    given(parent.isCustomPage(message, CustomPage.Type.OK_200)).willReturn(false);
    given(parent.getAnalyser()).willReturn(analyser);
    given(parent.getAnalyser().isFileExist(message)).willReturn(false);
    // When
    boolean result = plugin.isClientError(message);
    // Then
    assertThat(result, is(equalTo(true)));
    verify(parent).isCustomPage(message, type);
    verify(parent).isCustomPage(message, CustomPage.Type.OK_200);
}
Also used : CustomPage(org.zaproxy.zap.extension.custompages.CustomPage) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with HttpMessage

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

the class AbstractPluginUnitTest method shouldRaiseAlertWith10ParamsBingoDefaultingToMessageUriWhenGivenUriIsEmpty.

@Test
@SuppressWarnings("deprecation")
void shouldRaiseAlertWith10ParamsBingoDefaultingToMessageUriWhenGivenUriIsEmpty() {
    // Given
    AbstractPlugin plugin = createDefaultPlugin();
    HostProcess hostProcess = mock(HostProcess.class);
    plugin.init(mock(HttpMessage.class), hostProcess);
    String uri = "";
    String messageUri = "http://example.com/";
    HttpMessage alertMessage = createAlertMessage(messageUri);
    // When
    plugin.bingo(Alert.RISK_LOW, Alert.CONFIDENCE_HIGH, "", "", uri, "", "", "", "", alertMessage);
    // Then
    Alert alert = getRaisedAlert(hostProcess);
    assertThat(alert.getUri(), is(equalTo(messageUri)));
}
Also used : HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with HttpMessage

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

the class AbstractPluginUnitTest method isPage500ShouldReturnFalseIfNoStatusCodeOrCustomPageMatchesButCustomPage200Does.

@Test
void isPage500ShouldReturnFalseIfNoStatusCodeOrCustomPageMatchesButCustomPage200Does() {
    // Given
    CustomPage.Type type = CustomPage.Type.ERROR_500;
    HttpMessage message = new HttpMessage();
    message.getResponseHeader().setStatusCode(302);
    given(parent.isCustomPage(message, type)).willReturn(false);
    given(parent.isCustomPage(message, CustomPage.Type.OK_200)).willReturn(true);
    plugin.init(message, parent);
    // When
    boolean result = plugin.isPage500(message);
    // Then
    assertThat(result, is(equalTo(false)));
    verify(parent).isCustomPage(message, CustomPage.Type.OK_200);
}
Also used : CustomPage(org.zaproxy.zap.extension.custompages.CustomPage) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with HttpMessage

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

the class AbstractPluginUnitTest method isSuccessShouldReturnTrueIfStatusCodeMatches.

@Test
void isSuccessShouldReturnTrueIfStatusCodeMatches() {
    // Given
    CustomPage.Type type = CustomPage.Type.NOTFOUND_404;
    HttpMessage message = new HttpMessage();
    message.getResponseHeader().setStatusCode(204);
    plugin.init(message, parent);
    given(parent.isCustomPage(message, CustomPage.Type.NOTFOUND_404)).willReturn(false);
    given(parent.isCustomPage(message, CustomPage.Type.ERROR_500)).willReturn(false);
    given(parent.isCustomPage(message, type)).willReturn(false);
    given(parent.getAnalyser()).willReturn(analyser);
    given(parent.getAnalyser().isFileExist(message)).willReturn(false);
    // When
    boolean result = plugin.isSuccess(message);
    // Then
    assertThat(result, is(equalTo(true)));
    verify(parent).isCustomPage(message, CustomPage.Type.NOTFOUND_404);
    verify(parent).isCustomPage(message, CustomPage.Type.ERROR_500);
    verify(parent).isCustomPage(message, type);
}
Also used : CustomPage(org.zaproxy.zap.extension.custompages.CustomPage) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpMessage (org.parosproxy.paros.network.HttpMessage)460 Test (org.junit.jupiter.api.Test)360 Source (net.htmlparser.jericho.Source)86 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)86 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)57 CustomPage (org.zaproxy.zap.extension.custompages.CustomPage)48 SpiderParam (org.zaproxy.zap.spider.SpiderParam)36 URI (org.apache.commons.httpclient.URI)34 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)32 IOException (java.io.IOException)26 DatabaseException (org.parosproxy.paros.db.DatabaseException)26 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)17 FilterResult (org.zaproxy.zap.spider.filters.ParseFilter.FilterResult)17 HistoryReference (org.parosproxy.paros.model.HistoryReference)14 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)14 AuthenticationState (org.zaproxy.zap.users.AuthenticationState)14 URIException (org.apache.commons.httpclient.URIException)13 User (org.zaproxy.zap.users.User)13 IHTTPSession (fi.iki.elonen.NanoHTTPD.IHTTPSession)11