@Override public ArtifactStores artifactStores() { return this.cruiseConfig.getArtifactStores(); }
@Test public void addConfigurations_shouldLeaveUserEnteredValuesAsIsIfPluginIsMissing() throws CryptoException { ArtifactMetadataStore.instance().remove("cd.go.s3"); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "storeId"); ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>(); configurationProperties.add(ConfigurationPropertyMother.create("plain", false, "plain")); configurationProperties.add(ConfigurationPropertyMother.create("secure", true, new GoCipher().encrypt("password"))); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("storeId", "cd.go.s3")); pluggableArtifactConfig.addConfigurations(configurationProperties); assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties)); }
@Test public void shouldHandleEncryptionOfConfigProperties() throws CryptoException { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig); 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")); }
@Test public void addConfigurations_shouldSetUserSpecifiedConfigurationAsIs() throws CryptoException { ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "storeId"); ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>(); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain"))); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password") )); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret")))); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("storeId", "cd.go.s3")); pluggableArtifactConfig.addConfigurations(configurationProperties); assertThat(pluggableArtifactConfig.getConfiguration(), is(configurationProperties)); }
@Test public void shouldIgnoreEncryptionOfSecurePropertyIfStoreIdIsNull() { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", null, secureProperty, nonSecureProperty); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig); assertThat(secureProperty.isSecure(), is(false)); assertThat(secureProperty.getValue(), is("value1")); assertThat(nonSecureProperty.isSecure(), is(false)); assertThat(nonSecureProperty.getValue(), is("value2")); }
@Test public void shouldIgnoreEncryptionOfSecurePropertyForInvalidParamSpecification() { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "#{#{invalid}}", secureProperty, nonSecureProperty); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig); assertThat(secureProperty.isSecure(), is(false)); assertThat(secureProperty.getValue(), is("value1")); assertThat(nonSecureProperty.isSecure(), is(false)); assertThat(nonSecureProperty.getValue(), is("value2")); }
@Test public void shouldHandleEncryptionOfConfigPropertiesIfStoreIdIsAValidParam() throws Exception { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("id", "#{storeId}", secureProperty, nonSecureProperty); PluggableArtifactConfig preprocessedPluggableArtifactConfig = new PluggableArtifactConfig("id", "store-id", secureProperty, nonSecureProperty); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig.encryptSecureProperties(cruiseConfig, preprocessedPluggableArtifactConfig); 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")); }
@Test public void shouldIgnoreEncryptionOfSecurePropertyForNonExistentParam() { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig1 = new PluggableArtifactConfig("id", "#{non-existent-param}", secureProperty, nonSecureProperty); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig1.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig1); assertThat(secureProperty.isSecure(), is(false)); assertThat(secureProperty.getValue(), is("value1")); assertThat(nonSecureProperty.isSecure(), is(false)); assertThat(nonSecureProperty.getValue(), is("value2")); }
@Test public void shouldIgnoreEncryptionOfSecurePropertyIfParamsIsUndefined() { GoCipher goCipher = new GoCipher(); ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("key1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("key2", new Metadata(true, false))); when(artifactPluginInfo.getArtifactConfigSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); ConfigurationProperty secureProperty1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty secureProperty2 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, goCipher); ConfigurationProperty nonSecureProperty1 = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); ConfigurationProperty nonSecureProperty2 = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, goCipher); PluggableArtifactConfig pluggableArtifactConfig1 = new PluggableArtifactConfig("id", "#{storeId}", secureProperty1, nonSecureProperty1); PluggableArtifactConfig pluggableArtifactConfig2 = new PluggableArtifactConfig("id", "#{storeId}", secureProperty2, nonSecureProperty2); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.getArtifactStores().add(new ArtifactStore("store-id", "cd.go.s3")); pluggableArtifactConfig1.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig1); pluggableArtifactConfig2.encryptSecureProperties(cruiseConfig, pluggableArtifactConfig2); assertThat(secureProperty1.isSecure(), is(false)); assertThat(secureProperty1.getValue(), is("value1")); assertThat(nonSecureProperty1.isSecure(), is(false)); assertThat(nonSecureProperty1.getValue(), is("value2")); assertThat(secureProperty2.isSecure(), is(false)); assertThat(secureProperty2.getValue(), is("value1")); assertThat(nonSecureProperty2.isSecure(), is(false)); assertThat(nonSecureProperty2.getValue(), is("value2")); }
@Test public void encryptSecureProperties_shouldEncryptSecureProperties() throws CryptoException { ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>(); pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true))); pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false))); when(artifactPluginInfo.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations)); PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job"); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws"); pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactConfigs().add(pluggableArtifactConfig); BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig(); cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig); cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id())); FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3"); ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>(); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain"))); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password"))); configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret")))); ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>(); expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain"))); expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password")))); expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret")))); task.addConfigurations(configurationProperties); task.encryptSecureProperties(cruiseConfig, pipelineConfig, task); assertThat(task.getConfiguration().size(), is(3)); assertThat(task.getConfiguration(), is(expectedConfigurationProperties)); }
cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
private BasicCruiseConfig setupPipelines() { BasicCruiseConfig config = GoConfigMother.configWithPipelines("ancestor", "parent", "child"); config.getArtifactStores().add(new ArtifactStore("cd.go.s3", "cd.go.s3")); PipelineConfig ancestor = config.pipelineConfigByName(new CaseInsensitiveString("ancestor")); ancestor.add(StageConfigMother.stageConfig("stage1", new JobConfigs(new JobConfig("job1"))));