use of io.jenkins.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.
the class AdminWhitelistRuleConfiguratorTest method checkA2MAccessControl_disable.
@Test
@Issue("Issue #172")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml")
public void checkA2MAccessControl_disable() throws Exception {
final Jenkins jenkins = Jenkins.get();
MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class);
Assert.assertFalse("Agent → Master Access Control should be disabled", config.getMasterToSlaveAccessControl());
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final Configurator c = context.lookupOrFail(AdminWhitelistRule.class);
final CNode node = c.describe(rule, context);
final Mapping agent = node.asMapping();
assertEquals("false", agent.get("enabled").toString());
}
use of io.jenkins.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.
the class AdminWhitelistRuleConfiguratorTest method checkA2MAccessControl_enabled.
@Test
@Issue("Issue #172")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml")
public void checkA2MAccessControl_enabled() throws Exception {
final Jenkins jenkins = Jenkins.get();
MasterKillSwitchConfiguration config = jenkins.getDescriptorByType(MasterKillSwitchConfiguration.class);
Assert.assertTrue("Agent → Master Access Control should be enabled", config.getMasterToSlaveAccessControl());
AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final Configurator c = context.lookupOrFail(AdminWhitelistRule.class);
final CNode node = c.describe(rule, context);
final Mapping agent = node.asMapping();
assertEquals("true", agent.get("enabled").toString());
}
use of io.jenkins.plugins.casc.Configurator 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"));
}
use of io.jenkins.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.
the class UpdateCenterConfiguratorTest method shouldSetUpdateCenterSites.
@Test
@ConfiguredWithCode("UpdateCenter.yml")
public void shouldSetUpdateCenterSites() throws Exception {
UpdateCenter updateCenter = j.jenkins.getUpdateCenter();
List<UpdateSite> sites = updateCenter.getSites();
assertEquals(2, sites.size());
UpdateSite siteOne = sites.get(0);
assertEquals("default", siteOne.getId());
assertEquals("https://updates.jenkins.io/update-center.json", siteOne.getUrl());
UpdateSite siteTwo = sites.get(1);
assertEquals("experimental", siteTwo.getId());
assertEquals("https://updates.jenkins.io/experimental/update-center.json", siteTwo.getUrl());
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final Configurator c = context.lookupOrFail(UpdateCenter.class);
final CNode node = c.describe(updateCenter, context);
assertNotNull(node);
Mapping site1 = node.asMapping().get("sites").asSequence().get(1).asMapping();
assertEquals("experimental", site1.getScalarValue("id"));
}
use of io.jenkins.plugins.casc.Configurator in project configuration-as-code-plugin by jenkinsci.
the class PrimitiveConfiguratorTest method _Integer_env.
@Test
public void _Integer_env() throws Exception {
environment.set("ENV_FOR_TEST", "123");
Configurator c = registry.lookupOrFail(Integer.class);
final Object value = c.configure(new Scalar("${ENV_FOR_TEST}"), context);
assertEquals(123, (int) value);
}
Aggregations