use of io.jenkins.plugins.casc.model.CNode in project configuration-as-code-plugin by jenkinsci.
the class MavenConfiguratorTest method export_maven_tool.
@Test
@ConfiguredWithReadme("maven/README.md#0")
public void export_maven_tool() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getToolRoot(context).get("maven");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "MavenConfiguratorTestExpected.yml");
assertThat(exported, is(expected));
}
use of io.jenkins.plugins.casc.model.CNode in project configuration-as-code-plugin by jenkinsci.
the class MavenConfiguratorTest method export_maven_global_config.
@Test
@ConfiguredWithReadme("maven/README.md#1")
public void export_maven_global_config() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getToolRoot(context).get("mavenGlobalConfig");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "MavenConfiguratorTestGlobalConfigExpected.yml");
assertThat(exported, is(expected));
}
use of io.jenkins.plugins.casc.model.CNode in project configuration-as-code-plugin by jenkinsci.
the class RoleStrategyTest method shouldExportRolesCorrect.
@Test
@ConfiguredWithCode("RoleStrategy1.yml")
public void shouldExportRolesCorrect() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getJenkinsRoot(context).get("authorizationStrategy");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "RoleStrategy1Expected.yml");
assertThat(exported, is(expected));
}
use of io.jenkins.plugins.casc.model.CNode in project configuration-as-code-plugin by jenkinsci.
the class SbtTest method export_sbt_tool.
@Test
public void export_sbt_tool() throws Exception {
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
CNode yourAttribute = getToolRoot(context).get("sbtInstallation");
String exported = toYamlString(yourAttribute);
String expected = toStringFromYamlFile(this, "SbtTestExpected.yml");
assertThat(exported, is(expected));
}
use of io.jenkins.plugins.casc.model.CNode in project configuration-as-code-plugin by jenkinsci.
the class Security1446Test method testExportWithEnvVar.
@Test
@Issue("SECURITY-1446")
public void testExportWithEnvVar() throws Exception {
final String message = "Hello, world! PATH=${PATH} JAVA_HOME=^${JAVA_HOME}";
ConfiguratorRegistry registry = ConfiguratorRegistry.get();
ConfigurationContext context = new ConfigurationContext(registry);
DataBoundConfigurator<UsernamePasswordCredentialsImpl> configurator = new DataBoundConfigurator<>(UsernamePasswordCredentialsImpl.class);
UsernamePasswordCredentialsImpl creds = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test", message, "foo", "bar");
final CNode config = configurator.describe(creds, context);
final Node valueNode = ConfigurationAsCode.get().toYaml(config);
final String exported;
try (StringWriter writer = new StringWriter()) {
ConfigurationAsCode.serializeYamlNode(valueNode, writer);
exported = writer.toString();
} catch (IOException e) {
throw new YAMLException(e);
}
assertThat("Message was not escaped", exported, not(containsString(message)));
assertThat("Improper masking for PATH", exported, containsString("^${PATH}"));
assertThat("Improper masking for JAVA_HOME", exported, containsString("^^${JAVA_HOME}"));
}
Aggregations