Skip to content

Commit

Permalink
[JENKINS-49574] - Whitelist calendar classes and improve the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Feb 16, 2018
1 parent 566a831 commit c9172d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/main/resources/META-INF/hudson.remoting.ClassFilter
@@ -0,0 +1,10 @@
# For JENKINS-49574
# Calendar class implementation has a custom deserialization logic, but it seems to be safe.
java.util.Calendar
java.util.GregorianCalendar
java.util.SimpleTimeZone
sun.util.BuddhistCalendar
java.util.JapaneseImperialCalendar
java.util.TimeZone
java.util.SimpleTimeZone
sun.util.calendar.ZoneInfo
24 changes: 20 additions & 4 deletions src/test/java/hudson/scm/JEP200Test.java
Expand Up @@ -25,14 +25,19 @@

import com.google.common.base.Predicate;
import hudson.remoting.ClassFilter;
import hudson.util.VersionNumber;
import jenkins.model.Jenkins;
import jenkins.security.ClassFilterImpl;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.reflections.ReflectionUtils;

import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import static java.lang.reflect.Modifier.*;

Expand All @@ -46,13 +51,24 @@ public class JEP200Test {
public JenkinsRule j = new JenkinsRule();

@Test
@Issue("JENKINS-49574")
@Issue("JENKINS-49574") // Fails on Jenkins 2.102+
public void checkClassesForDefaultRemotingBlacklist() {
ClassFilter f = ClassFilter.DEFAULT;
ClassFilter cf;
try {
Class<?> cfclazz = Class.forName("jenkins.security.ClassFilterImpl");
Constructor c = cfclazz.getDeclaredConstructor();
c.setAccessible(true);
cf = (ClassFilter) c.newInstance();
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | InstantiationException ex) {
if (new VersionNumber(Jenkins.VERSION).isNewerThan(new VersionNumber("2.101"))) {
throw new AssertionError("Jenkins version is newer than 2.101, jenkins.security.ClassFilterImpl should be creatable", ex);
}
cf = ClassFilter.DEFAULT;
}

//TODO: It checks abstract classes, but not implementation
//TODO: Use ReflectionUtils to automatically determine Callable Structures
checkClasses(f, CvsChangeSet.class, CvsFile.class, CVSChangeLogSet.CVSChangeLog.class);
//TODO: Use ReflectionUtils to automatically determine Callable Structures, then move it to a generic test
checkClasses(cf, CvsChangeSet.class, CvsFile.class, CVSChangeLogSet.CVSChangeLog.class);
}

private void checkClasses(ClassFilter cf, Class<?> ... c) throws AssertionError {
Expand Down

0 comments on commit c9172d8

Please sign in to comment.