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