Skip to content

Commit

Permalink
Update Gradle and plugins
Browse files Browse the repository at this point in the history
Update Gradle Wrapper to 8.2.1, plugins, and build.
Update ZAP API client and dependencies.
Address deprecations with newer Java version and Selenium.
Apply new formatting, required for newer Java versions.

Signed-off-by: thc202 <thc202@gmail.com>
  • Loading branch information
thc202 committed Jul 25, 2023
1 parent 899793e commit 3c92945
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 38 deletions.
31 changes: 17 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.gradle.node.npm.task.NpmTask
import org.zaproxy.gradle.addon.AddOnPlugin
import org.zaproxy.gradle.addon.AddOnStatus
import org.zaproxy.gradle.addon.internal.model.ProjectInfo
import org.zaproxy.gradle.addon.internal.model.ReleaseState
Expand All @@ -14,11 +15,11 @@ import org.zaproxy.gradle.tasks.ZapStart
plugins {
`java-library`
jacoco
id("org.zaproxy.add-on") version "0.8.0"
id("org.zaproxy.add-on") version "0.9.0"
id("org.zaproxy.crowdin") version "0.3.1"
id("com.diffplug.spotless") version "6.14.1"
id("com.github.ben-manes.versions") version "0.45.0"
id("com.github.node-gradle.node") version "3.5.1"
id("com.diffplug.spotless") version "6.20.0"
id("com.github.ben-manes.versions") version "0.47.0"
id("com.github.node-gradle.node") version "5.0.0"
}

apply(from = "$rootDir/gradle/compile.gradle.kts")
Expand Down Expand Up @@ -127,26 +128,28 @@ val generateI18nJsFile by tasks.creating(GenerateI18nJsFile::class) {

sourceSets["main"].output.dir(generatedI18nJsFileDir, "builtBy" to generateI18nJsFile)

tasks.named(AddOnPlugin.GENERATE_MANIFEST_TASK_NAME) {
dependsOn(copyNpmDeps)
dependsOn(generateI18nJsFile)
}

java {
val javaVersion = JavaVersion.VERSION_11
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

val jupiterVersion = "5.9.2"

dependencies {
compileOnly("org.zaproxy.addon:network:0.1.0")
compileOnly(files(fileTree("lib").files))

testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

testImplementation("io.github.bonigarcia:selenium-jupiter:4.3.2")
testImplementation("org.seleniumhq.selenium:selenium-java:4.7.2")
testImplementation("io.github.bonigarcia:selenium-jupiter:4.3.6")
testImplementation("org.seleniumhq.selenium:selenium-java:4.10.0")
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("org.mockito:mockito-all:1.10.19")
testImplementation("org.mockito:mockito-core:5.4.0")
testImplementation("org.zaproxy.addon:network:0.1.0")
testImplementation(files(fileTree("lib").files))
}
Expand Down Expand Up @@ -175,7 +178,7 @@ spotless {
java {
licenseHeaderFile("gradle/spotless/license.java")

googleJavaFormat("1.7").aosp()
googleJavaFormat("1.17.0").aosp()
}

kotlinGradle {
Expand Down Expand Up @@ -248,7 +251,7 @@ tasks {

doLast {
copy {
from(zipTree(fileTree(zapDownloadDir.asFile).matching { "*.zip" }.singleFile)).eachFile {
from(zipTree(fileTree(zapDownloadDir.asFile).matching { include("*.zip") }.singleFile)).eachFile {
path = path.substring(relativePath.segments[0].length)
}
into(zapInstallDir)
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`java-gradle-plugin`
id("com.diffplug.spotless") version "6.14.1"
id("com.diffplug.spotless") version "6.20.0"
}

apply(from = "../gradle/compile.gradle.kts")
Expand All @@ -11,7 +11,7 @@ repositories {

dependencies {
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("org.zaproxy:zap-clientapi:1.11.0")
implementation("org.zaproxy:zap-clientapi:1.12.0")
}

java {
Expand All @@ -24,7 +24,7 @@ spotless {
java {
licenseHeaderFile("../gradle/spotless/license.java")

googleJavaFormat("1.7").aosp()
googleJavaFormat("1.17.0").aosp()
}

kotlinGradle {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=312eb12875e1747e05c2f81a4789902d7e4ec5defbd1eefeaccc08acf096505d
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionSha256Sum=7c3ad722e9b0ce8205b91560fd6ce8296ac3eadf065672242fd73c06b8eeb6ee
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 10 additions & 6 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,26 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ protected String setRecordedRequest(HttpMessage request) throws URIException {
return reqUrl;
}

/** @return index of pattern in s or -1, if not found */
/**
* @return index of pattern in s or -1, if not found
*/
public static int regexEndOf(Pattern pattern, String s) {
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.end() : -1;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/zaproxy/zap/extension/hud/HudAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public class HudAPI extends ApiImplementor {
* real shared secret
*/
public static final String SHARED_TEST_NON_SECRET = "TEST_MODE";

/**
* Shared secret used to ensure that we only accept messages from the ZAP code running on the
* target domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Constants {
public static int ZAP_PORT = 8999;
public static String ZAP_HOST = "localhost";
public static String ZAP_HOST_PORT = ZAP_HOST + ":" + ZAP_PORT;

/** This key is set in /build.gradle.kts - these must be kept the same */
public static String ZAP_TEST_API_KEY = "password123";
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class BrowsersTest {
@Options
private static final FirefoxOptions FIREFOX_OPTIONS =
new FirefoxOptions()
.setHeadless(true)
.addArguments("-headless")
.setAcceptInsecureCerts(true)
.addPreference("network.captive-portal-service.enabled", false)
.addPreference("browser.safebrowsing.provider.mozilla.gethashURL", "")
Expand All @@ -55,10 +55,11 @@ public abstract class BrowsersTest {
private static final ChromeOptions CHROME_OPTIONS =
(ChromeOptions)
new ChromeOptions()
.setHeadless(true)
.setAcceptInsecureCerts(true)
.addArguments(
"--proxy-bypass-list=<-loopback>", "--window-size=1024,768")
"--proxy-bypass-list=<-loopback>",
"--window-size=1024,768",
"--headless=new")
.setProxy(PROXY);

@RegisterExtension SeleniumJupiter seleniumJupiter = new SeleniumJupiter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -91,8 +90,7 @@ public void checkServerTrusted(
}

@TestTemplate
public void cannotAccessWebSocketsUrlWhenLoadingSwAsScript(WebDriver driver)
throws MalformedURLException {
public void cannotAccessWebSocketsUrlWhenLoadingSwAsScript(WebDriver driver) throws Exception {
HUD hud = new HUD(driver);
hud.openUrlWaitForHud(TutorialStatics.getTutorialUrl(IntroPage.NAME));
String swUrl = getHudFilesUrl(hud) + SERVICE_WORKER;
Expand Down Expand Up @@ -168,9 +166,9 @@ private static Object executeScriptWithRetry(WebDriver driver, String script) {
*
* @param driver
* @return
* @throws MalformedURLException
* @throws Exception
*/
private String getHudFilesUrl(HUD hud) throws MalformedURLException {
private static String getHudFilesUrl(HUD hud) throws Exception {
if (filesUrl == null) {
hud.openUrlWaitForHud(TutorialStatics.getTutorialUrl(IntroPage.NAME));
// Get hold of the API URL
Expand All @@ -182,7 +180,7 @@ private String getHudFilesUrl(HUD hud) throws MalformedURLException {
str = str.substring(str.lastIndexOf("https://"));
// Sanity check its a valid URL
assertTrue(str.length() > 0);
new URL(str);
new URI(str).toURL();
filesUrl = str;

hud.getWebDriver().switchTo().parentFrame();
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/zaproxy/zap/extension/hud/ui/uimap/HUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Date;
Expand Down Expand Up @@ -207,9 +206,11 @@ public static JSONObject callZapApi(String apiCall) throws MalformedURLException
+ "="
+ Constants.ZAP_TEST_API_KEY;

try (InputStream in = new URL(apiUrl).openStream()) {
try (InputStream in = new URI(apiUrl).toURL().openStream()) {
String str = IOUtils.toString(in, "UTF-8");
return JSONObject.fromObject(str);
} catch (URISyntaxException e) {
throw new MalformedURLException(e.getMessage());
}
}

Expand Down

0 comments on commit 3c92945

Please sign in to comment.