Skip to content

Commit b53be1b

Browse files
committed
Add test for null content type in createValue
Sends a GET request to buildWithParameters, which has no content type header. Before the fix in the previous commit, this would trigger an NPE in commons-fileupload2 when Pattern.matcher() receives null.
1 parent 897778e commit b53be1b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/test/java/io/jenkins/plugins/file_parameters/AbstractFileParameterDefinitionTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ void restMissingValue(JenkinsRule r) throws Exception {
144144
r.assertLogContains("received null: null", b);
145145
}
146146

147+
@Test
148+
void restGetRequestNullContentType(JenkinsRule r) throws Exception {
149+
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
150+
r.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to("admin"));
151+
WorkflowJob p = r.createProject(WorkflowJob.class, "myjob");
152+
p.addProperty(new ParametersDefinitionProperty(new Base64FileParameterDefinition("FILE")));
153+
p.setDefinition(new CpsFlowDefinition("echo 'ok'", true));
154+
// GET request has null content type, simulating what build-with-parameters plugin does
155+
// when rendering the parameter form via /parambuild/
156+
WebRequest req = new WebRequest(new URL(r.getURL() + "job/myjob/buildWithParameters"), HttpMethod.GET);
157+
JenkinsRule.WebClient wc = r.createWebClient().withBasicApiToken("admin");
158+
wc.setThrowExceptionOnFailingStatusCode(false);
159+
wc.getPage(req);
160+
// Should not throw NPE; createValue should return null for null content type
161+
}
162+
147163
@Test
148164
void buildStep(JenkinsRule r) throws Exception {
149165
WorkflowJob us = r.createProject(WorkflowJob.class, "us");

0 commit comments

Comments
 (0)