Skip to content

Commit

Permalink
Merge branch 'development-1.1.0' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanGS committed Jul 10, 2017
2 parents 0a78cc9 + b196d9e commit 0faf689
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 152 deletions.
28 changes: 12 additions & 16 deletions src/main/java/org/jenkinsci/plugins/zap/ZAPBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
if (zapHost == null || zapHost.isEmpty()) throw new IllegalArgumentException("ZAP HOST IS MISSING");
String zapPort = zaproxy.getZapPort();
if (zapPort == null || zapPort.isEmpty()) throw new IllegalArgumentException("ZAP PORT IS MISSING");
String zapSettingsDir = zaproxy.getZapSettingsDir();
String sessionFilename = zaproxy.getSessionFilename();
String internalSites = zaproxy.getInternalSites();
String contextName = zaproxy.getContextName();
Expand All @@ -147,7 +146,6 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
try {
zapHost = applyMacro(build, listener, zapHost);
zapPort = applyMacro(build, listener, zapPort);
zapSettingsDir = applyMacro(build, listener, zapSettingsDir);
sessionFilename = applyMacro(build, listener, sessionFilename);
internalSites = applyMacro(build, listener, internalSites);
contextName = applyMacro(build, listener, contextName);
Expand All @@ -165,7 +163,6 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {

zaproxy.setEvaluatedZapHost(zapHost);
zaproxy.setEvaluatedZapPort(Integer.valueOf(zapPort));
zaproxy.setEvaluatedZapSettingsDir(zapSettingsDir);
zaproxy.setEvaluatedSessionFilename(sessionFilename);
zaproxy.setEvaluatedInternalSites(internalSites);
zaproxy.setEvaluatedContextName(contextName);
Expand All @@ -179,7 +176,6 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
Utils.loggerMessage(listener, 1, "HOST = [ {0} ]", zapHost);
Utils.loggerMessage(listener, 1, "PORT = [ {0} ]", zapPort);
Utils.lineBreak(listener);
Utils.loggerMessage(listener, 1, "ZAP SETTINGS DIRECTORY = [ {0} ]", zapSettingsDir);
Utils.loggerMessage(listener, 1, "SESSION FILENAME = [ {0} ]", sessionFilename);
Utils.loggerMessage(listener, 1, "INTERNAL SITES = [ {0} ]", internalSites.trim().replace("\n", ", "));
Utils.lineBreak(listener);
Expand All @@ -199,17 +195,17 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
Utils.loggerMessage(listener, 0, "[{0}] END PRE-BUILD ENVIRONMENT VARIABLE REPLACEMENT", Utils.ZAP);
Utils.lineBreak(listener);

/* Clear the ZAP Settings folder of all previous zap logs. */
/* Clear the ZAP home directory of all previous zap logs. */
Utils.loggerMessage(listener, 0, "[{0}] CLEAR LOGS IN SETTINGS...", Utils.ZAP);
Utils.loggerMessage(listener, 1, "SETTINGS DIR [ {0} ]", this.zaproxy.getEvaluatedZapSettingsDir());
Utils.loggerMessage(listener, 1, "WORKSPACE [ {0} ]", build.getWorkspace().getRemote());
Utils.loggerMessage(listener, 1, "ZAP HOME DIRECTORY [ {0} ]", this.zaproxy.getZapSettingsDir());
Utils.loggerMessage(listener, 1, "JENKINS WORKSPACE [ {0} ]", build.getWorkspace().getRemote());

/* No workspace before the first build, so workspace is null. */
FilePath ws = build.getWorkspace();
if (ws != null) {
File[] listFiles = {};
try {
listFiles = ws.act(new LogCallable(this.zaproxy.getEvaluatedZapSettingsDir()));
listFiles = ws.act(new LogCallable(this.zaproxy.getZapSettingsDir()));
}
catch (IOException e) {
e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
Expand All @@ -218,7 +214,7 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
}

Utils.loggerMessage(listener, 1, "CLEARING SETTINGS/{0}", ZAPDriver.NAME_LOG_DIR.toUpperCase());
Utils.loggerMessage(listener, 1, "CLEARING ZAP HOME DIRECTORY/{0}", ZAPDriver.NAME_LOG_DIR.toUpperCase());
Utils.lineBreak(listener);

for (File listFile : listFiles) {
Expand Down Expand Up @@ -300,17 +296,17 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
Utils.loggerMessage(listener, 0, "[{0}] SHUTDOWN [ SUCCESSFUL ]", Utils.ZAP);
Utils.lineBreak(listener);

/* Upon ZAP successfully shutting down, copy the files from the ZAP settings directory into the workspace folder. */
/* Upon ZAP successfully shutting down, copy the files from the ZAP home directory into the workspace folder. */
Utils.loggerMessage(listener, 0, "[{0}] LOG SEARCH...", Utils.ZAP);
Utils.loggerMessage(listener, 1, "SETTINGS DIR [ {0} ]", this.zaproxy.getEvaluatedZapSettingsDir());
Utils.loggerMessage(listener, 1, "WORKSPACE [ {0} ]", build.getWorkspace().getRemote());
Utils.loggerMessage(listener, 1, "ZAP HOME DIRECTORY [ {0} ]", this.zaproxy.getZapSettingsDir());
Utils.loggerMessage(listener, 1, "JENKINS WORKSPACE [ {0} ]", build.getWorkspace().getRemote());

/* No workspace before the first build, so workspace is null. */
FilePath ws = build.getWorkspace();
if (ws != null) {
File[] listFiles = {};
try {
listFiles = ws.act(new LogCallable(this.zaproxy.getEvaluatedZapSettingsDir()));
listFiles = ws.act(new LogCallable(this.zaproxy.getZapSettingsDir()));
}
catch (IOException e) {
e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
Expand Down Expand Up @@ -387,7 +383,7 @@ public static final class ZAPBuilderDescriptorImpl extends BuildStepDescriptor<B

/* This human readable name is used in the configuration screen. */
@Override
public String getDisplayName() { return "Execute ZAP"; }
public String getDisplayName() { return Messages.jenkins_jobconfig_addbuildstep_zap(); }

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
Expand Down Expand Up @@ -456,7 +452,7 @@ public void checkRoles(RoleChecker checker) throws SecurityException { /* N/A */
}

/**
* This class allows to search all ZAP log files in the ZAP settings directory of the remote machine (or local machine if there is no remote machine). Returns a list of logs.
* This class allows to search all ZAP log files in the ZAP home directory of the remote machine (or local machine if there is no remote machine). Returns a list of logs.
*/
private static class LogCallable implements FileCallable<File[]> {

Expand Down Expand Up @@ -494,7 +490,7 @@ public void checkRoles(RoleChecker checker) throws SecurityException { /* N/A */
}

/**
* Allows to copy a log file from the ZAP settings directory into the job's workspace.
* Allows to copy a log file from the ZAP home directory into the job's workspace.
*/
private static class CopyFileCallable implements FileCallable<String> {
private static final long serialVersionUID = 1L;
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/org/jenkinsci/plugins/zap/ZAPDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public ZAPDriver(boolean autoInstall, String toolUsed, String zapHome, String jd
@Override
public String toString() {
String s = "";
s += "\n";
s += "\n";
s += "Admin Configurations\n";
s += "-------------------------------------------------------\n";
s += "zapHost [" + zapHost + "]\n";
Expand All @@ -307,7 +309,7 @@ public String toString() {
s += "jdk [" + jdk + "]\n";
s += "timeout [" + timeout + "]\n";
s += "\n";
s += "ZAP Settings\n";
s += "ZAP Home Directory\n";
s += "-------------------------------------------------------\n";
s += "zapSettingsDir [" + zapSettingsDir + "]\n";
s += "\n";
Expand Down Expand Up @@ -505,8 +507,8 @@ private void checkParams(AbstractBuild<?, ?> build, BuildListener listener) thro
zapProgram = retrieveZapHomeWithToolInstall(build, listener);
Utils.loggerMessage(listener, 0, "[{0}] PLUGIN VALIDATION (PLG), VARIABLE VALIDATION AND ENVIRONMENT INJECTOR EXPANSION (EXP)", Utils.ZAP);

if (this.zapProgram == null || this.zapProgram.isEmpty()) throw new IllegalArgumentException("ZAP PATH IS MISSING, PROVIDED [ " + this.zapProgram + " ]");
else Utils.loggerMessage(listener, 1, "ZAP PATH = [ {0} ]", this.zapProgram);
if (this.zapProgram == null || this.zapProgram.isEmpty()) throw new IllegalArgumentException("ZAP INSTALLATION DIRECTORY IS MISSING, PROVIDED [ " + this.zapProgram + " ]");
else Utils.loggerMessage(listener, 1, "ZAP INSTALLATION DIRECTORY = [ {0} ]", this.zapProgram);

/* System Environment and Build Environment variables will be expanded already, the following step will expand Environment Injector variables. Note: cannot be expanded in pre-build step. */
EnvVars envVars = build.getEnvironment(listener);
Expand All @@ -523,7 +525,7 @@ private void checkParams(AbstractBuild<?, ?> build, BuildListener listener) thro
this.evaluatedInternalSites = envVars.expand(this.evaluatedInternalSites);
if (this.startZAPFirst) {
if (!this.autoLoadSession) {
if (this.evaluatedSessionFilename == null || this.evaluatedSessionFilename.isEmpty()) throw new IllegalArgumentException("SESSION FILENAME IS MISSING, PROVIDED [ " + this.evaluatedZapSettingsDir + " ]");
if (this.evaluatedSessionFilename == null || this.evaluatedSessionFilename.isEmpty()) throw new IllegalArgumentException("SESSION FILENAME IS MISSING, PROVIDED [ " + this.evaluatedSessionFilename + " ]");
else Utils.loggerMessage(listener, 1, "(EXP) SESSION FILENAME = [ {0} ]", this.evaluatedSessionFilename);

if (this.removeExternalSites) {
Expand All @@ -540,10 +542,6 @@ private void checkParams(AbstractBuild<?, ?> build, BuildListener listener) thro
}
}

this.evaluatedZapSettingsDir = envVars.expand(this.evaluatedZapSettingsDir);
if (this.evaluatedZapSettingsDir == null || this.evaluatedZapSettingsDir.isEmpty()) throw new IllegalArgumentException("ZAP SETTINGS DIRECTORY IS MISSING, PROVIDED [ " + this.evaluatedZapSettingsDir + " ]");
else Utils.loggerMessage(listener, 1, "(EXP) ZAP SETTINGS DIRECTORY = [ {0} ]", this.evaluatedZapSettingsDir);

this.evaluatedContextName = envVars.expand(this.evaluatedContextName);
if (this.evaluatedContextName == null || this.evaluatedContextName.isEmpty()) this.evaluatedContextName = "Jenkins Default Context";
else Utils.loggerMessage(listener, 1, "(EXP) CONTEXT NAME = [ {0} ]", this.evaluatedContextName);
Expand Down Expand Up @@ -634,9 +632,9 @@ public Proc startZAP(AbstractBuild<?, ?> build, BuildListener listener, Launcher
cmd.add(CMD_LINE_API_KEY + "=" + API_KEY);

/* Set the default directory used by ZAP if it's defined and if a scan is provided */
if (this.activeScanURL && this.evaluatedZapSettingsDir != null && !this.evaluatedZapSettingsDir.isEmpty()) {
if (this.activeScanURL && this.zapSettingsDir != null && !this.zapSettingsDir.isEmpty()) {
cmd.add(CMD_LINE_DIR);
cmd.add(this.evaluatedZapSettingsDir);
cmd.add(this.zapSettingsDir);
}

/* Adds command line arguments if it's provided */
Expand Down Expand Up @@ -987,8 +985,8 @@ private void jiraCreate(BuildListener listener, ClientApi clientApi, String jira
map.put("jiraBaseURL", jiraBaseURL);
map.put("jiraUserName", jiraUsername);
map.put("jiraPassword", jiraPassword);
map.put("jiraProjectKey", jiraProjectKey);
map.put("jiraAssignee", jiraAssignee);
map.put("projectKey", jiraProjectKey);
map.put("assignee", jiraAssignee);
map.put("high", returnCheckedStatus(jiraAlertHigh));
map.put("medium", returnCheckedStatus(jiraAlertMedium));
map.put("low", returnCheckedStatus(jiraAlertLow));
Expand Down Expand Up @@ -1097,7 +1095,7 @@ public boolean executeZAP(BuildListener listener, FilePath workspace) {
if (workspace != null) {
File[] listFiles = {};
try {
listFiles = workspace.act(new PluginCallable(this.evaluatedZapSettingsDir));
listFiles = workspace.act(new PluginCallable(this.zapSettingsDir));
}
catch (IOException e) {
e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */
Expand Down Expand Up @@ -2807,7 +2805,7 @@ private void getAvailableFormats(ZAPDriverDescriptorImpl zapDriver) {

public String getToolUsed() { return toolUsed; }

private final String zapHome; /* Environment variable for the ZAP path. */
private final String zapHome; /* Environment variable for the ZAP Installation Directory. */

public String getZapHome() { return zapHome; }

Expand All @@ -2825,12 +2823,6 @@ private void getAvailableFormats(ZAPDriverDescriptorImpl zapDriver) {

public String getZapSettingsDir() { return zapSettingsDir; }

private String evaluatedZapSettingsDir; /* Todo */

public String getEvaluatedZapSettingsDir() { return evaluatedZapSettingsDir; }

public void setEvaluatedZapSettingsDir(String evaluatedZapSettingsDir) { this.evaluatedZapSettingsDir = evaluatedZapSettingsDir; }

/* Session Management */
private final boolean autoLoadSession; /* Todo */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jenkins.jobconfig.addbuildstep.zap=Execute ZAP
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ SOFTWARE.

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry help="/descriptor/com.github.jenkinsci.zaproxyplugin.ZAPAuthScriptParam/help/config">
<f:entry help="/descriptor/org.jenkinsci.plugins.zap.ZAPAuthScriptParam/help/config">
<table width="100%">
<tr>
<th>${%Script Parameter Name}</th>
<th>${%Script Parameter Value}</th>
<th>${%jenkins.jobconfig.zap.session.properties.context.authentication.script-based.nameparam.textbox.label}</th>
<th>${%jenkins.jobconfig.zap.session.properties.context.authentication.script-based.valueparam.textbox.label}</th>
</tr>
<tr>
<td><f:textbox field="scriptParameterName"/></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jenkins.jobconfig.zap.session.properties.context.authentication.script-based.nameparam.textbox.label=Script Parameter Name
jenkins.jobconfig.zap.session.properties.context.authentication.script-based.valueparam.textbox.label=Script Parameter Value
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<!-- This jelly script is used for per-project configuration. See global.jelly for a general discussion about jelly script. -->

<f:section title="${%Admin Configurations}">
<f:entry title="${%Workspace}">
<f:section title="${%jenkins.jobconfig.zap.defaultoverride.section.label}">
<f:entry title="${%jenkins.jobconfig.zap.workspace.label}">
${it.workspace}
</f:entry>

<f:entry title=""></f:entry>

<f:entry title="${%Override Host}" field="zapHost" description="Default Host is : ${descriptor.zapDefaultHost} (${%Configured under 'Manage Jenkins' > 'Configure System'})">
<f:entry title="${%jenkins.jobconfig.zap.defaultoverride.host.textbox.label}" field="zapHost" description="${%jenkins.jobconfig.zap.defaultoverride.host.textbox.description(descriptor.zapDefaultHost)}">
<f:textbox clazz="required" default="${descriptor.zapDefaultHost}" />
</f:entry>

<f:entry title="${%Override Port}" field="zapPort" description="Default Port is : ${descriptor.zapDefaultPort} (${%Configured under 'Manage Jenkins' > 'Configure System'})">
<f:entry title="${%jenkins.jobconfig.zap.defaultoverride.port.textbox.label}" field="zapPort" description="${%jenkins.jobconfig.zap.defaultoverride.port.textbox.description(descriptor.zapDefaultPort)}">
<f:textbox default="${descriptor.zapDefaultPort}" clazz="required" />
</f:entry>
</f:section>

<f:section title="${%Startup}" />
<f:optionalBlock title="${%Run as Pre-Build Step}" field="startZAPFirst" inline="true" />
<f:section title="${%jenkins.jobconfig.zap.startup.section.label}" />
<f:optionalBlock title="${%jenkins.jobconfig.zap.startup.selenium.checkbox.label}" field="startZAPFirst" inline="true" />
<!-- Load the config.jelly bind to ZAPDriver class. This code doesn't work : <st:include page="config.jelly" class="com.github.jenkinsci.zaproxyplugin.ZAPDriver"/>. It doesn't create an ZAPDriver. Use f:property instead. -->
<f:property field="zaproxy" />
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jenkins.jobconfig.zap.defaultoverride.section.label=Admin Configurations
jenkins.jobconfig.zap.workspace.label=Workspace
jenkins.jobconfig.zap.defaultoverride.host.textbox.label=Override Host
jenkins.jobconfig.zap.defaultoverride.host.textbox.description=Default Host is : {0} (Configured under 'Manage Jenkins' > 'Configure System')
jenkins.jobconfig.zap.defaultoverride.port.textbox.label=Override Port
jenkins.jobconfig.zap.defaultoverride.port.textbox.description=Default Port is : {0} (Configured under 'Manage Jenkins' > 'Configure System')
jenkins.jobconfig.zap.startup.section.label=Startup
jenkins.jobconfig.zap.startup.selenium.checkbox.label=Run as Pre-Build Step
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ SOFTWARE.
tags they use. Views are always organized according to its owner class,
so it should be straightforward to find them.
-->
<f:section title="ZAP">
<f:entry title="${%Default Host}" field="zapDefaultHost">
<f:section title="${%jenkins.systemconfig.zap.default.section.label}">
<f:entry title="${%jenkins.systemconfig.zap.default.host.textbox.label}" field="zapDefaultHost">
<f:textbox default="localhost" clazz="required" />
</f:entry>

<f:entry title="${%Default Port}" field="zapDefaultPort">
<f:entry title="${%jenkins.systemconfig.zap.default.port.textbox.label}" field="zapDefaultPort">
<f:textbox default="8090" clazz="required" />
</f:entry>
</f:section>
<f:section title="ZAP JIRA">
<f:entry title="${%JIRA Base Url}" field="jiraBaseURL">
<f:section title="${%jenkins.systemconfig.zap.jira.section.label}">
<f:entry title="${%jenkins.systemconfig.zap.jira.baseurl.textbox.label}" field="jiraBaseURL">
<f:textbox default="" />
</f:entry>

<f:entry title="${%Username}" field="jiraUsername">
<f:entry title="${%jenkins.systemconfig.zap.jira.username.textbox.label}" field="jiraUsername">
<f:textbox default="" />
</f:entry>

<f:entry title="${%Password}" field="jiraPassword">
<f:entry title="${%jenkins.systemconfig.zap.jira.password.textbox.label}" field="jiraPassword">
<f:password default="" />
</f:entry>
</f:section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
jenkins.systemconfig.zap.default.section.label=ZAP
jenkins.systemconfig.zap.default.host.textbox.label=Default Host
jenkins.systemconfig.zap.default.port.textbox.label=Default Port
jenkins.systemconfig.zap.jira.section.label=ZAP JIRA
jenkins.systemconfig.zap.jira.baseurl.textbox.label=JIRA Base URL
jenkins.systemconfig.zap.jira.username.textbox.label=Username
jenkins.systemconfig.zap.jira.password.textbox.label=Password
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ZAP will start in a pre-build step (before all other build steps).</br></br><hr/></br>
Please see <b>How to <a href="https://wiki.jenkins-ci.org/display/JENKINS/zaproxy-plugin+How+To#zaproxy-pluginHowTo-%21setting.png%21ConfiguretheJobtoExecuteZAPaspartofaSeleniumBuildJENKINS%3AzaproxypluginExecuteZAPasPreBuild">Configure the Job to Execute ZAP as part of a Selenium Build
Please see <b>How to <a href="https://wiki.jenkins-ci.org/display/JENKINS/zap-plugin+How+To#zap-pluginHowTo-ConfiguretheJobtoExecuteZAPaspartofaSeleniumBuild">Configure the Job to Execute ZAP as part of a Selenium Build
</a></b> for more information.

0 comments on commit 0faf689

Please sign in to comment.