Search in sources :

Example 11 with ConfiguredWithCode

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

the class SystemCredentialsTest method configure_system_credentials.

@Test
@ConfiguredWithCode("SystemCredentialsTest.yml")
public void configure_system_credentials() throws Exception {
    Jenkins jenkins = Jenkins.getInstance();
    List<UsernamePasswordCredentials> ups = CredentialsProvider.lookupCredentials(UsernamePasswordCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(ups, hasSize(1));
    assertThat(ups.get(0).getPassword().getPlainText(), equalTo("1234"));
    List<CertificateCredentials> certs = CredentialsProvider.lookupCredentials(CertificateCredentials.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(certs, hasSize(1));
    assertThat(certs.get(0).getPassword().getPlainText(), equalTo("ABCD"));
    List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList());
    assertThat(sshPrivateKeys, hasSize(2));
    assertThat(sshPrivateKeys.get(0).getPassphrase().getPlainText(), equalTo("ABCD"));
}
Also used : Jenkins(jenkins.model.Jenkins) CertificateCredentials(com.cloudbees.plugins.credentials.common.CertificateCredentials) BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) UsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 12 with ConfiguredWithCode

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

the class AdminWhitelistRuleConfiguratorTest method checkM2SSecurityKillSwitch_disabled.

@Test
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Slave2MasterSecurityKillSwitch_disabled.yml")
public void checkM2SSecurityKillSwitch_disabled() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
    Assert.assertFalse("MasterToSlave Security should be disabled", 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 13 with ConfiguredWithCode

use of org.jenkinsci.plugins.casc.misc.ConfiguredWithCode 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));
}
Also used : ArrayList(java.util.ArrayList) GlobalMatrixAuthorizationStrategy(hudson.security.GlobalMatrixAuthorizationStrategy) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 14 with ConfiguredWithCode

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

the class ProjectMatrixAuthorizationTest method checkCorrectlyConfiguredPermissions.

@Test
@ConfiguredWithCode("ProjectMatrixStrategy.yml")
public void checkCorrectlyConfiguredPermissions() throws Exception {
    assertEquals("The configured instance must use the Global Matrix Authentication Strategy", ProjectMatrixAuthorizationStrategy.class, Jenkins.getInstance().getAuthorizationStrategy().getClass());
    ProjectMatrixAuthorizationStrategy gms = (ProjectMatrixAuthorizationStrategy) 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));
}
Also used : ArrayList(java.util.ArrayList) ProjectMatrixAuthorizationStrategy(hudson.security.ProjectMatrixAuthorizationStrategy) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 15 with ConfiguredWithCode

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

the class GetConfiguratorsTest method shouldGetAllConfigurators.

@Test
@ConfiguredWithCode(value = "GetConfiguratorsTest.yml")
public void shouldGetAllConfigurators() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    ConfigurationAsCode configurationAsCode = jenkins.getExtensionList(ManagementLink.class).get(ConfigurationAsCode.class);
    assertThat(configurationAsCode.getConfigurators(), hasSize(greaterThan(0)));
}
Also used : Jenkins(jenkins.model.Jenkins) ManagementLink(hudson.model.ManagementLink) 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