Search in sources :

Example 1 with GoConfigHolder

use of com.thoughtworks.go.config.GoConfigHolder in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForSCMs.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForSCMs() throws Exception {
    String encryptedValue = new GoCipher().encrypt("secure-two");
    String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + "    <scm id='scm-id' name='name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>plain</key>\n" + "          <value>value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-one</key>\n" + "          <value>secure-value</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>secure-two</key>\n" + "          <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + "        </property>\n" + "      </configuration>\n" + "    </scm>\n" + "  </scms>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <scm ref='scm-id' />\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\">\n" + "           <tasks><ant /></tasks>\n" + "        </job>\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    // meta data of scm
    SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
    scmConfiguration.add(new SCMProperty("plain"));
    scmConfiguration.add(new SCMProperty("secure-one").with(SCMConfiguration.SECURE, true));
    scmConfiguration.add(new SCMProperty("secure-two").with(SCMConfiguration.SECURE, true));
    SCMMetadataStore.getInstance().addMetadataFor("plugin-id", new SCMConfigurations(scmConfiguration), null);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    SCM scmConfig = goConfigHolder.config.getSCMs().first();
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(scmConfig));
    Configuration configuration = pluggableSCMMaterialConfig.getSCMConfig().getConfiguration();
    assertThat(configuration.get(0).getConfigurationValue().getValue(), is("value"));
    assertThat(configuration.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
    assertThat(configuration.get(2).getEncryptedValue(), is(encryptedValue));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SCM(com.thoughtworks.go.domain.scm.SCM) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 2 with GoConfigHolder

use of com.thoughtworks.go.config.GoConfigHolder in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldGenerateSCMIdWhenMissing.

@Test
public void shouldGenerateSCMIdWhenMissing() throws Exception {
    String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'><scms>\n" + SCM_WITH_MISSING_ID + " </scms></cruise>";
    GoConfigHolder configHolder = xmlLoader.loadConfigHolder(xml);
    assertThat(configHolder.config.getSCMs().get(0).getId(), is(notNullValue()));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 3 with GoConfigHolder

use of com.thoughtworks.go.config.GoConfigHolder in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldResolveSCMReferenceElementForAMaterialInConfig.

@Test
public void shouldResolveSCMReferenceElementForAMaterialInConfig() throws Exception {
    String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + "    <scm id='scm-id' name='scm-name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>url</key>\n" + "          <value>http://go</value>\n" + "        </property>\n" + "      </configuration>\n" + "    </scm>\n" + "  </scms>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <scm ref='scm-id' />\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\">\n" + "           <tasks><ant /></tasks>\n" + "        </job>\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(goConfigHolder.config.getSCMs().get(0)));
    assertThat(pluggableSCMMaterialConfig.getFolder(), is(nullValue()));
    assertThat(pluggableSCMMaterialConfig.filter(), is(new Filter()));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Filter(com.thoughtworks.go.config.materials.Filter) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 4 with GoConfigHolder

use of com.thoughtworks.go.config.GoConfigHolder in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldLoadAutoUpdateValueForSCMWhenLoadedFromConfigFile.

@Test
public void shouldLoadAutoUpdateValueForSCMWhenLoadedFromConfigFile() throws Exception {
    String configTemplate = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>" + "<scms>" + "	<scm id='2ef830d7-dd66-42d6-b393-64a84646e557' name='scm-name' autoUpdate='%s' >" + "		<pluginConfiguration id='yum' version='1' />" + "       <configuration>" + "           <property>" + "               <key>SCM_URL</key>" + "               <value>http://fake-scm/git/go-cd</value>" + "               </property>" + "       </configuration>" + "   </scm>" + "</scms>" + "</cruise>";
    String configContent = String.format(configTemplate, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(configContent);
    SCM scm = holder.config.getSCMs().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    assertThat(scm.isAutoUpdate(), is(false));
    configContent = String.format(configTemplate, true);
    holder = xmlLoader.loadConfigHolder(configContent);
    scm = holder.config.getSCMs().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    assertThat(scm.isAutoUpdate(), is(true));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.jupiter.api.Test)

Example 5 with GoConfigHolder

use of com.thoughtworks.go.config.GoConfigHolder in project gocd by gocd.

the class SCMConfigXmlLoaderTest method shouldReadFolderAndFilterForPluggableSCMMaterialConfig.

@Test
public void shouldReadFolderAndFilterForPluggableSCMMaterialConfig() throws Exception {
    String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'>\n" + "<scms>\n" + "    <scm id='scm-id' name='scm-name'>\n" + "		<pluginConfiguration id='plugin-id' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>url</key>\n" + "          <value>http://go</value>\n" + "        </property>\n" + "      </configuration>\n" + "    </scm>\n" + "  </scms>" + "<pipelines group=\"group_name\">\n" + "  <pipeline name=\"new_name\">\n" + "    <materials>\n" + "      <scm ref='scm-id' dest='dest'>\n" + "            <filter>\n" + "                <ignore pattern=\"x\"/>\n" + "                <ignore pattern=\"y\"/>\n" + "            </filter>\n" + "      </scm>\n" + "    </materials>\n" + "    <stage name=\"stage_name\">\n" + "      <jobs>\n" + "        <job name=\"job_name\">\n" + "           <tasks><ant /></tasks>\n" + "        </job>\n" + "      </jobs>\n" + "    </stage>\n" + "  </pipeline>\n" + "</pipelines></cruise>";
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = (PluggableSCMMaterialConfig) pipelineConfig.materialConfigs().get(0);
    assertThat(pluggableSCMMaterialConfig.getSCMConfig(), is(goConfigHolder.config.getSCMs().get(0)));
    assertThat(pluggableSCMMaterialConfig.getFolder(), is("dest"));
    assertThat(pluggableSCMMaterialConfig.filter(), is(new Filter(new IgnoredFiles("x"), new IgnoredFiles("y"))));
}
Also used : GoConfigHolder(com.thoughtworks.go.config.GoConfigHolder) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) Filter(com.thoughtworks.go.config.materials.Filter) IgnoredFiles(com.thoughtworks.go.config.materials.IgnoredFiles) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialConfig(com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 GoConfigHolder (com.thoughtworks.go.config.GoConfigHolder)5 Test (org.junit.jupiter.api.Test)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)3 PluggableSCMMaterialConfig (com.thoughtworks.go.config.materials.PluggableSCMMaterialConfig)3 Filter (com.thoughtworks.go.config.materials.Filter)2 SCM (com.thoughtworks.go.domain.scm.SCM)2 IgnoredFiles (com.thoughtworks.go.config.materials.IgnoredFiles)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 GoCipher (com.thoughtworks.go.security.GoCipher)1