-
-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
soap: convert variant script to Java class
Convert the script into a Java class to no longer rely on the script engine, which is not available in newer Java versions. Fix zaproxy/zaproxy#6500. Signed-off-by: thc202 <[email protected]>
- Loading branch information
Showing
6 changed files
with
169 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
addOns/soap/src/main/java/org/zaproxy/zap/extension/soap/VariantSoap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2023 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.zap.extension.soap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.apache.commons.httpclient.URI; | ||
import org.apache.commons.httpclient.URIException; | ||
import org.parosproxy.paros.core.scanner.NameValuePair; | ||
import org.parosproxy.paros.core.scanner.Variant; | ||
import org.parosproxy.paros.network.HttpMessage; | ||
|
||
public class VariantSoap implements Variant { | ||
|
||
private static final String[] EMPTY_ARRAY = {}; | ||
|
||
@Override | ||
public void setMessage(HttpMessage msg) {} | ||
|
||
@Override | ||
public List<NameValuePair> getParamList() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public String setEscapedParameter( | ||
HttpMessage msg, NameValuePair originalPair, String param, String value) { | ||
return setParameter(msg, originalPair, param, value); | ||
} | ||
|
||
@Override | ||
public String setParameter( | ||
HttpMessage msg, NameValuePair originalPair, String param, String value) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<String> getTreePath(HttpMessage msg) throws URIException { | ||
String nodeName = SitesTreeHelper.getNodeName(msg); | ||
if (nodeName.isEmpty()) { | ||
// Not a SOAP message. | ||
return null; | ||
} | ||
|
||
URI uri = msg.getRequestHeader().getURI(); | ||
String[] path = uri.getRawPath() != null ? uri.getPath().split("/", 0) : EMPTY_ARRAY; | ||
List<String> list = new ArrayList<>(path.length); | ||
for (var i = 1; i < path.length; i++) { | ||
list.add(path[i]); | ||
} | ||
list.add(nodeName); | ||
|
||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
addOns/soap/src/main/zapHomeFiles/scripts/scripts/variant/SOAP Support.js
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
addOns/soap/src/test/java/org/zaproxy/zap/extension/soap/VariantSoapUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Zed Attack Proxy (ZAP) and its related class files. | ||
* | ||
* ZAP is an HTTP/HTTPS proxy for assessing web application security. | ||
* | ||
* Copyright 2023 The ZAP Development Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.zaproxy.zap.extension.soap; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.empty; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.List; | ||
import org.apache.commons.httpclient.URI; | ||
import org.apache.commons.httpclient.URIException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.parosproxy.paros.network.HttpMessage; | ||
|
||
/** Unit test for {@link VariantSoap}. */ | ||
class VariantSoapUnitTest { | ||
|
||
private HttpMessage msg; | ||
private VariantSoap variant; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
variant = new VariantSoap(); | ||
msg = new HttpMessage(); | ||
msg.getRequestHeader().setURI(new URI("http://www.example.org/temp", true)); | ||
msg.setRequestBody( | ||
"<?xml version=\"1.0\"?>\n" | ||
+ "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\">\n" | ||
+ "<soap:Body xmlns:m=\"http://www.example.org/temp\">\n" | ||
+ " <m:GetTemp>\n" | ||
+ " <m:Location>Sun</m:Location>\n" | ||
+ " </m:GetTemp>\n" | ||
+ "</soap:Body>\n" | ||
+ "</soap:Envelope>"); | ||
} | ||
|
||
@Test | ||
void shouldHaveNoParameters() { | ||
// Given / When | ||
variant.setMessage(msg); | ||
// Then | ||
assertThat(variant.getParamList(), is(empty())); | ||
} | ||
|
||
@Test | ||
void shouldUseDefaultLeafName() { | ||
// Given / When | ||
String leafName = variant.getLeafName("nodeName", msg); | ||
// Then | ||
assertThat(leafName, is(nullValue())); | ||
} | ||
|
||
@Test | ||
void shouldReturnTreePathForSoapMessage() throws URIException { | ||
// Given / When | ||
List<String> treePath = variant.getTreePath(msg); | ||
// Then | ||
assertThat(treePath, is(contains("temp", "GetTemp (v1.2)"))); | ||
} | ||
|
||
@Test | ||
void shouldReturnDefaultPathForNonSoapMessage() throws URIException { | ||
// Given | ||
msg = new HttpMessage(); | ||
// When | ||
List<String> treePath = variant.getTreePath(msg); | ||
// Then | ||
assertThat(treePath, is(nullValue())); | ||
} | ||
} |