Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 dbdef9b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Expand Up @@ -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;
Expand All @@ -41,8 +42,9 @@ public class JodaDateTimeConverter implements Converter {

@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
Expand Down
Expand Up @@ -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
Expand Down
@@ -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.