Search in sources :

Example 16 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class PackageDefinitionTest method shouldGetFingerprint.

@Test
public void shouldGetFingerprint() {
    String pluginId = "pluginid";
    PackageConfigurations repositoryConfigurations = new PackageConfigurations();
    repositoryConfigurations.add(new PackageConfiguration("k1", "v1").with(PackageConfiguration.PART_OF_IDENTITY, true));
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations);
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.add(new PackageConfiguration("k2", "v2").with(PackageConfiguration.PART_OF_IDENTITY, true));
    PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations);
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("k1", false, "v1")));
    PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("k2", false, "v2")), repository);
    String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER);
    assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k2=v2<|>k1=v1")));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 17 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class PackageRepositoryTest method shouldMakeConfigurationSecureBasedOnMetadata.

@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
    GoCipher goCipher = new GoCipher();
    /*secure property is set based on metadata*/
    ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
    //meta data of package
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
    /*secure property is set based on metadata*/
    ConfigurationProperty secureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher);
    ConfigurationProperty nonSecureRepoProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher);
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", new Configuration(secureRepoProperty, nonSecureRepoProperty), new Packages(packageDefinition));
    //meta data of repo
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key1").with(SECURE, true));
    repositoryConfiguration.addConfiguration(new PackageConfiguration("key2").with(SECURE, false));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", repositoryConfiguration);
    packageRepository.applyPackagePluginMetadata();
    //assert package properties
    assertThat(secureProperty.isSecure(), is(true));
    assertThat(secureProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureProperty.isSecure(), is(false));
    assertThat(nonSecureProperty.getValue(), is("value2"));
    //assert repository properties
    assertThat(secureRepoProperty.isSecure(), is(true));
    assertThat(secureRepoProperty.getEncryptedConfigurationValue(), is(notNullValue()));
    assertThat(secureRepoProperty.getEncryptedValue(), is(goCipher.encrypt("value1")));
    assertThat(nonSecureRepoProperty.isSecure(), is(false));
    assertThat(nonSecureRepoProperty.getValue(), is("value2"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 18 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists.

@Test
public void shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists() throws Exception {
    com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("PKG-KEY1"));
    RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY1"));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(packageConfiguration));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(repositoryConfiguration));
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id-1' name='name-1'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-1' name='name-1'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "    <repository id='repo-id-2' name='name-2'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>another-repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>another-repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-2' name='name-2'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories>" + "</cruise>";
    try {
        xmlLoader.loadConfigHolder(xml);
        fail("should have thrown duplicate fingerprint exception");
    } catch (GoConfigInvalidException e) {
        assertThat(e.getMessage(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'name-1', Package Name: 'name-1'], [Repo Name: 'name-2', Package Name: 'name-2']"));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 19 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class ScheduledPipelineLoaderIntegrationTest method setupPipelineWithPackageMaterial.

private PipelineConfig setupPipelineWithPackageMaterial(String pipelineName, String stageName, String jobName) {
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("p-id");
    Configuration repoConfig = new Configuration(ConfigurationPropertyMother.create("repo-key1", false, "repo-k1-value"), ConfigurationPropertyMother.create("repo-key2", false, "repo-k2-value"));
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", repoConfig);
    Configuration packageConfig = new Configuration(ConfigurationPropertyMother.create("package-key1", false, "package-key1-value"), ConfigurationPropertyMother.create("package-key2", false, "package-key2-value"));
    PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "package-name", packageConfig, repository);
    packageMaterialConfig.setPackageDefinition(packageDefinition);
    repository.getPackages().add(packageDefinition);
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig(pipelineName, stageName, new MaterialConfigs(packageMaterialConfig), jobName);
    configHelper.addPackageDefinition(packageMaterialConfig);
    configHelper.addPipeline(pipelineConfig);
    PackageConfigurations packageConfigurations = new PackageConfigurations();
    packageConfigurations.add(new PackageConfiguration("package-key1").with(PackageConfiguration.PART_OF_IDENTITY, true));
    packageConfigurations.add(new PackageConfiguration("package-key2").with(PackageConfiguration.PART_OF_IDENTITY, false));
    PackageMetadataStore.getInstance().addMetadataFor(packageMaterialConfig.getPluginId(), packageConfigurations);
    PackageConfigurations configuration = new PackageConfigurations();
    configuration.add(new PackageConfiguration("repo-key1").with(PackageConfiguration.PART_OF_IDENTITY, true));
    configuration.add(new PackageConfiguration("repo-key2").with(PackageConfiguration.PART_OF_IDENTITY, false));
    RepositoryMetadataStore.getInstance().addMetadataFor(packageMaterialConfig.getPluginId(), configuration);
    return pipelineConfig;
}
Also used : SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)

Example 20 with PackageConfiguration

use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.

the class ConfigurationPropertyTest method shouldSetConfigAttributesForNonSecureProperty.

@Test
public void shouldSetConfigAttributesForNonSecureProperty() throws Exception {
    ConfigurationProperty configurationProperty = new ConfigurationProperty();
    HashMap attributes = new HashMap();
    HashMap keyMap = new HashMap();
    keyMap.put("name", "fooKey");
    attributes.put(ConfigurationProperty.CONFIGURATION_KEY, keyMap);
    HashMap valueMap = new HashMap();
    valueMap.put("value", "fooValue");
    attributes.put(ConfigurationProperty.CONFIGURATION_VALUE, valueMap);
    PackageConfigurations metadata = new PackageConfigurations();
    metadata.addConfiguration(new PackageConfiguration("fooKey", null));
    attributes.put(Configuration.METADATA, metadata);
    configurationProperty.setConfigAttributes(attributes, null);
    assertThat(configurationProperty.getConfigurationKey().getName(), is("fooKey"));
    assertThat(configurationProperty.getConfigurationValue().getValue(), is("fooValue"));
}
Also used : HashMap(java.util.HashMap) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Aggregations

PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)23 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)19 Test (org.junit.Test)15 Configuration (com.thoughtworks.go.domain.config.Configuration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 GoCipher (com.thoughtworks.go.security.GoCipher)6 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)4 HashMap (java.util.HashMap)3 ConfigurationHolder (com.thoughtworks.go.config.helper.ConfigurationHolder)2 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)2 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)2 SecureKeyInfoProvider (com.thoughtworks.go.domain.config.SecureKeyInfoProvider)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)2 Map (java.util.Map)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Before (org.junit.Before)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1