Skip to content

Commit f859f0a

Browse files
committed
Fixed SECURITY-2266
1 parent 7297667 commit f859f0a

File tree

8 files changed

+155
-164
lines changed

8 files changed

+155
-164
lines changed

custom-checkbox-parameter.iml

Lines changed: 129 additions & 128 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>4.0</version>
7+
<version>4.16</version>
88
<relativePath />
99
</parent>
1010
<groupId>io.jenkins.plugins</groupId>
@@ -15,7 +15,8 @@
1515
<description>This plug-in can dynamically create a set of check boxes for users to check before building. The check box settings are configured through YAML or JSON files, and the file content can be obtained through HTTP, HTTPS, or file paths. After checking the check box, the user can use params['ParameterName'] in the build script to get the selected value. The result of the user's selection is returned in the form of a string separated by "," value1, value2, value3.</description>
1616
<url>https://github.com/jenkinsci/custom-checkbox-parameter-plugin</url>
1717
<properties>
18-
<jenkins.version>2.164.3</jenkins.version>
18+
<!--https://www.jenkins.io/doc/developer/plugin-development/updating-parent/-->
19+
<jenkins.version>2.277.1</jenkins.version>
1920
<java.level>8</java.level>
2021
</properties>
2122
<licenses>
@@ -54,11 +55,17 @@
5455
<dependency>
5556
<!-- Pick up common dependencies for 2.164.x: https://github.com/jenkinsci/bom#usage -->
5657
<groupId>io.jenkins.tools.bom</groupId>
57-
<artifactId>bom-2.164.x</artifactId>
58-
<version>3</version>
58+
<artifactId>bom-2.277.x</artifactId>
59+
<version>26</version>
5960
<scope>import</scope>
6061
<type>pom</type>
6162
</dependency>
63+
<dependency>
64+
<groupId>org.apache.httpcomponents</groupId>
65+
<artifactId>httpclient</artifactId>
66+
<version>4.5.13</version>
67+
<scope>compile</scope>
68+
</dependency>
6269
</dependencies>
6370
</dependencyManagement>
6471
<dependencies>
@@ -98,12 +105,6 @@
98105
<version>1.25</version>
99106
<optional>true</optional>
100107
</dependency>
101-
<dependency>
102-
<groupId>org.apache.httpcomponents</groupId>
103-
<artifactId>httpclient</artifactId>
104-
<version>4.5.13</version>
105-
<scope>compile</scope>
106-
</dependency>
107108
<dependency>
108109
<groupId>org.yaml</groupId>
109110
<artifactId>snakeyaml</artifactId>

src/main/java/com/bluersw/CheckboxParameterDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public CheckboxParameterDefinition(String name, String description, Protocol pro
6868
this.uuid = UUID.randomUUID();
6969
this.protocol = protocol == null ? Protocol.HTTP_HTTPS : protocol;
7070
this.format = format == null ? Format.Empty : format;
71-
this.uri = uri == null ? "" : uri;
72-
this.displayNodePath = displayNodePath == null ? DEFAULT_NAME_NODE : displayNodePath;
73-
this.valueNodePath = valueNodePath == null ? DEFAULT_VALUE_NODE : valueNodePath;
71+
this.uri = isNotBlank(uri) ? uri : "";
72+
this.displayNodePath = isNotBlank(displayNodePath) ? displayNodePath : DEFAULT_NAME_NODE;
73+
this.valueNodePath = isNotBlank(valueNodePath) ? valueNodePath : DEFAULT_VALUE_NODE;
7474
this.submitContent="";
7575
this.useInput=false;
7676
this.defaultValue = "";

src/main/resources/com/bluersw/CheckboxParameterDefinition/index.jelly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<st:adjunct includes="com.bluersw.CheckboxParameter"/>
77
<f:entry title="${it.name}" description="${it.description}">
88
<div name="parameter" id="${it.divId}" style="white-space:nowrap" >
9-
<input type="hidden" name="name" value="${it.name}" />
9+
<input type="hidden" name="name" value="${it.name}" id="name_${it.divId}"/>
1010
<label style='padding:0 0 0 10px'><input type="checkbox" name="all_checkbox" value="checkall" class="checkbox-all"/>${%parameter.selectAll} </label>
1111
<br/>
1212
<div id="checkbox_div" style="width:auto;"/>
1313
<div id="result_message"/>
1414
</div>
1515
<script type="text/javascript">
1616
var parentDiv = jQuery('#${it.divId}');
17+
var nameHidden = parentDiv.find('#name_${it.divId}');
1718
var requestBasicUrl = "${h.getCurrentDescriptorByNameUrl()}/${it.descriptor.descriptorUrl}/";
18-
var parameterName = '${it.name}';
19-
initializationCheckbox(parentDiv,requestBasicUrl,parameterName);
19+
initializationCheckbox(parentDiv,requestBasicUrl,nameHidden.val());
2020
</script>
2121
</f:entry>
2222
</j:jelly>

src/main/resources/com/bluersw/javascript/CheckboxParameter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function initializationCheckbox(parentDiv,requestBasicUrl,parameterName){
1010
contentType: "application/json; charset=utf-8",
1111
success: function(result){
1212
for(i=0;i<result.list.length;i++){
13+
if(i!=0 && i%20==0) {checkboxDiv.append("<br/><br/>")}
1314
checkboxDiv.append("<label style='padding:0 0 0 10px'><input type='checkbox' " + result.list[i].checked + " name='checkbox_" + result.list[i].value + "'>" + result.list[i].name + "</input></label>");
1415
}
1516
messageD.text(result.message);

src/test/java/com/bluersw/CheckboxParameterDefinitionTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ public class CheckboxParameterDefinitionTests {
1818

1919
@Test
2020
public void testScriptedPipeline() throws Exception{
21-
22-
CheckboxParameterDefinition param = new CheckboxParameterDefinition(Name,description,protocol,format,uri,displayNodePath,valueNodePath,useInput);
21+
CheckboxParameterDefinition param = new CheckboxParameterDefinition(name,description,protocol,format,"","","",useInput);
2322
param.setDefaultValue(defaultValue);
2423
WorkflowJob job = jenkins.createProject(WorkflowJob.class, "test-scripted-pipeline");
2524
job.addProperty(new ParametersDefinitionProperty(param));
2625
String pipelineScript
2726
= "node {\n"
28-
+ " print params['my-checkbox'] \n"
27+
+ " print params['SELECT_NODES'] \n"
2928
+ "}";
3029
job.setDefinition(new CpsFlowDefinition(pipelineScript, true));
3130
WorkflowRun completedBuild = jenkins.assertBuildStatusSuccess(job.scheduleBuild2(0));

src/test/java/com/bluersw/Constants.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
import net.sf.json.JSONObject;
66

77
public class Constants {
8-
static final String Name = "my-checkbox";
8+
static final String name = "SELECT_NODES";
99
static final Protocol protocol = Protocol.HTTP_HTTPS;
10-
static final Format format = Format.YAML;
11-
static final JSONObject useInput = JSONObject.fromObject("{useInput:{submitContent:''}}");
12-
static final String uri = "https://raw.githubusercontent.com/sunweisheng/Jenkins/master/examples/example.yaml";
13-
static final String displayNodePath = "//CheckboxParameter/key";
14-
static final String valueNodePath = "//CheckboxParameter/value";
15-
static final String description = "";
10+
static final Format format = Format.JSON;
11+
static final JSONObject useInput = JSONObject.fromObject("{\"submitContent\" : {\"CheckboxParameter\": [{\"key\": \"node1\",\"value\": \"node1\"},{\"key\": \"node2\",\"value\": \"node2\"},{\"key\": \"node3\",\"value\": \"node3\"},{\"key\": \"node4\",\"value\": \"node4\"}]}}");
12+
static final String description = "Select nodes";
1613
static final String defaultValue = "default value";
1714
}

src/test/java/com/bluersw/source/HttpRequestTests.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@
77
public class HttpRequestTests {
88

99
@Test
10-
public void httpsGet_GitHub() throws Exception{
11-
HttpRequest request = new HttpRequest("https://raw.githubusercontent.com/sunweisheng/Jenkins/master/examples/example.yaml");
12-
assertNotNull(request.get());
13-
assertEquals(request.getStatusLine(),"HTTP/1.1 200 OK");
14-
assertEquals(request.getStatusCode(),200);
15-
}
16-
17-
@Test
18-
public void httpsGet_Jenkins() throws Exception{
19-
HttpRequest request = new HttpRequest("https://www.jenkins.io/zh/");
10+
public void httpsGet_Baidu() throws Exception{
11+
HttpRequest request = new HttpRequest("https://www.baidu.com");
2012
assertNotNull(request.get());
2113
assertEquals(request.getStatusLine(),"HTTP/1.1 200 OK");
2214
assertEquals(request.getStatusCode(),200);

0 commit comments

Comments
 (0)