Search in sources :

Example 1 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class AdminWhitelistRuleConfiguratorTest method checkM2SSecurityKillSwitch_enabled.

@Test
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Slave2MasterSecurityKillSwitch_enabled.yml")
public void checkM2SSecurityKillSwitch_enabled() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
    Assert.assertTrue("MasterToSlave Security should be enabled", rule.getMasterKillSwitch());
}
Also used : Jenkins(jenkins.model.Jenkins) AdminWhitelistRule(jenkins.security.s2m.AdminWhitelistRule) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 2 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class HudsonPrivateSecurityRealmConfiguratorTest method configure_local_security_and_admin_user.

@Test
@ConfiguredWithCode("HudsonPrivateSecurityRealmConfiguratorTest.yml")
public void configure_local_security_and_admin_user() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    final HudsonPrivateSecurityRealm securityRealm = (HudsonPrivateSecurityRealm) jenkins.getSecurityRealm();
    assertFalse(securityRealm.allowsSignup());
    final User admin = User.getById("admin", false);
    assertNotNull(admin);
    final HudsonPrivateSecurityRealm.Details details = admin.getProperty(HudsonPrivateSecurityRealm.Details.class);
    assertTrue(details.isPasswordCorrect("1234"));
    final FullControlOnceLoggedInAuthorizationStrategy authorizationStrategy = (FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy();
    assertTrue(authorizationStrategy.isAllowAnonymousRead());
}
Also used : Jenkins(jenkins.model.Jenkins) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) User(hudson.model.User) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 3 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class RoleStrategyTest method shouldReadRolesCorrectly.

@Test
@Issue("Issue #48")
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldReadRolesCorrectly() throws Exception {
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    User admin = User.get("admin");
    User user1 = User.get("user1");
    User user2 = User.get("user2");
    Computer agent1 = j.jenkins.getComputer("agent1");
    Computer agent2 = j.jenkins.getComputer("agent2");
    Folder folderA = j.jenkins.createProject(Folder.class, "A");
    FreeStyleProject jobA1 = folderA.createProject(FreeStyleProject.class, "1");
    Folder folderB = j.jenkins.createProject(Folder.class, "B");
    FreeStyleProject jobB2 = folderB.createProject(FreeStyleProject.class, "2");
    AuthorizationStrategy s = j.jenkins.getAuthorizationStrategy();
    assertThat("Authorization Strategy has been read incorrectly", s, instanceOf(RoleBasedAuthorizationStrategy.class));
    RoleBasedAuthorizationStrategy rbas = (RoleBasedAuthorizationStrategy) s;
    Map<Role, Set<String>> globalRoles = rbas.getGrantedRoles(RoleBasedAuthorizationStrategy.GLOBAL);
    assertThat(globalRoles.size(), equalTo(2));
    // Admin has configuration access
    assertHasPermission(admin, j.jenkins, Jenkins.ADMINISTER, Jenkins.READ);
    assertHasPermission(user1, j.jenkins, Jenkins.READ);
    assertHasNoPermission(user1, j.jenkins, Jenkins.ADMINISTER, Jenkins.RUN_SCRIPTS);
    // Folder A is restricted to admin
    assertHasPermission(admin, folderA, Item.CONFIGURE);
    assertHasPermission(user1, folderA, Item.READ, Item.DISCOVER);
    assertHasNoPermission(user1, folderA, Item.CONFIGURE, Item.DELETE, Item.BUILD);
    // But they have access to jobs in Folder A
    assertHasPermission(admin, folderA, Item.CONFIGURE, Item.CANCEL);
    assertHasPermission(user1, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasPermission(user2, jobA1, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    assertHasNoPermission(user1, folderA, Item.CANCEL);
    // FolderB is editable by user2, but he cannot delete it
    assertHasPermission(user2, folderB, Item.READ, Item.DISCOVER, Item.CONFIGURE, Item.BUILD);
    assertHasNoPermission(user2, folderB, Item.DELETE);
    assertHasNoPermission(user1, folderB, Item.CONFIGURE, Item.BUILD, Item.DELETE);
    // Only user1 can run on agent1, but he still cannot configure it
    assertHasPermission(admin, agent1, Computer.CONFIGURE, Computer.DELETE, Computer.BUILD);
    assertHasPermission(user1, agent1, Computer.BUILD);
    assertHasNoPermission(user1, agent1, Computer.CONFIGURE, Computer.DISCONNECT);
    // Same user still cannot build on agent2
    assertHasNoPermission(user1, agent2, Computer.BUILD);
}
Also used : Role(com.michelin.cio.hudson.plugins.rolestrategy.Role) AuthorizationStrategy(hudson.security.AuthorizationStrategy) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) User(hudson.model.User) Set(java.util.Set) Computer(hudson.model.Computer) Folder(com.cloudbees.hudson.plugins.folder.Folder) FreeStyleProject(hudson.model.FreeStyleProject) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 4 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class GithubOAuthTest method testSampleVersionForOAuth.

@Test
@ConfiguredWithCode("GithubOAuth.yml")
public void testSampleVersionForOAuth() {
    SecurityRealm realm = Jenkins.getInstance().getSecurityRealm();
    assertThat(realm, instanceOf(GithubSecurityRealm.class));
    GithubSecurityRealm gsh = (GithubSecurityRealm) realm;
    assertEquals("someId", gsh.getClientID());
    assertEquals("https://api.github.com", gsh.getGithubApiUri());
    assertEquals("https://github.com", gsh.getGithubWebUri());
    assertEquals("j985j8fhfhh377", gsh.getClientSecret().getPlainText());
    assertEquals("read:org,user:email", gsh.getOauthScopes());
}
Also used : GithubSecurityRealm(org.jenkinsci.plugins.GithubSecurityRealm) SecurityRealm(hudson.security.SecurityRealm) GithubSecurityRealm(org.jenkinsci.plugins.GithubSecurityRealm) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 5 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguratorTest method jenkins_primitive_attributes.

@Test
@ConfiguredWithCode("Primitives.yml")
public void jenkins_primitive_attributes() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    assertEquals(6666, jenkins.getSlaveAgentPort());
    assertEquals(false, jenkins.isUsageStatisticsCollected());
}
Also used : Jenkins(jenkins.model.Jenkins) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Aggregations

ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)21 Test (org.junit.Test)20 Jenkins (jenkins.model.Jenkins)13 Issue (org.jvnet.hudson.test.Issue)3 DockerCloud (com.nirima.jenkins.plugins.docker.DockerCloud)2 DockerTemplate (com.nirima.jenkins.plugins.docker.DockerTemplate)2 TopLevelItem (hudson.model.TopLevelItem)2 User (hudson.model.User)2 FullControlOnceLoggedInAuthorizationStrategy (hudson.security.FullControlOnceLoggedInAuthorizationStrategy)2 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)2 ArrayList (java.util.ArrayList)2 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)2 Folder (com.cloudbees.hudson.plugins.folder.Folder)1 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)1 CertificateCredentials (com.cloudbees.plugins.credentials.common.CertificateCredentials)1 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)1 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)1 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)1 Computer (hudson.model.Computer)1 FreeStyleProject (hudson.model.FreeStyleProject)1