Skip to content
Permalink
Browse files

[JENKINS-50216] - Joda DateTime converter now has higher priority tha…

…n JEP-200 blacklist
  • Loading branch information
oleg-nenashev committed Apr 17, 2018
1 parent 9099cb1 commit dbdef9b760d3c1d21be7d8199022b1bae60864e0
@@ -20,6 +20,7 @@
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
@@ -41,8 +42,9 @@

@Initializer(before = InitMilestone.PLUGINS_LISTED)
public static void initConverter() {
// Overrides the default converters
Jenkins.XSTREAM2.registerConverter(new JodaDateTimeConverter(), 10);
// Overrides the default converters, runs before the JEP-200 blacklist
Jenkins.XSTREAM2.registerConverter(new JodaDateTimeConverter(),
XStream.PRIORITY_VERY_HIGH + 1);
}

@Override
@@ -121,6 +121,29 @@ public void shouldDeserializeBrokenXMLAsNull() throws Exception {
read.isTokenExpired());
}

@Test
@Issue("JENKINS-50216")
public void shouldRoundtripNulls() throws Exception {
File file = new File(tmp.getRoot(), "remotableGoogleCredentials.xml");
try (InputStream istream =
RemotableGoogleCredentialsTest.class.getResourceAsStream(
"jodaDateTimeNull.xml");
OutputStream ostream = new FileOutputStream(file)) {
org.apache.commons.io.IOUtils.copy(istream, ostream);
}

XmlFile xml = new XmlFile(Jenkins.XSTREAM2, file);
RemotableGoogleCredentials read =
(RemotableGoogleCredentials) xml.read();
DateTime expiration = read.getTokenExpirationTime();
assertNull("Expiration token should be null", expiration);
assertTrue("Deserialized token should be considered as expired",
read.isTokenExpired());

// Write it back
xml.write(read);
}

private static class Requirement extends GoogleOAuth2ScopeRequirement {

@Override
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<com.google.jenkins.plugins.credentials.oauth.RemotableGoogleCredentials>
<module/>
<projectId>myproject</projectId>
<username>mattomata</username>
<accessToken>&lt;MOCKED&gt;</accessToken>
</com.google.jenkins.plugins.credentials.oauth.RemotableGoogleCredentials>

0 comments on commit dbdef9b

Please sign in to comment.