Skip to content

Commit

Permalink
Fix 3 bugs -
Browse files Browse the repository at this point in the history
CWE-124457 - Jenkins Operations Plugin - Bad error message when selected
host connection doesn't have a CES URL
CWE-126841 - ISPW Operations Jenkins Plugin has problems with
GetReleaseTaskList
CWE-124623 - Jenkins Operations Plugin - Pre-populate help text in
Request field
  • Loading branch information
zhouqr2000 committed Mar 5, 2018
1 parent 5c3b4d2 commit c0b561d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 18 deletions.
12 changes: 12 additions & 0 deletions dev/readme.extra/changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Version 1.0.3
* CWE-124457 - Jenkins Operations Plugin - Bad error message when selected host connection doesn't have a CES URL
* CWE-126841 - ISPW Operations Jenkins Plugin has problems with GetReleaseTaskList
* CWE-124623 - Jenkins Operations Plugin - Pre-populate help text in Request field

Version 1.0.2
* The plugin now integrates with the Compuware Common Configuration plugin which allows the Host Connection configurations to be defined centrally for other Compuware Jenkins plugins instead of needing to be specified in each Jenkins project's configuration. Host Connection configuration is now defined in the Jenkins/Manage Jenkins/Configure System screen.
* Jenkins console logs produced by the plugin have been streamlined to improve readability.
* Support for the Jenkins Pipeline Syntax.
* Support Credentials secret text to store CES token
* Support most ISPW build operations.
* Provide Docker script to build Docker image for CES server and Docker image for Jenkins with Compuware plugins pre-installed.
23 changes: 17 additions & 6 deletions src/main/java/com/compuware/ispw/restapi/IspwRestApiRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.compuware.ispw.model.rest.SetInfoResponse;
import com.compuware.ispw.model.rest.TaskResponse;
import com.compuware.ispw.restapi.action.GetSetInfoAction;
import com.compuware.ispw.restapi.action.IAction;
import com.compuware.ispw.restapi.action.IspwCommand;
import com.compuware.ispw.restapi.auth.BasicDigestAuthentication;
import com.compuware.ispw.restapi.auth.FormAuthentication;
import com.compuware.ispw.restapi.util.HttpClientUtil;
Expand All @@ -44,12 +42,12 @@
import hudson.Launcher;
import hudson.init.InitMilestone;
import hudson.init.Initializer;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Item;
import hudson.model.Items;
import hudson.model.TaskListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.security.ACL;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
Expand Down Expand Up @@ -335,7 +333,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
HostConnection hostConnection = RestApiUtils.getCesUrl(connectionId);
if (hostConnection != null) {
cesUrl = StringUtils.trimToEmpty(hostConnection.getCesUrl());

if(!cesUrl.startsWith("http")) {
logger.println("Host connection does NOT contain a valid CES URL. Please re-configure in 'Manage Jenkins | Configure System | Compuware Configurations' section");
return false;
}


String host = StringUtils.trimToEmpty(hostConnection.getHost());
String port = StringUtils.trimToEmpty(hostConnection.getPort());
cesIspwHost = host + "-" + port;
Expand Down Expand Up @@ -455,7 +458,15 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
public static final String connectionId = StringUtils.EMPTY;
public static final String credentialsId = StringUtils.EMPTY;
public static final String ispwAction = StringUtils.EMPTY;
public static final String ispwRequestBody = StringUtils.EMPTY;
public static final String ispwRequestBody = "#The following messages are commented out to show how to use the 'Request' field.\n"
+"#Click on the help button to the right of the screen for examples of how to populate this field based on 'Action' type\n"
+"#\n"
+"#For example, if you select GenerateTasksInAssignment for 'Action' field,\n"
+"# you may populate the following properties in 'Request' field.\n"
+"# The property value should be based on your own container ID and level.\n"
+"#\n"
+"#assignmentId=PLAY000313\n"
+"#level=STG2\n";
public static final Boolean consoleLogResponseBody = false;

public static final List<HttpRequestNameValuePair> customHeaders = Collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.compuware.ispw.model.rest.SetInfoResponse;
import com.compuware.ispw.model.rest.TaskResponse;
import com.compuware.ispw.restapi.action.IAction;
import com.compuware.ispw.restapi.action.IspwCommand;
import com.compuware.ispw.restapi.util.HttpRequestNameValuePair;
import com.compuware.ispw.restapi.util.RestApiUtils;
import com.compuware.jenkins.common.configuration.HostConnection;
Expand All @@ -33,8 +32,8 @@
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
Expand Down Expand Up @@ -235,7 +234,15 @@ public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
public static final String connectionId = StringUtils.EMPTY;
public static final String credentialsId = StringUtils.EMPTY;
public static final String ispwAction = StringUtils.EMPTY;
public static final String ispwRequestBody = StringUtils.EMPTY;
public static final String ispwRequestBody = "#The following messages are commented out to show how to use the 'Request' field.\n"
+"#Click on the help button to the right of the screen for examples of how to populate this field based on 'Action' type\n"
+"#\n"
+"#For example, if you select GenerateTasksInAssignment for 'Action' field,\n"
+"# you may populate the following properties in 'Request' field.\n"
+"# The property value should be based on your own container ID and level.\n"
+"#\n"
+"#assignmentId=PLAY000313\n"
+"#level=STG2\n";
public static final Boolean consoleLogResponseBody =
IspwRestApiRequest.DescriptorImpl.consoleLogResponseBody;

Expand Down Expand Up @@ -346,6 +353,12 @@ protected ResponseContentSupplier run() throws Exception {
if (hostConnection != null) {
cesUrl = StringUtils.trimToEmpty(hostConnection.getCesUrl());

if(!cesUrl.startsWith("http")) {
String errorMsg = "Host connection does NOT contain a valid CES URL. Please re-configure in 'Manage Jenkins | Configure System | Compuware Configurations' section";
logger.println(errorMsg);
throw new IllegalStateException(new Exception(errorMsg));
}

String host = StringUtils.trimToEmpty(hostConnection.getHost());
String port = StringUtils.trimToEmpty(hostConnection.getPort());
cesIspwHost = host + "-" + port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public IspwRequestBean getIspwRequestBean(String srid, String ispwRequestBody, S
String[] lines = ispwRequestBody.split("\n");
for (String line : lines) {
line = StringUtils.trimToEmpty(line);

if(line.startsWith("#")) {
continue;
}

int indexOfEqualSign = line.indexOf("=");
if (indexOfEqualSign != -1) {
String name = StringUtils.trimToEmpty(line.substring(0, indexOfEqualSign));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public IspwRequestBean getIspwRequestBean(String srid, String ispwRequestBody,
String[] lines = ispwRequestBody.split("\n");
for (String line : lines) {
line = StringUtils.trimToEmpty(line);

if(line.startsWith("#")) {
continue;
}

int indexOfEqualSign = line.indexOf("=");
if (indexOfEqualSign != -1) {
String name = StringUtils.trimToEmpty(line.substring(0, indexOfEqualSign));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public IspwRequestBean getIspwRequestBean(String srid, String ispwRequestBody,
String[] lines = ispwRequestBody.split("\n");
for (String line : lines) {
line = StringUtils.trimToEmpty(line);

if(line.startsWith("#")) {
continue;
}

int indexOfEqualSign = line.indexOf("=");
if (indexOfEqualSign != -1) {
String name = StringUtils.trimToEmpty(line.substring(0, indexOfEqualSign));
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/com/compuware/ispw/restapi/util/RestApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ public static void startLog(PrintStream logger, String ispwAction, IspwContextPa
}
}

//Fix CES bug - CWE-124094 - Get assignment/release/set task list doesn't return a JSON array ("tasks":[]) if they contains just one task
public static String fixCesTaskListResponseJson(String responseJson) {
String fixedResponseJson = responseJson;

if(responseJson.startsWith("{\"tasks\":{")) {
fixedResponseJson = responseJson.replace("{\"tasks\":{", "{\"tasks\":[{");
fixedResponseJson = fixedResponseJson.replace("}}", "}]}");
}

return fixedResponseJson;
}


public static Object endLog(PrintStream logger, String ispwAction, IspwRequestBean ispwRequestBean, String responseJson, boolean block) {
Object returnObject = null;
JsonProcessor jsonProcessor = new JsonProcessor();
Expand All @@ -267,14 +280,7 @@ public static Object endLog(PrintStream logger, String ispwAction, IspwRequestBe
returnObject = taskResponse;
} else if (IspwCommand.GetAssignmentTaskList.equals(ispwAction)) {

String fixedResponseJson = responseJson;

//Fix CES bug - CWE-124094 - Get assignment/release/set task list doesn't return a JSON array ("tasks":[]) if they contains just one task
if(responseJson.startsWith("{\"tasks\":{")) {
fixedResponseJson = responseJson.replace("{\"tasks\":{", "{\"tasks\":[{");
fixedResponseJson = fixedResponseJson.replace("}}", "}]}");
}

String fixedResponseJson = fixCesTaskListResponseJson(responseJson);
TaskListResponse listResponse = jsonProcessor.parse(fixedResponseJson, TaskListResponse.class);

logger.println("...taskId, module, userId, version, status, application/stream/level, release");
Expand Down Expand Up @@ -326,7 +332,10 @@ public static Object endLog(PrintStream logger, String ispwAction, IspwRequestBe
logger.println("...user tag: " + releaseInfo.getUserTag());
returnObject = releaseInfo;
} else if (IspwCommand.GetReleaseTaskList.equals(ispwAction)) {
TaskListResponse listResponse = jsonProcessor.parse(responseJson, TaskListResponse.class);

String fixedResponseJson = fixCesTaskListResponseJson(responseJson);
TaskListResponse listResponse = jsonProcessor.parse(fixedResponseJson, TaskListResponse.class);

logger.println("...taskId, module, userId, version, status, application/stream/level, release");
for(TaskInfo taskInfo: listResponse.getTasks()) {
logger.println("..." + taskInfo.getTaskId() + ", " + taskInfo.getModuleName() + "."
Expand Down

0 comments on commit c0b561d

Please sign in to comment.