Search in sources :

Example 1 with MockQueueItemAuthenticator

use of org.jvnet.hudson.test.MockQueueItemAuthenticator in project workflow-cps-plugin by jenkinsci.

the class WorkflowTest method authentication.

@Test
public void authentication() throws Exception {
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            jenkins().setSecurityRealm(story.j.createDummySecurityRealm());
            jenkins().save();
            QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(new MockQueueItemAuthenticator(Collections.singletonMap("demo", User.get("someone").impersonate())));
            p = jenkins().createProject(WorkflowJob.class, "demo");
            p.setDefinition(new CpsFlowDefinition("checkAuth()"));
            ScriptApproval.get().preapproveAll();
            startBuilding();
            waitForWorkflowToSuspend();
            assertTrue(b.isBuilding());
            story.j.waitForMessage("running as someone", b);
            CheckAuth.finish(false);
            waitForWorkflowToSuspend();
            assertTrue(b.isBuilding());
            story.j.waitForMessage("still running as someone", b);
        }
    });
    story.addStep(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            assertEquals(JenkinsRule.DummySecurityRealm.class, jenkins().getSecurityRealm().getClass());
            rebuildContext(story.j);
            assertThatWorkflowIsSuspended();
            story.j.waitForMessage("again running as someone", b);
            CheckAuth.finish(true);
            story.j.assertLogContains("finally running as someone", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
        }
    });
}
Also used : MockQueueItemAuthenticator(org.jvnet.hudson.test.MockQueueItemAuthenticator) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Statement(org.junit.runners.model.Statement) Test(org.junit.Test)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 Test (org.junit.Test)1 Statement (org.junit.runners.model.Statement)1 MockQueueItemAuthenticator (org.jvnet.hudson.test.MockQueueItemAuthenticator)1