use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldConvertPluggableSCMMaterialToJsonFormatToBeStoredInDb.
@Test
public void shouldConvertPluggableSCMMaterialToJsonFormatToBeStoredInDb() {
GoCipher cipher = new GoCipher();
ConfigurationProperty secureSCMProperty = new ConfigurationProperty(new ConfigurationKey("secure-key"), null, new EncryptedConfigurationValue("hnfcyX5dAvd82AWUyjfKCQ\u003d\u003d"), cipher);
ConfigurationProperty scmProperty = new ConfigurationProperty(new ConfigurationKey("non-secure-key"), new ConfigurationValue("value"), null, cipher);
SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(secureSCMProperty, scmProperty));
PluggableSCMMaterial pluggableSCMMaterial = new PluggableSCMMaterial();
pluggableSCMMaterial.setSCMConfig(scmConfig);
String json = JsonHelper.toJsonString(pluggableSCMMaterial);
String expected = "{\"scm\":{\"plugin\":{\"id\":\"plugin-id\",\"version\":\"1.0\"},\"config\":[{\"configKey\":{\"name\":\"secure-key\"},\"encryptedConfigValue\":{\"value\":\"hnfcyX5dAvd82AWUyjfKCQ\\u003d\\u003d\"}},{\"configKey\":{\"name\":\"non-secure-key\"},\"configValue\":{\"value\":\"value\"}}]}}";
assertThat(json, is(expected));
assertThat(JsonHelper.fromJson(expected, PluggableSCMMaterial.class), is(pluggableSCMMaterial));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteMultipleSearchBases.
@Test
public void shouldWriteMultipleSearchBases() throws Exception {
BaseConfig base1 = new BaseConfig("base1");
BaseConfig base2 = new BaseConfig("base2");
BasesConfig basesConfig = new BasesConfig(base1, base2);
LdapConfig ldapConfig = new LdapConfig("url", "managerDn", "managerPassword", "managerPassword", false, basesConfig, "filter");
SecurityConfig securityConfig = new SecurityConfig(ldapConfig, new PasswordFileConfig("some_path"), false);
ServerConfig serverConfig = new ServerConfig(securityConfig, new MailHost(new GoCipher()));
CruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setServerConfig(serverConfig);
xmlWriter.write(cruiseConfig, output, false);
GoConfigHolder holder = xmlLoader.loadConfigHolder(output.toString());
BasesConfig actualBasesConfig = holder.config.server().security().ldapConfig().getBasesConfig();
assertThat(actualBasesConfig.size(), is(2));
assertThat(actualBasesConfig, hasItems(base1, base2));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SecurityConfigTest method security.
public static SecurityConfig security(LdapConfig ldap, PasswordFileConfig pwordFile, AdminsConfig admins) {
ldap = ldap == null ? new LdapConfig(new GoCipher()) : ldap;
pwordFile = pwordFile == null ? new PasswordFileConfig() : pwordFile;
SecurityConfig security = new SecurityConfig(ldap, pwordFile, true, admins);
for (Role role : DEFAULT_ROLES) {
security.addRole(role);
}
return security;
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SecurityConfigTest method shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull.
@Test
public void shouldNotUpdateManagerPasswordForLDAPIfNotChangedOrNull() throws InvalidCipherTextException {
SecurityConfig securityConfig = new SecurityConfig();
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "p", null, true, new BasesConfig(new BaseConfig("")), ""));
assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
String encryptedPassword = new GoCipher().encrypt("p");
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "notP", null, false, new BasesConfig(new BaseConfig("")), ""));
assertThat(ReflectionUtil.getField(securityConfig.ldapConfig(), "managerPassword"), is(""));
assertThat(securityConfig.ldapConfig().managerPassword(), is("p"));
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(encryptedPassword));
securityConfig.modifyLdap(new LdapConfig("ldap://uri", "dn", "", null, true, new BasesConfig(new BaseConfig("")), ""));
assertThat(securityConfig.ldapConfig().managerPassword(), is(""));
assertThat(securityConfig.ldapConfig().getEncryptedManagerPassword(), is(nullValue()));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ServerConfigServiceIntegrationTest method shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged.
@Test
public void shouldUseTheEncryptedPasswordWhenPasswordIsNotChanged() throws InvalidCipherTextException {
String encryptedPassword = new GoCipher().encrypt("encrypted_password");
LdapConfig ldapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, encryptedPassword, false, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
DefaultSpringSecurityContextSource source = serverConfigService.ldapContextSource(ldapConfig);
assertThat(source.getAuthenticationSource().getCredentials(), is("encrypted_password"));
}
Aggregations