use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class MaterialConfigsMother method svnMaterialConfig.
public static SvnMaterialConfig svnMaterialConfig(String svnUrl, String folder, boolean autoUpdate) {
SvnMaterialConfig materialConfig = new SvnMaterialConfig(new UrlArgument(svnUrl), "user", "pass", true, new GoCipher(), autoUpdate, new Filter(new IgnoredFiles("*.doc")), false, folder, new CaseInsensitiveString("svn-material"));
materialConfig.setPassword("pass");
return materialConfig;
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ConfigCipherUpdaterTest method shouldMigrateEncryptedManagerPasswordsEncryptedWithFlawedCipher.
@Test
public void shouldMigrateEncryptedManagerPasswordsEncryptedWithFlawedCipher() throws Exception {
String originalConfig = FileUtils.readFileToString(originalConfigFile, UTF_8);
assertThat(originalConfig.contains("encryptedPassword=\"" + passwordEncryptedWithFlawedCipher + "\""), is(true));
updater.migrate();
File copyOfOldConfig = new File(systemEnvironment.getConfigDir(), "cipher.original." + timestamp);
assertThat(copyOfOldConfig.exists(), is(true));
assertThat(FileUtils.readFileToString(copyOfOldConfig, UTF_8).equals(ConfigCipherUpdater.FLAWED_VALUE), is(true));
assertThat(FileUtils.readFileToString(systemEnvironment.getCipherFile(), UTF_8).equals(ConfigCipherUpdater.FLAWED_VALUE), is(false));
File editedConfigFile = new File(systemEnvironment.getCruiseConfigFile());
String editedConfig = FileUtils.readFileToString(editedConfigFile, UTF_8);
assertThat(editedConfig.contains("encryptedManagerPassword=\"" + passwordEncryptedWithFlawedCipher + "\""), is(false));
CruiseConfig config = magicalGoConfigXmlLoader.loadConfigHolder(editedConfig).config;
SecurityAuthConfig migratedLdapConfig = config.server().security().securityAuthConfigs().get(0);
assertThat(migratedLdapConfig.getProperty("Password").getValue(), is(password));
assertThat(migratedLdapConfig.getProperty("Password").getEncryptedValue(), is(new GoCipher().encrypt(password)));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class GoSmtpMailSenderTest method shouldUseTheEncryptedPasswordIfThePasswordIsNotChanged.
@Test
public void shouldUseTheEncryptedPasswordIfThePasswordIsNotChanged() throws InvalidCipherTextException {
String encryptedPassword = new GoCipher().encrypt("encrypted_password");
MailHost mailHost = new MailHost(hostName, 25, "smtpuser", "password", encryptedPassword, false, true, "cruise@me.com", "jez@me.com");
GoMailSender sender = GoSmtpMailSender.createSender(mailHost);
assertThat(sender, is(new BackgroundMailSender(new GoSmtpMailSender(hostName, 25, "smtpuser", "encrypted_password", true, "cruise@me.com", "jez@me.com"))));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SvnMaterialTest method shouldNotDecryptSvnPasswordIfPasswordIsNotNull.
@Test
public void shouldNotDecryptSvnPasswordIfPasswordIsNotNull() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
SvnMaterial material = new SvnMaterial("/foo", "username", "password", false, mockGoCipher);
material.ensureEncrypted();
when(mockGoCipher.encrypt("new_password")).thenReturn("new_encrypted");
material.setPassword("new_password");
when(mockGoCipher.decrypt("new_encrypted")).thenReturn("new_password");
assertThat(material.getPassword(), is("new_password"));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class SvnMaterialTest method shouldErrorOutIfEncryptionFails.
@Test
public void shouldErrorOutIfEncryptionFails() throws Exception {
GoCipher mockGoCipher = mock(GoCipher.class);
when(mockGoCipher.encrypt("password")).thenThrow(new InvalidCipherTextException("exception"));
try {
new SvnMaterial("/foo", "username", "password", false, mockGoCipher);
fail("Should have thrown up");
} catch (Exception e) {
assertThat(e.getMessage(), is("Password encryption failed. Please verify your cipher key."));
}
}
Aggregations