Refine search
@Test @Issue("JENKINS-25623") public void timeoutKillsLoop() throws Exception { p.setDefinition(new CpsFlowDefinition("timeout(time:3, unit:'SECONDS') { while (true) {} }", true)); jenkins.assertBuildStatus(Result.ABORTED, p.scheduleBuild2(0)); }
@Issue("JENKINS-45455") @Test public void parametersAndRestart() throws Exception { // Initial build passes - we mainly just want it to add the parameters. WorkflowRun original = expect("restart", "parametersAndRestart").go(); WorkflowJob p = original.getParent(); WorkflowRun failing = p.scheduleBuild2(0, new ParametersAction(new BooleanParameterValue("flag", false), new StringParameterValue("someParam", "changed"))).waitForStart(); j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(failing)); HtmlPage redirect = restartFromStageInUI(failing, "restart"); assertNotNull(redirect); assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString()); j.waitUntilNoActivity(); WorkflowRun b3 = p.getBuildByNumber(3); assertNotNull(b3); j.assertBuildStatusSuccess(b3); j.assertLogContains("Odd numbered build, success", b3); j.assertLogContains("Stage \"pre-restart\" skipped due to this build restarting at stage \"restart\"", b3); j.assertLogContains("Flag is false", b3); j.assertLogContains("someParam is changed", b3); j.assertLogContains("otherParam is should not change", b3); j.assertLogNotContains("hello on non-restart", b3); }
/** * Tests the "URL@HEAD" format in the SVN URL */ @Test public void headRevisionCheckout() throws Exception { File testRepo = new CopyExisting(getClass().getResource("two-revisions.zip")).allocate(); SubversionSCM scm = new SubversionSCM("file://" + testRepo.toURI().toURL().getPath() + "@HEAD"); FreeStyleProject p = r.createFreeStyleProject(); p.setScm(scm); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause()).get(); System.out.println(b.getLog(LOG_LIMIT)); r.assertLogContains("At revision 2", b); r.assertBuildStatus(Result.SUCCESS,b); }
@Test public void errors() throws Exception { WorkflowJob p = j.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("erroneous()", true)); j.assertLogContains("ought to fail", j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0))); } public static final class Erroneous extends Step {
@Issue("JENKINS-53305") @Test public void contextClassLoader() throws Exception { WorkflowJob p = j.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("" + // Sets the class loader used to invoke steps to null to demonstrate a potential problem. // I am not sure how this could occur in practice, so this is a very artificial reproduction. "org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.ORIGINAL_CONTEXT_CLASS_LOADER.set(null)\n" + "checkClassLoader()\n", false)); j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0)); } public static final class CheckClassLoader extends Step {
/** * Trying to run a step without having the required context should result in a graceful error. */ @Test public void missingContextCheck() throws Exception { p.setDefinition(new CpsFlowDefinition("readFile 'true'", true)); WorkflowRun b = p.scheduleBuild2(0).get(); jenkins.assertLogContains("such as: node", b); // make sure the 'node' is a suggested message. this comes from MissingContextVariableException // jenkins.assertLogNotContains("Exception", b) // haven't figured out how to hide this jenkins.assertBuildStatus(Result.FAILURE, b); }
@Test @Issue("JENKINS-25623") public void killInfiniteLoop() throws Exception { p.setDefinition(new CpsFlowDefinition("while(true) { " + WorkflowJobNonRestartingTest.class.getName()+".going(); }", true)); QueueTaskFuture<WorkflowRun> f = p.scheduleBuild2(0); WorkflowRun b = f.getStartCondition().get(3, TimeUnit.SECONDS); going.block(3000); // get the buld going, which will loop infinitely b.doStop(); // abort, abort! jenkins.assertBuildStatus(Result.ABORTED, jenkins.waitForCompletion(b)); }
@Test public void compilationErrorsCanBeSerialized() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition( "node {\n" + " writeFile text: 'bad, syntax', file: 'test.groovy'\n" + " try {\n" + " load('test.groovy')\n" + " } catch (e) {\n" + " sleep(time: 1, unit: 'MILLISECONDS')\n" + // Force the exception to be persisted. " throw e\n" + " }\n" + "}", true)); WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); r.assertLogNotContains(NotSerializableException.class.getName(), b); r.assertLogNotContains(MultipleCompilationErrorsException.class.getName(), b); r.assertLogContains(CpsCompilationErrorsException.class.getName(), b); r.assertLogContains("unexpected token: bad", b); }
@Test public void emptyDirectoryAllowEmptyResult() throws Exception { JUnitResultArchiver a = new JUnitResultArchiver("TEST-*.xml"); a.setAllowEmptyResults(true); FreeStyleProject freeStyleProject = j.createFreeStyleProject(); freeStyleProject.getPublishersList().add(a); j.assertBuildStatus(Result.SUCCESS, freeStyleProject.scheduleBuild2(0).get()); }
/** * Not a syntax error but semantics error in using the 'pipeline' step. * This should be reported nicely. */ @Test public void errorInJenkinsfile() throws Exception { WorkflowJob job = j.createProject(WorkflowJob.class); // still a syntactically valid groovy code but no stage name job.setDefinition(new CpsFlowDefinition("pipeline { stages { stage { sh './test.sh' } } }")); WorkflowRun b = j.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); j.assertLogContains(Messages.ModelParser_ExpectedStringLiteral(), b); j.assertLogContains(String.format(" pipeline { stages { stage { sh './test.sh' } } }%n" + " ^%n") ,b); }
@Test public void emptyDirectory() throws Exception { JUnitResultArchiver a = new JUnitResultArchiver("TEST-*.xml"); a.setAllowEmptyResults(false); FreeStyleProject freeStyleProject = j.createFreeStyleProject(); freeStyleProject.getPublishersList().add(a); j.assertBuildStatus(Result.FAILURE, freeStyleProject.scheduleBuild2(0).get()); }
@Issue("SECURITY-1186") @Test public void finalizer() throws Exception { WorkflowJob p = jenkins.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("class Foo {\n" + " @Override public void finalize() {\n" + " }\n" + "}\n" + "echo 'Should never get here'", true)); WorkflowRun b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); jenkins.assertLogContains("Object.finalize()", b); jenkins.assertLogNotContains("Should never get here", b); }
/** Verify that running branch projects are not deleted even after an organization folder reindex. */ @Issue("JENKINS-25240") @Test public void runningBuildMeta() throws Exception { SecondOrderComputedFolder org = r.jenkins.createProject(SecondOrderComputedFolder.class, "org"); org.metakids.add(Arrays.asList("A", "B")); org.metakids.add(Arrays.asList("C", "D")); org.assertItemNames("A+B", "C+D"); FreeStyleProject b = r.jenkins.getItemByFullName("org/A+B/B", FreeStyleProject.class); b.getBuildersList().add(new SleepBuilder(Long.MAX_VALUE)); FreeStyleBuild b1 = b.scheduleBuild2(0).waitForStart(); org.metakids.remove(0); org.assertItemNames("A+B", "C+D"); assertTrue(b1.isBuilding()); b1.doStop(); r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b1)); org.assertItemNames("C+D"); }
/** * Tests the "URL@REV" format in SVN URL. */ @Issue("JENKINS-262") @Test @Ignore("TODO use docker-fixtures for a reproducible test case") public void revisionedCheckout() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); p.setScm(new SubversionSCM("https://svn.jenkins-ci.org/trunk/hudson/test-projects/trivial-ant@13000")); FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserIdCause()).get(); System.out.println(b.getLog(LOG_LIMIT)); r.assertLogContains("at revision 13000", b); r.assertBuildStatus(Result.SUCCESS,b); b = p.scheduleBuild2(0, new Cause.UserIdCause()).get(); System.out.println(b.getLog(LOG_LIMIT)); r.assertLogContains("at revision 13000", b); r.assertBuildStatus(Result.SUCCESS,b); }
@Issue("JENKINS-29922") @Test public void nonexistentFunctions() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("nonexistent()", true)); WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); r.assertLogContains("nonexistent", b); r.assertLogContains("wrapInCurve", b); r.assertLogContains("polygon", b); }
@Issue("SECURITY-567") @Test public void methodPointers() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("println((Jenkins.&getInstance)())", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }
@Issue("JENKINS-46088") @Test public void rhsOfDeclarationSandboxedInCPS() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("jenkins.model.Jenkins x = jenkins.model.Jenkins.getInstance()\n", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }
@Issue({"JENKINS-42563", "SECURITY-582"}) @Test public void superCallsSandboxed() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("class X extends groovy.json.JsonSlurper {def parse(url) {super.parse(new URL(url))}}; echo(/got ${new X().parse(\"${JENKINS_URL}api/json\")}/)", true)); WorkflowRun r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.json.JsonSlurper parse java.net.URL", r); job.setDefinition(new CpsFlowDefinition("class X extends groovy.json.JsonSlurper {def m(url) {super.parse(new URL(url))}}; echo(/got ${new X().m(\"${JENKINS_URL}api/json\")}/)", true)); r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.json.JsonSlurper parse java.net.URL", r); job.setDefinition(new CpsFlowDefinition("class X extends File {X(String f) {super(f)}}; echo(/got ${new X('x')}/)", true)); r = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.File java.lang.String", r); }
@Issue("JENKINS-46088") @Test public void rhsOfDeclarationTransformedInNonCPS() throws Exception { logging.record(CpsTransformer.class, Level.FINEST); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p"); job.setDefinition(new CpsFlowDefinition("@NonCPS\n" + "def willFail() {\n" + " jenkins.model.Jenkins x = jenkins.model.Jenkins.getInstance()\n" + "}\n" + "willFail()\n", true)); WorkflowRun b = job.scheduleBuild2(0).get(); jenkins.assertBuildStatus(Result.FAILURE, b); jenkins.assertLogContains("org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod jenkins.model.Jenkins getInstance", b); }
@Issue("SECURITY-266") @Test public void sandboxRejectsASTTransforms() throws Exception { WorkflowJob p = jenkins.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("import groovy.transform.*\n" + "import jenkins.model.Jenkins\n" + "import org.jenkinsci.plugins.workflow.job.WorkflowJob\n" + "@ASTTest(value={ assert Jenkins.get().createProject(WorkflowJob.class, \"should-not-exist\") })\n" + "@Field int x\n" + "echo 'hello'\n", true)); WorkflowRun b = jenkins.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)); jenkins.assertLogContains("Annotation ASTTest cannot be used in the sandbox", b); assertNull(jenkins.jenkins.getItem("should-not-exist")); } }