Search in sources :

Example 91 with GoCipher

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;
}
Also used : HgUrlArgument(com.thoughtworks.go.util.command.HgUrlArgument) UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 92 with GoCipher

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)));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) File(java.io.File) Test(org.junit.Test)

Example 93 with GoCipher

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"))));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 94 with GoCipher

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"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Test(org.junit.Test)

Example 95 with GoCipher

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."));
    }
}
Also used : InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)149 Test (org.junit.Test)128 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)36 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HashMap (java.util.HashMap)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)10 Configuration (com.thoughtworks.go.domain.config.Configuration)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)8 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)7 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)7 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)7 Map (java.util.Map)7 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)6 File (java.io.File)6