use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class ProxyConfiguratorTest method shouldSetProxyWithMinimumFields.
@Test
@ConfiguredWithCode("ProxyMinimal.yml")
public void shouldSetProxyWithMinimumFields() throws Exception {
ProxyConfiguration proxy = j.jenkins.proxy;
assertEquals(proxy.name, "proxyhost");
assertEquals(proxy.port, 80);
assertNull(proxy.getUserName());
assertNull(proxy.getTestUrl());
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(2, node.asMapping().size());
assertEquals("proxyhost", mapping.getScalarValue("name"));
assertEquals("80", mapping.getScalarValue("port"));
}
use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class ProxyConfiguratorTest method describeMinimalProxyConfig.
@Test
@ConfiguredWithCode("ProxyMinimal.yml")
public void describeMinimalProxyConfig() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
final CNode configNode = getProxyNode(context);
final String yamlConfig = Util.toYamlString(configNode);
assertEquals(String.join("\n", "name: \"proxyhost\"", "port: 80", ""), yamlConfig);
}
use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method packageParametersAreNonnullByDefaultButCanBeNullable.
@Test
@Issue("#1025")
public void packageParametersAreNonnullByDefaultButCanBeNullable() throws Exception {
Mapping config = new Mapping();
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
final PackageParametersNonNullCheckForNull configured = (PackageParametersNonNullCheckForNull) registry.lookupOrFail(PackageParametersNonNullCheckForNull.class).configure(config, new ConfigurationContext(registry));
assertNull(configured.getSecret());
}
use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method shouldThrowConfiguratorException.
@Test
public void shouldThrowConfiguratorException() {
Mapping config = new Mapping();
config.put("foo", "foo");
config.put("bar", "abcd");
config.put("qix", "99");
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
try {
registry.lookupOrFail(Foo.class).configure(config, new ConfigurationContext(registry));
fail("above action is excepted to throw ConfiguratorException!");
} catch (ConfiguratorException e) {
assertThat(e.getMessage(), is("foo: Failed to construct instance of class io.jenkins.plugins.casc.impl.configurators.DataBoundConfiguratorTest$Foo.\n" + " Constructor: public io.jenkins.plugins.casc.impl.configurators.DataBoundConfiguratorTest$Foo(java.lang.String,boolean,int).\n" + " Arguments: [java.lang.String, java.lang.Boolean, java.lang.Integer].\n" + " Expected Parameters: foo java.lang.String, bar boolean, qix int"));
}
}
use of io.jenkins.plugins.casc.ConfigurationContext in project configuration-as-code-plugin by jenkinsci.
the class DataBoundConfiguratorTest method shouldNotLogSecretsForUndefinedConstructors.
@Test
@Issue("SECURITY-1497")
public void shouldNotLogSecretsForUndefinedConstructors() throws Exception {
Mapping config = new Mapping();
config.put("secret", "mySecretValue");
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
registry.lookupOrFail(SecretHolderWithString.class).configure(config, new ConfigurationContext(registry));
assertLogContains(logging, "secret");
assertNotInLog(logging, "mySecretValue");
}
Aggregations