use of com.thoughtworks.go.plugin.access.scm.SCMConfigurations in project gocd by gocd.
the class PluginInfoBuilderTest method setUp.
@Before
public void setUp() {
initMocks(this);
githubDescriptor = new GoPluginDescriptor("github.oauth", "version1", new GoPluginDescriptor.About("Github OAuth Plugin", "1.0", null, null, null, null), null, null, false);
emailNotifier = new GoPluginDescriptor("email.notifier", "version1", new GoPluginDescriptor.About("Email Notifier", "1.0", null, null, null, null), null, null, false);
yumPoller = new GoPluginDescriptor("yum.poller", "version1", new GoPluginDescriptor.About("Yum Poller", "1.0", null, null, null, null), null, null, false);
xunitConvertor = new GoPluginDescriptor("xunit.convertor", "version1", new GoPluginDescriptor.About("Xunit Convertor", "1.0", null, null, null, null), null, null, false);
githubPR = new GoPluginDescriptor("github.pr", "version1", new GoPluginDescriptor.About("Github PR", "1.0", null, null, null, null), null, null, false);
dockerElasticAgentPlugin = new GoPluginDescriptor("cd.go.elastic-agent.docker", "1.0", new GoPluginDescriptor.About("GoCD Docker Elastic Agent Plugin", "1.0", null, null, null, null), null, null, false);
ldapAuthPlugin = new GoPluginDescriptor("cd.go.authorization.ldap", "1.0", new GoPluginDescriptor.About("GoCD LDAP Plugin", "1.0", null, null, null, null), null, null, false);
JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "task display value";
}
@Override
public String template() {
return "pluggable task view template";
}
};
when(authenticationPluginRegistry.getAuthenticationPlugins()).thenReturn(new HashSet<>(Arrays.asList("github.oauth")));
when(notificationPluginRegistry.getNotificationPlugins()).thenReturn(new HashSet<>(Arrays.asList("email.notifier")));
when(elasticPluginConfigMetadataStore.getPlugins()).thenReturn(new ArrayList<>(Arrays.asList(dockerElasticAgentPlugin)));
when(authorizationPluginConfigMetadataStore.getPlugins()).thenReturn(new ArrayList<>(Arrays.asList(ldapAuthPlugin)));
when(jsonBasedPluggableTask.view()).thenReturn(taskView);
when(manager.getPluginDescriptorFor("github.oauth")).thenReturn(githubDescriptor);
when(manager.getPluginDescriptorFor("email.notifier")).thenReturn(emailNotifier);
when(manager.getPluginDescriptorFor("yum.poller")).thenReturn(yumPoller);
when(manager.getPluginDescriptorFor("xunit.convertor")).thenReturn(xunitConvertor);
when(manager.getPluginDescriptorFor("github.pr")).thenReturn(githubPR);
when(manager.getPluginDescriptorFor("cd.go.elastic-agent.docker")).thenReturn(dockerElasticAgentPlugin);
when(manager.getPluginDescriptorFor(ldapAuthPlugin.id())).thenReturn(ldapAuthPlugin);
MetadataStoreHelper.clear();
PackageMetadataStore.getInstance().addMetadataFor(yumPoller.id(), new PackageConfigurations());
PluggableTaskConfigStore.store().setPreferenceFor("xunit.convertor", new TaskPreference(jsonBasedPluggableTask));
SCMMetadataStore.getInstance().setPreferenceFor("github.pr", new SCMPreference(new SCMConfigurations(), mock(SCMView.class)));
pluginViewModelBuilder = new PluginInfoBuilder(authenticationPluginRegistry, notificationPluginRegistry, elasticPluginConfigMetadataStore, authorizationPluginConfigMetadataStore, manager);
}
use of com.thoughtworks.go.plugin.access.scm.SCMConfigurations in project gocd by gocd.
the class SCMViewModelBuilderTest method setUp.
@Before
public void setUp() {
initMocks(this);
builder = new SCMViewModelBuilder(manager);
githubPR = new GoPluginDescriptor("github.pr", "version1", new GoPluginDescriptor.About("Github PR", "1.0", null, null, null, null), null, null, false);
stashPR = new GoPluginDescriptor("stash.pr", "version1", new GoPluginDescriptor.About("Stash PR", "2.0", null, null, null, null), null, null, false);
SCMConfigurations configurations = new SCMConfigurations();
configurations.add(new SCMConfiguration("key1"));
configurations.add(new SCMConfiguration("key2"));
SCMView view = new SCMView() {
@Override
public String displayValue() {
return "SCM Display Value";
}
@Override
public String template() {
return "scm view template";
}
};
preference = new SCMPreference(configurations, view);
SCMMetadataStore.getInstance().setPreferenceFor("github.pr", preference);
SCMMetadataStore.getInstance().setPreferenceFor("stash.pr", preference);
}
use of com.thoughtworks.go.plugin.access.scm.SCMConfigurations in project gocd by gocd.
the class SCM method setPluginConfigurationAttributes.
protected void setPluginConfigurationAttributes(Map attributes) {
SCMConfigurations scmConfigurations = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginConfiguration.getId());
if (scmConfigurations == null) {
throw new RuntimeException("metadata unavailable for plugin: " + pluginConfiguration.getId());
}
for (SCMConfiguration scmConfiguration : scmConfigurations.list()) {
String key = scmConfiguration.getKey();
if (attributes.containsKey(key)) {
if (configuration.getProperty(key) == null) {
configuration.addNewConfiguration(scmConfiguration.getKey(), scmConfiguration.getOption(Property.SECURE));
}
configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key)));
configuration.getProperty(key).handleSecureValueConfiguration(scmConfiguration.getOption(Property.SECURE));
}
}
}
use of com.thoughtworks.go.plugin.access.scm.SCMConfigurations in project gocd by gocd.
the class SCMsTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.
@Test
void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
String pluginId = "plugin-id";
SCMPropertyConfiguration scmConfiguration = new SCMPropertyConfiguration();
scmConfiguration.add(new SCMProperty("k1"));
scmConfiguration.add(new SCMProperty("k2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
SCMMetadataStore.getInstance().addMetadataFor(pluginId, new SCMConfigurations(scmConfiguration), null);
SCM scm1 = SCMMother.create("1", "scm1", pluginId, "1.0", new Configuration(create("k1", false, "v1")));
SCM scm2 = SCMMother.create("2", "scm2", pluginId, "1.0", new Configuration(create("k1", false, "v2")));
SCM scm3 = SCMMother.create("3", "scm3", pluginId, "1.0", new Configuration(create("k1", false, "v1")));
SCM scm4 = SCMMother.create("4", "scm4", pluginId, "1.0", new Configuration(create("k1", false, "V1")));
SCM scm5 = SCMMother.create("5", "scm5", pluginId, "1.0", new Configuration(create("k1", false, "v1"), create("k2", false, "v2")));
SCMs scms = new SCMs(scm1, scm2, scm3, scm4, scm5);
scms.validate(null);
assertThat(scm2.getFingerprint().equals(scm1.getFingerprint())).isFalse();
assertThat(scm3.getFingerprint().equals(scm1.getFingerprint())).isTrue();
assertThat(scm4.getFingerprint().equals(scm1.getFingerprint())).isFalse();
assertThat(scm5.getFingerprint().equals(scm1.getFingerprint())).isTrue();
String expectedErrorMessage = "Cannot save SCM, found duplicate SCMs. scm1, scm3, scm5";
assertThat(scm1.errors().getAllOn(SCM.SCM_ID)).isEqualTo(asList(expectedErrorMessage));
assertThat(scm2.errors().getAllOn(SCM.SCM_ID)).isEmpty();
assertThat(scm3.errors().getAllOn(SCM.SCM_ID)).isEqualTo(asList(expectedErrorMessage));
assertThat(scm4.errors().getAllOn(SCM.SCM_ID)).isEmpty();
assertThat(scm5.errors().getAllOn(SCM.SCM_ID)).isEqualTo(asList(expectedErrorMessage));
}
use of com.thoughtworks.go.plugin.access.scm.SCMConfigurations in project gocd by gocd.
the class SCMTest method shouldMakeConfigurationSecureBasedOnMetadata.
@Test
void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
GoCipher goCipher = new GoCipher();
// meta data of SCM
SCMConfigurations scmConfiguration = new SCMConfigurations();
scmConfiguration.add(new SCMConfiguration("key1").with(SECURE, true));
scmConfiguration.add(new SCMConfiguration("key2").with(SECURE, false));
SCMMetadataStore.getInstance().addMetadataFor("plugin-id", scmConfiguration, null);
/*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);
SCM scm = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(secureProperty, nonSecureProperty));
scm.applyPluginMetadata();
// assert SCM properties
assertThat(secureProperty.isSecure()).isTrue();
assertThat(secureProperty.getEncryptedConfigurationValue()).isNotNull();
assertThat(secureProperty.getEncryptedValue()).isEqualTo(goCipher.encrypt("value1"));
assertThat(nonSecureProperty.isSecure()).isFalse();
assertThat(nonSecureProperty.getValue()).isEqualTo("value2");
}
Aggregations