use of hudson.security.GlobalMatrixAuthorizationStrategy in project blueocean-plugin by jenkinsci.
the class ProfileApiTest method shouldFailForAnonymousRead.
@Test
public void shouldFailForAnonymousRead() throws IOException {
HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
realm.createAccount("alice", "alice");
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(as);
as.add(Hudson.READ, "alice");
Map resp = new RequestBuilder(baseUrl).status(403).get("/users/").build(Map.class);
assertEquals(403, resp.get("code"));
}
use of hudson.security.GlobalMatrixAuthorizationStrategy in project workflow-cps-plugin by jenkinsci.
the class ReplayActionTest method rebuild.
@Issue("JENKINS-47339")
@Test
public void rebuild() throws Exception {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
story.j.jenkins.setSecurityRealm(story.j.createDummySecurityRealm());
GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy();
gmas.add(Jenkins.READ, "dev3");
gmas.add(Item.BUILD, "dev3");
gmas.add(Item.READ, "dev3");
story.j.jenkins.setAuthorizationStrategy(gmas);
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'script to rebuild'", true));
WorkflowRun b1 = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("script to rebuild", b1);
WorkflowRun b2;
{
// First time around, verify that UI elements are present and functional.
ReplayAction a = b1.getAction(ReplayAction.class);
assertNotNull(a);
assertFalse(canReplay(b1, "dev3"));
assertTrue(canRebuild(b1, "dev3"));
JenkinsRule.WebClient wc = story.j.createWebClient();
wc.login("dev3");
HtmlPage page = wc.getPage(b1, a.getUrlName());
WebAssert.assertFormNotPresent(page, "config");
HtmlForm form = page.getFormByName("rebuild");
HtmlPage redirect = story.j.submit(form);
assertEquals(p.getAbsoluteUrl(), redirect.getUrl().toString());
story.j.waitUntilNoActivity();
b2 = p.getBuildByNumber(2);
assertNotNull(b2);
}
story.j.assertLogContains("script to rebuild", story.j.assertBuildStatusSuccess(b2));
ReplayCause cause = b2.getCause(ReplayCause.class);
assertNotNull(cause);
assertEquals(1, cause.getOriginalNumber());
assertEquals(b1, cause.getOriginal());
assertEquals(b2, cause.getRun());
}
});
}
use of hudson.security.GlobalMatrixAuthorizationStrategy in project configuration-as-code-plugin by jenkinsci.
the class GlobalMatrixAuthorizationTest method checkCorrectlyConfiguredPermissions.
@Test
@ConfiguredWithCode("GlobalMatrixStrategy.yml")
public void checkCorrectlyConfiguredPermissions() throws Exception {
assertEquals("The configured instance must use the Global Matrix Authentication Strategy", GlobalMatrixAuthorizationStrategy.class, Jenkins.getInstance().getAuthorizationStrategy().getClass());
GlobalMatrixAuthorizationStrategy gms = (GlobalMatrixAuthorizationStrategy) Jenkins.getInstance().getAuthorizationStrategy();
List<String> adminPermission = new ArrayList<>(gms.getGrantedPermissions().get(Jenkins.ADMINISTER));
assertEquals("authenticated", adminPermission.get(0));
List<String> readPermission = new ArrayList<>(gms.getGrantedPermissions().get(Jenkins.READ));
assertEquals("anonymous", readPermission.get(0));
}
use of hudson.security.GlobalMatrixAuthorizationStrategy in project blueocean-plugin by jenkinsci.
the class ArtifactsSecurity564 method testArtifactsWithPermissions.
/**
* Uses matrix-auth to provide artifacts permission.
*
* If hudson.security.ArtifactsPermission is set then the user must have Run.ARTIFACTS set.
*
* @throws Exception
*/
@Issue("SECURITY-564")
@Test
public void testArtifactsWithPermissions() throws Exception {
String JOB_NAME = "artifactPermissions";
String artifactPath = "a/b/c";
HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
realm.createAccount("alice", "alice");
realm.createAccount("bob", "bob");
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(as);
as.add(Hudson.READ, "alice");
as.add(Item.READ, "alice");
as.add(Run.ARTIFACTS, "alice");
as.add(Hudson.READ, "bob");
as.add(Item.READ, "bob");
FreeStyleProject p = j.createFreeStyleProject(JOB_NAME);
p.getBuildersList().add(new ArtifactBuilder(artifactPath, 100));
p.getPublishersList().add(new ArtifactArchiver("**/*"));
Run r = p.scheduleBuild2(0).waitForStart();
r = j.waitForCompletion(r);
List artifacts = request().authAlice().get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
Assert.assertEquals(100, artifacts.size());
Assert.assertEquals(0, ((Map) artifacts.get(0)).get("size"));
Assert.assertEquals(artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("path"));
Assert.assertEquals("/job/artifactPermissions/1/artifact/" + artifactPath + "/0.txt", ((Map) artifacts.get(0)).get("url"));
List artifactsBob = request().auth("bob", "bob").get("/organizations/jenkins/pipelines/" + JOB_NAME + "/runs/" + r.getId() + "/artifacts").build(List.class);
Assert.assertEquals(0, artifactsBob.size());
}
use of hudson.security.GlobalMatrixAuthorizationStrategy in project blueocean-plugin by jenkinsci.
the class ProfileApiTest method shouldSucceedForAnonymousRead.
@Test
public void shouldSucceedForAnonymousRead() throws IOException {
HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false);
realm.createAccount("alice", "alice");
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy as = new GlobalMatrixAuthorizationStrategy();
j.jenkins.setAuthorizationStrategy(as);
as.add(Hudson.READ, "anonymous");
List resp = new RequestBuilder(baseUrl).status(200).get("/users/").build(List.class);
assertEquals(1, resp.size());
}
Aggregations