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