Search in sources :

Example 21 with ConfiguredWithCode

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

the class JenkinsConfiguratorTest method shouldSetEnvironmentVariable.

@Test
@Issue("Issue #173")
@ConfiguredWithCode("SetEnvironmentVariable.yml")
public void shouldSetEnvironmentVariable() throws Exception {
    final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.get().getNodeProperties();
    EnvVars env = new EnvVars();
    for (NodeProperty<?> property : properties) {
        property.buildEnvVars(env, TaskListener.NULL);
    }
    assertEquals("BAR", env.get("FOO"));
}
Also used : EnvVars(hudson.EnvVars) NodePropertyDescriptor(hudson.slaves.NodePropertyDescriptor) NodeProperty(hudson.slaves.NodeProperty) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 22 with ConfiguredWithCode

use of io.jenkins.plugins.casc.misc.ConfiguredWithCode 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() {
    final Jenkins jenkins = Jenkins.get();
    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(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 23 with ConfiguredWithCode

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

the class JenkinsConfiguratorTest method shouldImportLabelAtoms.

@Test
@ConfiguredWithCode("ConfigureLabels.yml")
public void shouldImportLabelAtoms() {
    LabelAtom label1 = Jenkins.get().getLabelAtom("label1");
    assertNotNull(label1);
    assertThat(label1.getProperties(), hasSize(2));
    assertEquals(2, label1.getProperties().get(TestProperty.class).value);
    assertEquals(4, label1.getProperties().get(AnotherTestProperty.class).otherProperty);
    LabelAtom label2 = Jenkins.get().getLabelAtom("label2");
    assertNotNull(label2);
    assertThat(label2.getProperties(), hasSize(1));
    assertEquals(3, label2.getProperties().get(TestProperty.class).value);
}
Also used : LabelAtom(hudson.model.labels.LabelAtom) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 24 with ConfiguredWithCode

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

the class ProxyConfiguratorTest method shouldSetProxyWithAllFields.

@Test
@ConfiguredWithCode("Proxy.yml")
public void shouldSetProxyWithAllFields() throws Exception {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.name, "proxyhost");
    assertEquals(proxy.port, 80);
    assertEquals(proxy.getUserName(), "login");
    assertThat(proxy.getSecretPassword(), hasPlainText("password"));
    assertEquals(proxy.noProxyHost, "externalhost");
    assertEquals(proxy.getTestUrl(), "http://google.com");
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final Configurator c = context.lookupOrFail(ProxyConfiguration.class);
    final CNode node = c.describe(proxy, context);
    assertNotNull(node);
    Mapping mapping = node.asMapping();
    assertEquals(6, mapping.size());
    assertEquals("proxyhost", mapping.getScalarValue("name"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) ProxyConfiguration(hudson.ProxyConfiguration) Configurator(io.jenkins.plugins.casc.Configurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 25 with ConfiguredWithCode

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

the class ProxyConfiguratorTest method shouldNotWritePasswordToLog.

@Test
@Env(name = "PROXY_USER", value = "proxy_user")
@Env(name = "PROXY_PASSWORD", value = "proxy_password")
@ConfiguredWithCode("ProxyWithSecrets.yml")
// Fixed in 1.20
@Issue("SECURITY-1303")
public void shouldNotWritePasswordToLog() {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.getUserName(), "proxy_user");
    assertThat(proxy.getSecretPassword(), hasPlainText("proxy_password"));
    // Check logs
    assertLogContains(logging, "secretPassword");
    assertNotInLog(logging, "proxy_password");
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode) Env(io.jenkins.plugins.casc.misc.Env)

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