|
28 | 28 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
29 | 29 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
30 | 30 | import static org.junit.jupiter.api.Assertions.assertNull;
|
| 31 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
31 | 32 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
32 | 33 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
|
33 | 34 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.SCCS;
|
34 | 35 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.SUBVERSION;
|
35 | 36 | import static org.opengrok.indexer.history.MercurialRepositoryTest.runHgCommand;
|
36 | 37 |
|
37 | 38 | import java.io.File;
|
| 39 | +import java.io.IOException; |
38 | 40 | import java.nio.file.Paths;
|
39 | 41 | import java.util.Date;
|
40 | 42 | import java.util.Iterator;
|
|
47 | 49 | import org.junit.jupiter.api.Test;
|
48 | 50 | import org.junit.jupiter.api.condition.EnabledOnOs;
|
49 | 51 | import org.junit.jupiter.api.condition.OS;
|
| 52 | +import org.junit.jupiter.params.ParameterizedTest; |
| 53 | +import org.junit.jupiter.params.provider.ValueSource; |
50 | 54 | import org.opengrok.indexer.condition.EnabledForRepository;
|
51 | 55 | import org.opengrok.indexer.configuration.Filter;
|
52 | 56 | import org.opengrok.indexer.configuration.IgnoredNames;
|
@@ -827,4 +831,60 @@ public void testStoreAndTryToGetIgnored() throws Exception {
|
827 | 831 | retrievedHistory = cache.get(makefile, repo, true);
|
828 | 832 | assertNotNull(retrievedHistory, "history for Makefile should not be null");
|
829 | 833 | }
|
| 834 | + |
| 835 | + @ParameterizedTest |
| 836 | + @ValueSource(strings = { |
| 837 | + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| 838 | + "<java version=\"11.0.8\" class=\"java.beans.XMLDecoder\">\n" + |
| 839 | + " <object class=\"java.lang.Runtime\" method=\"getRuntime\">\n" + |
| 840 | + " <void method=\"exec\">\n" + |
| 841 | + " <array class=\"java.lang.String\" length=\"2\">\n" + |
| 842 | + " <void index=\"0\">\n" + |
| 843 | + " <string>/usr/bin/nc</string>\n" + |
| 844 | + " </void>\n" + |
| 845 | + " <void index=\"1\">\n" + |
| 846 | + " <string>-l</string>\n" + |
| 847 | + " </void>\n" + |
| 848 | + " </array>\n" + |
| 849 | + " </void>\n" + |
| 850 | + " </object>\n" + |
| 851 | + "</java>", |
| 852 | + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| 853 | + "<java version=\"11.0.8\" class=\"java.beans.XMLDecoder\">\n" + |
| 854 | + " <object class=\"java.lang.ProcessBuilder\">\n" + |
| 855 | + " <array class=\"java.lang.String\" length=\"1\" >\n" + |
| 856 | + " <void index=\"0\"> \n" + |
| 857 | + " <string>/usr/bin/curl https://oracle.com</string>\n" + |
| 858 | + " </void>\n" + |
| 859 | + " </array>\n" + |
| 860 | + " <void method=\"start\"/>\n" + |
| 861 | + " </object>\n" + |
| 862 | + "</java>", |
| 863 | + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| 864 | + "<java version=\"11.0.8\" class=\"java.beans.XMLDecoder\">\n" + |
| 865 | + " <object class = \"java.io.FileOutputStream\"> \n" + |
| 866 | + " <string>opengrok_test.txt</string>\n" + |
| 867 | + " <method name = \"write\">\n" + |
| 868 | + " <array class=\"byte\" length=\"3\">\n" + |
| 869 | + " <void index=\"0\"><byte>96</byte></void>\n" + |
| 870 | + " <void index=\"1\"><byte>96</byte></void>\n" + |
| 871 | + " <void index=\"2\"><byte>96</byte></void>\n" + |
| 872 | + " </array>\n" + |
| 873 | + " </method>\n" + |
| 874 | + " <method name=\"close\"/>\n" + |
| 875 | + " </object>\n" + |
| 876 | + "</java>" |
| 877 | + }) |
| 878 | + void testDeserializationOfNotWhiteListedClassThrowsError(final String exploit) { |
| 879 | + assertThrows(IllegalAccessError.class, () -> FileHistoryCache.readCache(exploit)); |
| 880 | + } |
| 881 | + |
| 882 | + @Test |
| 883 | + void testReadCacheValid() throws IOException { |
| 884 | + File testFile = new File(FileHistoryCacheTest.class.getClassLoader(). |
| 885 | + getResource("history/FileHistoryCache.java.gz").getFile()); |
| 886 | + History history = FileHistoryCache.readCache(testFile); |
| 887 | + assertNotNull(history); |
| 888 | + assertEquals(30, history.getHistoryEntries().size()); |
| 889 | + } |
830 | 890 | }
|
0 commit comments