Skip to content

Commit

Permalink
Merge pull request #1811 from ikedam/feature/JENKINS-28440_AdditionalFix
Browse files Browse the repository at this point in the history
[JENKINS-28440] Additional fixes for #1715
  • Loading branch information
jglick committed Aug 31, 2015
2 parents bc2ad1b + 0d54d89 commit 69a9848
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
Expand Up @@ -29,6 +29,8 @@

/**
* Wraps {@link XStreamException} to indicate it is critical for Jenkins.
*
* @since 1.625
*/
public class CriticalXStreamException extends ConversionException {
private static final long serialVersionUID = 1L;
Expand Down
62 changes: 25 additions & 37 deletions test/src/test/java/hudson/util/RobustReflectionConverterTest.java
Expand Up @@ -24,7 +24,7 @@

package hudson.util;

import hudson.cli.CLI;
import hudson.cli.CLICommandInvoker;
import hudson.diagnosis.OldDataMonitor;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Items;
Expand All @@ -37,8 +37,6 @@
import hudson.security.ACL;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

Expand Down Expand Up @@ -274,23 +272,19 @@ public void testCliFailure() throws Exception {

// Configure a bad keyword via CLI.
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
CLI cli = new CLI(r.getURL());
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int ret = cli.execute(
Arrays.asList(
"update-job",
p.getFullName(),
"--username",
"test",
"--password",
"test"
),
new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, "badvalue", AcceptOnlySpecificKeyword.ACCEPT_KEYWORD).getBytes()),
stdout,
stderr
);
assertEquals(0, ret);

CLICommandInvoker.Result ret = new CLICommandInvoker(r, "update-job")
.withStdin(new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, "badvalue", AcceptOnlySpecificKeyword.ACCEPT_KEYWORD).getBytes()))
.withArgs(
p.getFullName(),
"--username",
"test",
"--password",
"test"
)
.invoke();

assertEquals(0, ret.returnCode());

// AcceptOnlySpecificKeyword with bad value is not instantiated for rejected with readResolve,
assertNull(p.getProperty(KeywordProperty.class).getNonCriticalField());
Expand All @@ -314,23 +308,17 @@ public void testCliFailure() throws Exception {

// Configure a bad keyword via CLI.
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
CLI cli = new CLI(r.getURL());
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int ret = cli.execute(
Arrays.asList(
"update-job",
p.getFullName(),
"--username",
"test",
"--password",
"test"
),
new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, AcceptOnlySpecificKeyword.ACCEPT_KEYWORD, "badvalue").getBytes()),
stdout,
stderr
);
assertNotEquals(0, ret);
CLICommandInvoker.Result ret = new CLICommandInvoker(r, "update-job")
.withStdin(new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, AcceptOnlySpecificKeyword.ACCEPT_KEYWORD, "badvalue").getBytes()))
.withArgs(
p.getFullName(),
"--username",
"test",
"--password",
"test"
)
.invoke();
assertNotEquals(0, ret.returnCode());

// Configuration should not be updated for a failure of the critical field,
assertNotEquals("badvalue", p.getProperty(KeywordProperty.class).getCriticalField().getKeyword());
Expand Down

0 comments on commit 69a9848

Please sign in to comment.