Skip to content

Commit

Permalink
[JENKINS-48463] It appears that the KXml2Driver is more tolerant of
Browse files Browse the repository at this point in the history
technically illegal xml (ie. it doesn't complain if an Xml v1.0 file
contains special characters).  Added a unit test that proves this, as well
as fixing silentlyMigrateConfigsTest so that it starts with technically
valid Xml 1.0 content
  • Loading branch information
mikecirioli committed Jan 24, 2018
1 parent b9c2148 commit a0f4191
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
19 changes: 18 additions & 1 deletion core/src/test/java/hudson/XmlFileTest.java
Expand Up @@ -8,6 +8,8 @@

import jenkins.model.Jenkins;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXParseException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
Expand All @@ -29,6 +31,21 @@ public void canReadXml1_0Test() throws IOException {
}
}

@Test(expected = SAXParseException.class)
public void xml1_0_withSpecialCharsShouldFail() throws IOException {
URL configUrl = getClass().getResource("/hudson/config_1_0_with_special_chars.xml");
File configFile = new File(configUrl.getFile());
XStream2 xs = new XStream2();
xs.alias("hudson", Jenkins.class);

XmlFile xmlFile = new XmlFile(xs, configFile);
if (xmlFile.exists()) {
Node n = (Node) xmlFile.read();
assertThat(n.getNumExecutors(), is(2));
assertThat(n.getMode().toString(), is("NORMAL"));
}
}

@Test
public void canReadXml1_1Test() throws IOException {
URL configUrl = getClass().getResource("/hudson/config_1_1.xml");
Expand All @@ -46,7 +63,7 @@ public void canReadXml1_1Test() throws IOException {

@Test
public void canReadXmlWithControlCharsTest() throws IOException {
URL configUrl = getClass().getResource("/hudson/confg_1_1_with_special_chars.xml");
URL configUrl = getClass().getResource("/hudson/config_1_1_with_special_chars.xml");
File configFile = new File(configUrl.getFile());
XStream2 xs = new XStream2();
xs.alias("hudson", Jenkins.class);
Expand Down
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<hudson>
<disabledAdministrativeMonitors/>
<version>1.480.1</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<label>LESS_TERMCAP_mb=&#x1b;[01;31m</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/XMLFileTest.java
Expand Up @@ -34,7 +34,7 @@ public void canStartWithXml_1_1_ConfigsTest() {
public void silentlyMigrateConfigsTest() throws Exception {
j.jenkins.save();
// verify that we did indeed load our test config.xml
assertThat(j.jenkins.getLabelString(), is("LESS_TERMCAP_mb=\u001B[01;31m"));
assertThat(j.jenkins.getLabelString(), is("I am a label"));
//verify that the persisted top level config.xml is v1.1
File configFile = new File(j.jenkins.getRootPath().getRemote() + File.separator + "config.xml");
assertThat(configFile.exists(), is(true));
Expand Down
Expand Up @@ -4,6 +4,6 @@
<version>1.480.1</version>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
<label>LESS_TERMCAP_mb=&#x1b;[01;31m</label>
<label>I am a label</label>
<!-- Yeah, we deleted a lot of this ... fine for testing. -->
</hudson>

0 comments on commit a0f4191

Please sign in to comment.