Search in sources :

Example 41 with Jenkins

use of jenkins.model.Jenkins 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 42 with Jenkins

use of jenkins.model.Jenkins 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 43 with Jenkins

use of jenkins.model.Jenkins 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)

Example 44 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class GitToolInstallationTest method configure_git_installations.

@Test
@ConfiguredWithCode("GitToolInstallationTest.yml")
public void configure_git_installations() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    final GitTool.DescriptorImpl descriptor = (GitTool.DescriptorImpl) jenkins.getDescriptor(GitTool.class);
    assertEquals(2, descriptor.getInstallations().length);
    assertEquals("/usr/local/bin/git", descriptor.getInstallation("another_git").getGitExe());
    assertEquals("/bin/git", descriptor.getInstallation("git").getGitExe());
}
Also used : Jenkins(jenkins.model.Jenkins) GitTool(hudson.plugins.git.GitTool) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Example 45 with Jenkins

use of jenkins.model.Jenkins in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguratorTest method jenkins_abstract_describable_attributes.

@Test
@ConfiguredWithCode("HeteroDescribable.yml")
public void jenkins_abstract_describable_attributes() throws Exception {
    final Jenkins jenkins = Jenkins.getInstance();
    assertTrue(jenkins.getSecurityRealm() instanceof HudsonPrivateSecurityRealm);
    assertTrue(jenkins.getAuthorizationStrategy() instanceof FullControlOnceLoggedInAuthorizationStrategy);
    assertFalse(((FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy()).isAllowAnonymousRead());
}
Also used : Jenkins(jenkins.model.Jenkins) FullControlOnceLoggedInAuthorizationStrategy(hudson.security.FullControlOnceLoggedInAuthorizationStrategy) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) Test(org.junit.Test) ConfiguredWithCode(org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)

Aggregations

Jenkins (jenkins.model.Jenkins)73 Test (org.junit.Test)22 ConfiguredWithCode (org.jenkinsci.plugins.casc.misc.ConfiguredWithCode)13 IOException (java.io.IOException)10 File (java.io.File)9 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)9 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 Statement (org.junit.runners.model.Statement)7 CheckForNull (javax.annotation.CheckForNull)6 FilePath (hudson.FilePath)5 Computer (hudson.model.Computer)5 URL (java.net.URL)5 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)5 Issue (org.jvnet.hudson.test.Issue)5 Item (hudson.model.Item)4 Node (hudson.model.Node)4 Date (java.util.Date)4