Search in sources :

Example 96 with HttpMessage

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

the class VariantAbstractQueryUnitTest method shouldUseInjectedNameEvenIfEqualToIndexedNameWhenSettingArrayParameter.

@Test
void shouldUseInjectedNameEvenIfEqualToIndexedNameWhenSettingArrayParameter() {
    // Given
    List<String> names = new ArrayList<>();
    VariantAbstractQuery variantAbstractQuery = new VariantAbstractQueryImpl() {

        @Override
        protected String getEscapedName(HttpMessage msg, String name) {
            names.add(name);
            return name;
        }
    };
    List<org.zaproxy.zap.model.NameValuePair> parameters = parameters(parameter("a[]", "b"));
    variantAbstractQuery.setParameters(NAME_VALUE_PAIR_TYPE, parameters);
    HttpMessage message = createMessage();
    // When
    variantAbstractQuery.setParameter(message, param("a[]", "b", 0), "a[0]", "z");
    // Then
    assertThat(names, contains("a[0]"));
}
Also used : ArrayList(java.util.ArrayList) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 97 with HttpMessage

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

the class VariantAbstractQueryUnitTest method shouldUseOriginalNamesForArraysWhenSettingParameter.

@Test
void shouldUseOriginalNamesForArraysWhenSettingParameter() {
    // Given
    List<String> names = new ArrayList<>();
    VariantAbstractQuery variantAbstractQuery = new VariantAbstractQueryImpl() {

        @Override
        protected String getEscapedName(HttpMessage msg, String name) {
            names.add(name);
            return name;
        }
    };
    List<org.zaproxy.zap.model.NameValuePair> parameters = parameters(parameter("a[]", "b"), parameter("a[]", "d"), parameter("e", "f"), parameter("g[]", "h"), parameter("i", "j"));
    variantAbstractQuery.setParameters(NAME_VALUE_PAIR_TYPE, parameters);
    HttpMessage message = createMessage();
    // When
    variantAbstractQuery.setParameter(message, param("e", "f", 2), "e", "f");
    // Then
    assertThat(names, contains("a[]", "a[]", "e", "g[]", "i"));
}
Also used : ArrayList(java.util.ArrayList) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 98 with HttpMessage

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

the class VariantAbstractQueryUnitTest method shouldCallBuildMessageWhenSettingParameter.

@Test
void shouldCallBuildMessageWhenSettingParameter() {
    // Given
    MutableBoolean buildMessageCalled = new MutableBoolean();
    VariantAbstractQuery variantAbstractQuery = new VariantAbstractQueryImpl() {

        @Override
        protected void buildMessage(HttpMessage msg, String query) {
            buildMessageCalled.setValue(true);
        }
    };
    List<org.zaproxy.zap.model.NameValuePair> parameters = parameters(parameter("a", "b"), parameter("c", "d"));
    variantAbstractQuery.setParameters(NAME_VALUE_PAIR_TYPE, parameters);
    HttpMessage message = createMessage();
    // When
    variantAbstractQuery.setParameter(message, param("a", "b", 0), "y", "z");
    // Then
    assertTrue(buildMessageCalled.isTrue());
}
Also used : MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 99 with HttpMessage

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

the class VariantCustomUnitTest method shouldReturnNullLeafNameWithDisabledScript.

@Test
void shouldReturnNullLeafNameWithDisabledScript() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.isEnabled()).willReturn(false);
    String nodeName = "name";
    String expectedName = "newname";
    ExtensionScript extScript = mock(ExtensionScript.class);
    VariantScript variantScript = mock(VariantScript.class);
    given(extScript.getInterface(scriptWrapper, VariantScript.class)).willReturn(variantScript);
    VariantCustom variantCustom = new VariantCustom(scriptWrapper, extScript);
    HttpMessage msg = mock(HttpMessage.class);
    given(variantScript.getLeafName(variantCustom, nodeName, msg)).willReturn(expectedName);
    // When
    String name = variantCustom.getLeafName(nodeName, msg);
    // Then
    assertThat(name, is(equalTo(null)));
}
Also used : ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 100 with HttpMessage

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

the class VariantCustomUnitTest method shouldReturnNullTreePathWithScriptException.

@Test
void shouldReturnNullTreePathWithScriptException() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    String expectedPath = "newpath";
    List<String> list = new ArrayList<>();
    list.add(expectedPath);
    ExtensionScript extScript = mock(ExtensionScript.class);
    VariantScript variantScript = mock(VariantScript.class);
    given(extScript.getInterface(scriptWrapper, VariantScript.class)).willReturn(variantScript);
    VariantCustom variantCustom = new VariantCustom(scriptWrapper, extScript);
    HttpMessage msg = mock(HttpMessage.class);
    given(variantScript.getTreePath(variantCustom, msg)).willThrow(RuntimeException.class);
    // When
    List<String> path = variantCustom.getTreePath(msg);
    // Then
    assertThat(path, is(equalTo(null)));
}
Also used : ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) ScriptWrapper(org.zaproxy.zap.extension.script.ScriptWrapper) ArrayList(java.util.ArrayList) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test)

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