|
28 | 28 | import com.google.common.base.Predicate;
|
29 | 29 | import hudson.FilePath;
|
30 | 30 | import hudson.Functions;
|
31 |
| -import hudson.init.InitMilestone; |
32 |
| -import hudson.init.Initializer; |
33 | 31 | import hudson.model.Computer;
|
34 | 32 | import hudson.model.Executor;
|
35 | 33 | import hudson.model.Item;
|
|
57 | 55 | import java.io.FileOutputStream;
|
58 | 56 | import java.io.IOException;
|
59 | 57 | import java.io.StringWriter;
|
60 |
| -import java.lang.reflect.Field; |
61 |
| -import java.nio.charset.StandardCharsets; |
62 |
| -import java.nio.file.FileVisitResult; |
63 |
| -import java.nio.file.Files; |
64 |
| -import java.nio.file.Path; |
65 |
| -import java.nio.file.SimpleFileVisitor; |
66 |
| -import java.nio.file.attribute.BasicFileAttributes; |
67 | 58 | import java.util.ArrayList;
|
68 | 59 | import java.util.Arrays;
|
69 | 60 | import java.util.Collections;
|
|
86 | 77 | import net.sf.json.JSONObject;
|
87 | 78 | import net.sf.json.groovy.JsonSlurper;
|
88 | 79 | import org.acegisecurity.Authentication;
|
89 |
| -import org.apache.commons.io.FileUtils; |
90 | 80 | import org.apache.commons.io.IOUtils;
|
91 | 81 | import org.apache.tools.ant.util.JavaEnvUtils;
|
92 | 82 | import static org.hamcrest.Matchers.*;
|
93 |
| -import org.jboss.marshalling.ObjectResolver; |
94 | 83 | import org.jenkinsci.plugins.durabletask.FileMonitoringTask;
|
95 | 84 | import org.jenkinsci.plugins.workflow.actions.LogAction;
|
96 | 85 | import org.jenkinsci.plugins.workflow.actions.QueueItemAction;
|
|
108 | 97 | import org.jenkinsci.plugins.workflow.steps.EchoStep;
|
109 | 98 | import org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep;
|
110 | 99 | import org.jenkinsci.plugins.workflow.steps.durable_task.Messages;
|
111 |
| -import org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader; |
112 | 100 | import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
|
113 | 101 | import org.junit.AfterClass;
|
114 | 102 | import static org.junit.Assert.*;
|
|
126 | 114 | import org.jvnet.hudson.test.MockAuthorizationStrategy;
|
127 | 115 | import org.jvnet.hudson.test.RestartableJenkinsRule;
|
128 | 116 | import org.jvnet.hudson.test.TestExtension;
|
129 |
| -import org.jvnet.hudson.test.recipes.LocalData; |
130 | 117 |
|
131 | 118 | /** Tests pertaining to {@code node} and {@code sh} steps. */
|
132 | 119 | public class ExecutorStepTest {
|
@@ -1121,105 +1108,6 @@ List<String> currentLabels() {
|
1121 | 1108 | });
|
1122 | 1109 | }
|
1123 | 1110 |
|
1124 |
| - @Issue("JENKINS-39134") |
1125 |
| - @LocalData |
1126 |
| - @Test public void serialForm() { |
1127 |
| - story.addStep(new Statement() { |
1128 |
| - @Override public void evaluate() throws Throwable { |
1129 |
| - WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); |
1130 |
| - WorkflowRun b = p.getBuildByNumber(1); |
1131 |
| - assertThat(patchedFiles, containsInAnyOrder(/* "program.dat", */"3.xml", "3.log", "log")); |
1132 |
| - /* TODO this seems to randomly not include the expected items: |
1133 |
| - assertThat(patchedFields, Matchers.containsInAnyOrder( |
1134 |
| - // But not FileMonitoringController.controlDir, since this old version is still using location-independent .id. |
1135 |
| - "private final java.lang.String org.jenkinsci.plugins.workflow.support.pickles.FilePathPickle.path", |
1136 |
| - "private final java.lang.String org.jenkinsci.plugins.workflow.support.pickles.WorkspaceListLeasePickle.path", |
1137 |
| - "private java.lang.String org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.remote")); |
1138 |
| - */ |
1139 |
| - story.j.assertLogContains("simulated later output", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b))); |
1140 |
| - } |
1141 |
| - }); |
1142 |
| - } |
1143 |
| - private static final List<String> patchedFiles = new ArrayList<>(); |
1144 |
| - private static final List<String> patchedFields = new ArrayList<>(); |
1145 |
| - // TODO @TestExtension("serialForm") ItemListener does not work since we need to run before FlowExecutionList.ItemListenerImpl yet TestExtension does not support ordinal |
1146 |
| - @Initializer(before = InitMilestone.JOB_LOADED) public static void replaceWorkspacePath() throws Exception { |
1147 |
| - final File prj = new File(Jenkins.getInstance().getRootDir(), "jobs/p"); |
1148 |
| - final File workspace = new File(prj, "workspace"); |
1149 |
| - final String ORIG_WS = "/space/tmp/AbstractStepExecutionImpl-upgrade/jobs/p/workspace"; |
1150 |
| - final String newWs = workspace.getAbsolutePath(); |
1151 |
| - File controlDir = new File(workspace, ".eb6272d3"); |
1152 |
| - if (!controlDir.isDirectory()) { |
1153 |
| - return; |
1154 |
| - } |
1155 |
| - System.err.println("Patching " + controlDir); |
1156 |
| - RiverReader.customResolver = new ObjectResolver() { |
1157 |
| - @Override public Object readResolve(Object replacement) { |
1158 |
| - Class<?> c = replacement.getClass(); |
1159 |
| - //System.err.println("replacing " + c.getName()); |
1160 |
| - while (c != Object.class) { |
1161 |
| - for (Field f : c.getDeclaredFields()) { |
1162 |
| - if (f.getType() == String.class) { |
1163 |
| - try { |
1164 |
| - f.setAccessible(true); |
1165 |
| - Object v = f.get(replacement); |
1166 |
| - if (ORIG_WS.equals(v)) { |
1167 |
| - //System.err.println("patching " + f); |
1168 |
| - f.set(replacement, newWs); |
1169 |
| - patchedFields.add(f.toString()); |
1170 |
| - } else if (newWs.equals(v)) { |
1171 |
| - //System.err.println(f + " was already patched, somehow?"); |
1172 |
| - } else { |
1173 |
| - //System.err.println("some other value " + v + " for " + f); |
1174 |
| - } |
1175 |
| - } catch (Exception x) { |
1176 |
| - x.printStackTrace(); |
1177 |
| - } |
1178 |
| - } |
1179 |
| - } |
1180 |
| - c = c.getSuperclass(); |
1181 |
| - } |
1182 |
| - return replacement; |
1183 |
| - } |
1184 |
| - @Override public Object writeReplace(Object original) { |
1185 |
| - throw new IllegalStateException(); |
1186 |
| - } |
1187 |
| - }; |
1188 |
| - Files.walkFileTree(prj.toPath(), new SimpleFileVisitor<Path>() { |
1189 |
| - @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { |
1190 |
| - File f = file.toFile(); |
1191 |
| - String name = f.getName(); |
1192 |
| - if (name.equals("program.dat")) { |
1193 |
| - /* TODO could not get this to work; stream appeared corrupted: |
1194 |
| - patchedFiles.add(name); |
1195 |
| - String origContent = FileUtils.readFileToString(f, StandardCharsets.ISO_8859_1); |
1196 |
| - String toReplace = String.valueOf((char) Protocol.ID_STRING_SMALL) + String.valueOf((char) ORIG_WS.length()) + ORIG_WS; |
1197 |
| - int newLen = newWs.length(); |
1198 |
| - String replacement = String.valueOf((char) Protocol.ID_STRING_MEDIUM) + |
1199 |
| - String.valueOf((char) (newLen & 0xff00) >> 8) + |
1200 |
| - String.valueOf((char) newLen & 0xff) + |
1201 |
| - newWs; // TODO breaks if not ASCII |
1202 |
| - String replacedContent = origContent.replace(toReplace, replacement); |
1203 |
| - assertNotEquals("failed to replace ‘" + toReplace + "’", replacedContent, origContent); |
1204 |
| - FileUtils.writeStringToFile(f, replacedContent, StandardCharsets.ISO_8859_1); |
1205 |
| - */ |
1206 |
| - } else { |
1207 |
| - String origContent = FileUtils.readFileToString(f, StandardCharsets.ISO_8859_1); |
1208 |
| - String replacedContent = origContent.replace(ORIG_WS, newWs); |
1209 |
| - if (!replacedContent.equals(origContent)) { |
1210 |
| - patchedFiles.add(name); |
1211 |
| - FileUtils.writeStringToFile(f, replacedContent, StandardCharsets.ISO_8859_1); |
1212 |
| - } |
1213 |
| - } |
1214 |
| - return super.visitFile(file, attrs); |
1215 |
| - } |
1216 |
| - }); |
1217 |
| - FilePath controlDirFP = new FilePath(controlDir); |
1218 |
| - controlDirFP.child("jenkins-result.txt").write("0", null); |
1219 |
| - FilePath log = controlDirFP.child("jenkins-log.txt"); |
1220 |
| - log.write(log.readToString() + "simulated later output\n", null); |
1221 |
| - } |
1222 |
| - |
1223 | 1111 | @Issue("SECURITY-675")
|
1224 | 1112 | @Test public void authentication() {
|
1225 | 1113 | story.then(r -> {
|
|
0 commit comments