clear checks between tets, just in case

This commit is contained in:
Chris Frohoff
2015-01-29 07:52:17 -08:00
parent cdfaff46cd
commit dbdce11f76
2 changed files with 13 additions and 6 deletions
@@ -11,6 +11,10 @@ public class MockSecurityManager extends SecurityManager {
return checks;
}
public void clearChecks() {
checks.clear();
}
@Override
public void checkPermission(final Permission perm) {
checks.add(perm);
@@ -3,8 +3,10 @@ package ysoserial.payloads;
import static com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.DESERIALIZE_TRANSLET;
import java.io.FilePermission;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ProvideSecurityManager;
@@ -17,10 +19,6 @@ import ysoserial.ExecSerializable;
import ysoserial.MockPayload;
import ysoserial.MockSecurityManager;
import ysoserial.Throwables;
import ysoserial.payloads.CommonsCollections1;
import ysoserial.payloads.Groovy1;
import ysoserial.payloads.ObjectPayload;
import ysoserial.payloads.Spring1;
import ysoserial.payloads.util.Serializables;
/*
@@ -46,6 +44,10 @@ public class PayloadsTest {
@Rule
public final ProvideSecurityManager psm = new ProvideSecurityManager(msm);
// ensure that checks get cleared between tests, though current test setup seems to work without it
@Before
public void clearChecks() { msm.clearChecks(); }
@DataPoints
public static ObjectPayload[] payloads() {
return new ObjectPayload[] { new CommonsCollections1(), new Groovy1(), new Spring1() };
@@ -68,7 +70,8 @@ public class PayloadsTest {
}
// confirm sm saw the check for file execution
Assert.assertTrue(msm.getChecks().contains(new FilePermission("<<ALL FILES>>", "execute")));
Assert.assertEquals(1,Collections.frequency(msm.getChecks(), new FilePermission("<<ALL FILES>>", "execute")));
}
// make sure test harness fails properly