Search in sources :

Example 6 with ExtensionScript

use of org.zaproxy.zap.extension.script.ExtensionScript 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)

Example 7 with ExtensionScript

use of org.zaproxy.zap.extension.script.ExtensionScript in project zaproxy by zaproxy.

the class VariantCustomUnitTest method shouldCallScriptForGetLeafName.

@Test
void shouldCallScriptForGetLeafName() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.isEnabled()).willReturn(true);
    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(expectedName)));
}
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 8 with ExtensionScript

use of org.zaproxy.zap.extension.script.ExtensionScript in project zaproxy by zaproxy.

the class ScriptsActiveScannerUnitTest method setUp.

@BeforeEach
void setUp() throws Exception {
    extensionScript = mock(ExtensionScript.class);
    parent = mock(HostProcess.class);
    message = new HttpMessage(new HttpRequestHeader("GET / HTTP/1.1"));
    given(extensionLoader.getExtension(ExtensionScript.class)).willReturn(extensionScript);
}
Also used : HostProcess(org.parosproxy.paros.core.scanner.HostProcess) ExtensionScript(org.zaproxy.zap.extension.script.ExtensionScript) HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ExtensionScript

use of org.zaproxy.zap.extension.script.ExtensionScript in project zaproxy by zaproxy.

the class VariantCustomUnitTest method shouldCallScriptForGetTreePath.

@Test
void shouldCallScriptForGetTreePath() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.isEnabled()).willReturn(true);
    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)).willReturn(list);
    // When
    List<String> path = variantCustom.getTreePath(msg);
    // Then
    assertThat(path.size(), is(equalTo(1)));
    assertThat(path.get(0), is(equalTo(expectedPath)));
}
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)

Example 10 with ExtensionScript

use of org.zaproxy.zap.extension.script.ExtensionScript in project zaproxy by zaproxy.

the class VariantCustomUnitTest method shouldReturnNullTreePathWithDisabledScript.

@Test
void shouldReturnNullTreePathWithDisabledScript() throws Exception {
    // Given
    ScriptWrapper scriptWrapper = mock(ScriptWrapper.class);
    given(scriptWrapper.isEnabled()).willReturn(false);
    List<String> list = new ArrayList<>();
    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)).willReturn(list);
    // 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

ExtensionScript (org.zaproxy.zap.extension.script.ExtensionScript)11 HttpMessage (org.parosproxy.paros.network.HttpMessage)8 Test (org.junit.jupiter.api.Test)6 ScriptWrapper (org.zaproxy.zap.extension.script.ScriptWrapper)6 ArrayList (java.util.ArrayList)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ScriptType (org.zaproxy.zap.extension.script.ScriptType)2 Source (net.htmlparser.jericho.Source)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 HostProcess (org.parosproxy.paros.core.scanner.HostProcess)1 HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)1 ExtensionAlert (org.zaproxy.zap.extension.alert.ExtensionAlert)1