io.jenkins.plugins.casc.misc.ConfiguredWithCode Java Examples

The following examples show how to use io.jenkins.plugins.casc.misc.ConfiguredWithCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpdateCenterConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));

}
 
Example #2
Source File: SeedJobTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("SeedJobTest_withSecurityConfig.yml")
@Envs(
    @Env(name = "SEED_JOB_FOLDER_FILE_PATH", value = ".")
)
public void configure_seed_job_with_security_config() throws Exception {
    final Jenkins jenkins = Jenkins.get();

    final GlobalJobDslSecurityConfiguration dslSecurity = GlobalConfiguration.all()
        .get(GlobalJobDslSecurityConfiguration.class);
    assertNotNull(dslSecurity);
    assertThat("ScriptSecurity", dslSecurity.isUseScriptSecurity(), is(false));

    FreeStyleProject seedJobWithSecurityConfig = (FreeStyleProject) jenkins.getItem("seedJobWithSecurityConfig");
    assertNotNull(seedJobWithSecurityConfig);

    assertTrue(seedJobWithSecurityConfig.isInQueue());
    FreeStyleBuild freeStyleBuild = j.buildAndAssertSuccess(seedJobWithSecurityConfig);
    j.assertLogContains("Processing DSL script testJob2.groovy", freeStyleBuild);
    j.assertLogContains("Added items:", freeStyleBuild);
    j.assertLogContains("GeneratedJob{name='testJob2'}", freeStyleBuild);
}
 
Example #3
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("Proxy.yml")
public void describeProxyConfig() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final CNode configNode = getProxyNode(context);

    Secret password = requireNonNull(Secret.decrypt(getProxyNode(context).getScalarValue("secretPassword")));

    final String yamlConfig = Util.toYamlString(configNode);
    assertEquals(String.join("\n",
            "name: \"proxyhost\"",
            "noProxyHost: \"externalhost\"",
            "port: 80",
            "secretPassword: \"" + password.getEncryptedValue() + "\"",
            "testUrl: \"http://google.com\"",
            "userName: \"login\"",
            ""
    ), yamlConfig);
}
 
Example #4
Source File: CredentialsTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("GlobalCredentials.yml")
public void testExportFileCredentials() throws Exception {
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CredentialsRootConfigurator root = ExtensionList.lookupSingleton(CredentialsRootConfigurator.class);

    CNode node = root.describe(root.getTargetComponent(context), context);
    assertNotNull(node);
    final Mapping mapping = node.asMapping();

    Mapping fileCredential = mapping.get("system")
        .asMapping()
        .get("domainCredentials")
        .asSequence().get(0)
        .asMapping().get("credentials")
        .asSequence().get(2)
        .asMapping().get("file").asMapping();

    assertThat(fileCredential.getScalarValue("scope"), is("GLOBAL"));
    assertThat(fileCredential.getScalarValue("id"), is("secret-file"));
    assertThat(fileCredential.getScalarValue("fileName"), is("mysecretfile.txt"));
    assertThat(fileCredential.getScalarValue("secretBytes"), not("WJjZAo="));
}
 
Example #5
Source File: CredentialsTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@ConfiguredWithCode("GlobalCredentials.yml")
@Test
public void testGlobalScopedCredentials() {
    List<StandardUsernamePasswordCredentials> creds = CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class,Jenkins.getInstanceOrNull(), null, Collections.emptyList());
    assertThat(creds.size(), is(1));
    assertEquals("user1", creds.get(0).getId());
    assertEquals("Administrator", creds.get(0).getUsername());
    assertEquals("secretPassword", creds.get(0).getPassword().getPlainText());

    List<BasicSSHUserPrivateKey> creds2 = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class,Jenkins.getInstanceOrNull(), null, Collections.emptyList());
    assertThat(creds2.size(), is(1));
    BasicSSHUserPrivateKey basicSSHUserPrivateKey = creds2.get(0);
    assertEquals("agentuser", basicSSHUserPrivateKey.getUsername());
    assertEquals("password", basicSSHUserPrivateKey.getPassphrase().getPlainText());
    assertEquals("ssh private key used to connect ssh slaves", basicSSHUserPrivateKey.getDescription());
    assertThat(basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().size(), is(1));
    String directKey = basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().get(0);
    assertThat(directKey, is("sp0ds9d+skkfjf"));

}
 
Example #6
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@Env(name = "PROXY_HOST", value = "proxyhost")
@Env(name = "PROXY_PORT", value = "80")
@Env(name = "PROXY_USER", value = "proxy_user")
@Env(name = "PROXY_PASSWORD", value = "proxy_password")
@Env(name = "PROXY_NOPROXY", value = "external.host")
@Env(name = "PROXY_TEST_URL", value = "http://google.com")
@ConfiguredWithCode("ProxyWithSecrets.yml")
public void shouldSetProxyWithSecretInFields() {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.name, "proxyhost");
    assertEquals(proxy.port, 80);

    assertEquals(proxy.getUserName(), "proxy_user");
    assertThat(proxy.getSecretPassword(), hasPlainText("proxy_password"));
    assertEquals(proxy.noProxyHost, "external.host");
    assertEquals(proxy.getTestUrl(), "http://google.com");
}
 
Example #7
Source File: ConfigurationAsCodeTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("multi-line1.yml")
public void multiline_literal_stays_literal_in_export() throws Exception {
    assertEquals("Welcome to our build server.\n\n"
            + "This Jenkins is 100% configured and managed 'as code'.\n",
        j.jenkins.getSystemMessage());

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CNode systemMessage = getJenkinsRoot(context).get("systemMessage");
    String exported = toYamlString(systemMessage);
    String expected = "|\n"
        + "  Welcome to our build server.\n\n"
        + "  This Jenkins is 100% configured and managed 'as code'.\n";
    assertThat(exported, is(expected));
}
 
Example #8
Source File: ConfigurationAsCodeTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("multi-line2.yml")
public void string_to_literal_in_export() throws Exception {
    assertEquals("Welcome to our build server.\n\n"
            + "This Jenkins is 100% configured and managed 'as code'.\n",
        j.jenkins.getSystemMessage());

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    CNode systemMessage = getJenkinsRoot(context).get("systemMessage");
    String exported = toYamlString(systemMessage);
    String expected = "|\n"
        + "  Welcome to our build server.\n\n"
        + "  This Jenkins is 100% configured and managed 'as code'.\n";
    assertThat(exported, is(expected));
}
 
Example #9
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));
}
 
Example #10
Source File: BackwardCompatibilityTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("BackwardCompatibilityTest.yml")
public void should_accept_legacy_symbols_on_descriptors() throws Exception {

    final List<Node> nodes = j.jenkins.getNodes();
    System.out.println(nodes);
    assertNotNull(j.jenkins.getNode("foo"));
    assertNotNull(j.jenkins.getNode("bar"));
    assertNotNull(j.jenkins.getNode("qix"));
    // see # see https://github.com/jenkinsci/jenkins/pull/3475
    // assertNotNull(j.jenkins.getNode("zot"));

    final List<ObsoleteConfigurationMonitor.Error> errors = ObsoleteConfigurationMonitor.get()
        .getErrors();
    String expected = format("'DumbSlave' is obsolete, please use '%s'",
        agentNameToCompareAgainst());
    assertEquals(expected, errors.get(0).message);
}
 
Example #11
Source File: GitLabConnectionConfigAsCodeTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
@ConfiguredWithCode("global-config.yml")
public void export_configuration() throws Exception {
    GitLabConnectionConfig globalConfiguration = GitLabConnectionConfig.get();

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final Configurator c = context.lookupOrFail(GitLabConnectionConfig.class);

    @SuppressWarnings("unchecked")
    CNode node = c.describe(globalConfiguration, context);
    assertNotNull(node);
    String exported = toYamlString(node);
    String expected = toStringFromYamlFile(this, "global-config-expected.yml");
    assertEquals(expected, exported);
}
 
Example #12
Source File: SSHCredentialsTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("SSHCredentialsTest.yml")
@Issue("SECURITY-1279")
public void shouldNotExportOrLogCredentials() throws Exception {
    StandardUsernamePasswordCredentials creds = getCredentials(StandardUsernamePasswordCredentials.class);
    assertEquals(CREDENTIALS_PASSWORD, creds.getPassword().getPlainText());
    assertNotInLog(logging, CREDENTIALS_PASSWORD);

    BasicSSHUserPrivateKey certKey = getCredentials(BasicSSHUserPrivateKey.class);
    // JENKINS-50181 made getPrivateKey always append a trailing newline.
    assertEquals(PRIVATE_KEY + "\n", certKey.getPrivateKey());
    assertNotInLog(logging, PRIVATE_KEY);

    // Verify that the password does not get exported
    String exportedConfig = j.exportToString(false);
    assertThat("There should be no password in the exported YAML", exportedConfig, not(containsString(CREDENTIALS_PASSWORD)));
    assertThat("There should be no private key in the exported YAML", exportedConfig, not(containsString(PRIVATE_KEY)));
}
 
Example #13
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 6 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(VAULT_APPROLE_FILE)
@Envs({
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV2_AUTH_TEST),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "2")
})
public void kv2WithApproleWithReauth() throws Exception {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("auth-test"));

    try {
        // Update secret
        runCommand(vaultContainer, "vault", "kv", "put", VAULT_PATH_KV2_AUTH_TEST,
            "key1=re-auth-test");
    } catch (InterruptedException e) {
        LOGGER.log(Level.WARNING, "Test got interrupted", e);
        assert false;
    } catch (IOException eio) {
        LOGGER.log(Level.WARNING, "Could not update vault secret for test", eio);
        assert false;
    }

    // SecretSource.init is normally called on configure
    context.getSecretSources().forEach(SecretSource::init);
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("re-auth-test"));
}
 
Example #14
Source File: GlobalLibrariesTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Issue("JENKINS-57557")
@Test
@ConfiguredWithCode("GlobalLibrariesGitHubTest.yml")
public void configure_global_library_using_github() throws Exception {
    assertEquals(1, GlobalLibraries.get().getLibraries().size());
    final LibraryConfiguration library = GlobalLibraries.get().getLibraries().get(0);
    assertEquals("jenkins-pipeline-lib", library.getName());
    final SCMSourceRetriever retriever = (SCMSourceRetriever) library.getRetriever();
    final GitHubSCMSource scm = (GitHubSCMSource) retriever.getScm();
    assertEquals("e43d6600-ba0e-46c5-8eae-3989bf654055", scm.getId());
    assertEquals("jenkins-infra", scm.getRepoOwner());
    assertEquals("pipeline-library", scm.getRepository());
    assertEquals(3, scm.getTraits().size());
    final BranchDiscoveryTrait branchDiscovery = (BranchDiscoveryTrait) scm.getTraits().get(0);
    assertEquals(1, branchDiscovery.getStrategyId());
    final OriginPullRequestDiscoveryTrait prDiscovery = (OriginPullRequestDiscoveryTrait) scm.getTraits().get(1);
    assertEquals(2, prDiscovery.getStrategyId());
    final ForkPullRequestDiscoveryTrait forkDiscovery = (ForkPullRequestDiscoveryTrait) scm.getTraits().get(2);
    assertEquals(3, forkDiscovery.getStrategyId());
    assertThat(forkDiscovery.getTrust(), instanceOf(TrustPermission.class));
}
 
Example #15
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@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"));
}
 
Example #16
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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);
}
 
Example #17
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(VAULT_APPROLE_FILE)
@Envs({
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV1_1 + "," + VAULT_PATH_KV1_2),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "1")
})
public void kv1WithApprole() {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("123"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV1_1 + "/key1}"), equalTo("123"));
}
 
Example #18
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(value = {VAULT_AGENT_FILE, VAULT_APPROLE_FILE})
@Envs({
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV1_1 + "," + VAULT_PATH_KV1_2),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "1")
})
public void kv1WithAgent() {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("123"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV1_1 + "/key1}"), equalTo("123"));
}
 
Example #19
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(VAULT_APPROLE_FILE)
@Envs({
    @Env(name = "CASC_VAULT_APPROLE", value = "1234"),
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV2_1),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "2")
})
public void kv2WithWrongApprole() {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo(""));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV2_1 + "/key1}"), equalTo(""));
}
 
Example #20
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(VAULT_APPROLE_FILE)
@Envs({
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV2_1 + "," + VAULT_PATH_KV2_2),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "2")
})
public void kv2WithApproleMultipleKeys() {
    assertThat(SecretSourceResolver.resolve(context, "${key2}"), equalTo("456"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV2_1 + "/key2}"), equalTo("456"));
    assertThat(SecretSourceResolver.resolve(context, "${key3}"), equalTo("789"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV2_2 + "/key3}"), equalTo("789"));
}
 
Example #21
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@EnvsFromFile(VAULT_APPROLE_FILE)
@Envs({
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV2_1 + "," + VAULT_PATH_KV2_2),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "2")
})
public void kv2WithApprole() throws ConfiguratorException {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("123"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV2_1 + "/key1}"), equalTo("123"));
}
 
Example #22
Source File: VaultSecretSourceTest.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("vault.yml")
@Envs({
    @Env(name = "CASC_VAULT_USER", value = VAULT_USER),
    @Env(name = "CASC_VAULT_PW", value = VAULT_PW),
    @Env(name = "CASC_VAULT_PATHS", value = VAULT_PATH_KV1_1 + "," + VAULT_PATH_KV1_2),
    @Env(name = "CASC_VAULT_ENGINE_VERSION", value = "1")
})
public void kv1WithUser() {
    assertThat(SecretSourceResolver.resolve(context, "${key1}"), equalTo("123"));
    assertThat(SecretSourceResolver.resolve(context, "${" + VAULT_PATH_KV1_1 + "/key1}"), equalTo("123"));
}
 
Example #23
Source File: AdminWhitelistRuleConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_disabled.yml")
public void checkM2ASecurityKillSwitch_enabled() {
    final Jenkins jenkins = Jenkins.get();
    AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
    Assert.assertTrue("MasterToAgent Security should be enabled", rule.getMasterKillSwitch());
}
 
Example #24
Source File: AdminWhitelistRuleConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("Issue #28")
@ConfiguredWithCode("AdminWhitelistRuleConfigurator/Agent2MasterSecurityKillSwitch_enabled.yml")
public void checkM2ASecurityKillSwitch_disabled() {
    final Jenkins jenkins = Jenkins.get();
    AdminWhitelistRule rule = jenkins.getInjector().getInstance(AdminWhitelistRule.class);
    Assert.assertFalse("MasterToAgent Security should be disabled", rule.getMasterKillSwitch());
}
 
Example #25
Source File: JenkinsConfiguratorCloudSupportTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("JenkinsConfiguratorCloudSupportTest.yml")
public void should_export_only_static_nodes() throws Exception {
    j.jenkins.addNode(new Cloud1PretendSlave());

    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final CNode configNode = getJenkinsRoot(context).get("nodes");

    final String yamlConfig = toYamlString(configNode);
    assertThat(yamlConfig, containsString("name: \"agent1\""));
    assertThat(yamlConfig, containsString("name: \"agent2\""));
    assertThat(yamlConfig, not(containsString("name: \"testCloud\"")));
}
 
Example #26
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("HeteroDescribable.yml")
public void jenkins_abstract_describable_attributes() throws Exception {
    final Jenkins jenkins = Jenkins.get();
    assertTrue(jenkins.getSecurityRealm() instanceof HudsonPrivateSecurityRealm);
    assertTrue(jenkins.getAuthorizationStrategy() instanceof FullControlOnceLoggedInAuthorizationStrategy);
    assertFalse(((FullControlOnceLoggedInAuthorizationStrategy) jenkins.getAuthorizationStrategy()).isAllowAnonymousRead());
}
 
Example #27
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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"));
}
 
Example #28
Source File: ProxyConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@Env(name = "PROXY_USER", value = "proxy_user")
@Env(name = "PROXY_PASSWORD", value = "proxy_password")
@ConfiguredWithCode("ProxyWithSecrets.yml")
@Issue("SECURITY-1303") // Fixed in 1.20
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");
}
 
Example #29
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("ConfigureLabels.yml")
public void shouldExportLabelAtoms() throws Exception {
    DescribableList properties = Jenkins.get().getLabelAtom("label1").getProperties();
    properties.add(new TestProperty(1));

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    ConfigurationAsCode.get().export(out);
    final String exported = out.toString();

    String content = FileUtils.readFileToString(new File(getClass().getResource("ExpectedLabelsConfiguration.yml").toURI()), "UTF-8");
    assertThat(exported, containsString(content));
}
 
Example #30
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@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);
}