Search in sources :

Example 36 with ConfiguredWithCode

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

the class RoleStrategyTest method shouldHandleNullItemsAndAgentsCorrectly.

@Test
@Issue("Issue #214")
@ConfiguredWithCode("RoleStrategy2.yml")
public void shouldHandleNullItemsAndAgentsCorrectly() {
    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(RoleType.Global);
    assertThat(globalRoles.size(), equalTo(2));
}
Also used : Role(com.michelin.cio.hudson.plugins.rolestrategy.Role) AuthorizationStrategy(hudson.security.AuthorizationStrategy) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) Set(java.util.Set) RoleBasedAuthorizationStrategy(com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 37 with ConfiguredWithCode

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

the class ProjectMatrixAuthorizationTest method checkCorrectlyConfiguredPermissions.

@Test
@ConfiguredWithCode("ProjectMatrixStrategy.yml")
public void checkCorrectlyConfiguredPermissions() {
    assertEquals("The configured instance must use the Global Matrix Authentication Strategy", ProjectMatrixAuthorizationStrategy.class, Jenkins.get().getAuthorizationStrategy().getClass());
    ProjectMatrixAuthorizationStrategy gms = (ProjectMatrixAuthorizationStrategy) Jenkins.get().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(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 38 with ConfiguredWithCode

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

the class SSHCredentialsTest method shouldSupportSinglelineBase64Certificates.

@Test
@ConfiguredWithCode("SSHCredentialsTest_Singleline_Key.yml")
@Issue("https://github.com/jenkinsci/configuration-as-code-plugin/issues/1189")
public void shouldSupportSinglelineBase64Certificates() {
    BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class);
    assertThat("Private key roundtrip failed", certKey.getPrivateKey().trim().replace("\r\n", "\n"), equalTo(MySSHKeySecretSource.PRIVATE_SSH_KEY));
}
Also used : BasicSSHUserPrivateKey(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 39 with ConfiguredWithCode

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

the class Security1446Test method testImportWithEnvVar.

@ConfiguredWithCode("Security1446Test.yml")
@Test
@Issue("SECURITY-1446")
public void testImportWithEnvVar() {
    List<StandardUsernamePasswordCredentials> userPasswCred = CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, Jenkins.getInstanceOrNull(), null, Collections.emptyList());
    assertThat(userPasswCred.size(), is(1));
    for (StandardUsernamePasswordCredentials cred : userPasswCred) {
        assertTrue("The JAVA_HOME environment variable should not be resolved", cred.getUsername().matches(JAVA_HOME_PATTERN));
        assertTrue("The PATH environment variable should not be resolved", cred.getDescription().matches(PATH_PATTERN));
    }
    List<StringCredentials> stringCred = CredentialsProvider.lookupCredentials(StringCredentials.class, Jenkins.getInstanceOrNull(), null, Collections.emptyList());
    assertThat(stringCred.size(), is(1));
    for (StringCredentials cred : stringCred) {
        assertTrue("The PATH environment variable should not be resolved", cred.getDescription().matches(PATH_PATTERN));
    }
}
Also used : StandardUsernamePasswordCredentials(com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) StringCredentials(org.jenkinsci.plugins.plaincredentials.StringCredentials) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 40 with ConfiguredWithCode

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

the class SeedJobTest method configure_seed_job_with_secrets.

@Test
@ConfiguredWithCode("SeedJobTest_withSecrets.yml")
public void configure_seed_job_with_secrets() {
    final Jenkins jenkins = Jenkins.get();
    assertNotNull(jenkins.getItem("testJob2"));
}
Also used : Jenkins(jenkins.model.Jenkins) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Aggregations

ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)52 Test (org.junit.Test)51 Issue (org.jvnet.hudson.test.Issue)18 CNode (io.jenkins.plugins.casc.model.CNode)16 Jenkins (jenkins.model.Jenkins)15 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)8 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)8 Util.toYamlString (io.jenkins.plugins.casc.misc.Util.toYamlString)8 Mapping (io.jenkins.plugins.casc.model.Mapping)7 BasicSSHUserPrivateKey (com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey)5 Configurator (io.jenkins.plugins.casc.Configurator)5 ProxyConfiguration (hudson.ProxyConfiguration)4 StandardUsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials)3 UsernamePasswordCredentials (com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials)3 AdminWhitelistRule (jenkins.security.s2m.AdminWhitelistRule)3 CredentialsRootConfigurator (com.cloudbees.plugins.credentials.casc.CredentialsRootConfigurator)2 Role (com.michelin.cio.hudson.plugins.rolestrategy.Role)2 RoleBasedAuthorizationStrategy (com.michelin.cio.hudson.plugins.rolestrategy.RoleBasedAuthorizationStrategy)2 FreeStyleProject (hudson.model.FreeStyleProject)2 User (hudson.model.User)2