Search in sources :

Example 11 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class SvnMaterialConfigTest method shouldValidateWhetherTheEncryptedPasswordIsCorrect.

@Test
public void shouldValidateWhetherTheEncryptedPasswordIsCorrect() {
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(new UrlArgument("foo/bar"), "", "encryptedPassword", new GoCipher(), null, false, "folder");
    svnMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(svnMaterialConfig.errors().on("encryptedPassword"), is("Encrypted password value for svn material with url 'foo/bar' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 12 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class SvnMaterialConfigTest method shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided.

@Test
public void shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided() {
    SvnMaterialConfig svnMaterialConfig = new SvnMaterialConfig(new UrlArgument("foo/bar"), "password", "encryptedPassword", new GoCipher(), null, false, "folder");
    svnMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(svnMaterialConfig.errors().on("password"), is("You may only specify `password` or `encrypted_password`, not both!"));
    assertThat(svnMaterialConfig.errors().on("encryptedPassword"), is("You may only specify `password` or `encrypted_password`, not both!"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 13 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldMigrateServerMailhostEncryptedPasswordWithNewlineAndSpaces_XslMigrationFrom88To90.

@Test
public void shouldMigrateServerMailhostEncryptedPasswordWithNewlineAndSpaces_XslMigrationFrom88To90() throws Exception {
    String plainText = "something";
    String encryptedValue = new GoCipher().encrypt(plainText);
    String encryptedValueWithWhitespaceAndNewline = new StringBuilder(encryptedValue).insert(2, "\r\n" + "                        ").toString();
    String content = config("<server artifactsdir='artifacts'>\n" + "    <mailhost hostname='host' port='25' username='user' encryptedPassword='" + encryptedValueWithWhitespaceAndNewline + "' tls='false' from='user@domain.com' admin='admin@domain.com' />\n" + "  </server>", 88);
    CruiseConfig config = ConfigMigrator.loadWithMigration(content).config;
    assertThat(config.server().mailHost().getPassword(), is(plainText));
    assertThat(config.server().mailHost().getEncryptedPassword(), is(encryptedValue));
    assertThat(config.server().mailHost().getHostName(), is("host"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 14 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldUpdateServerConfig.

@Test
public void shouldUpdateServerConfig() throws InvalidCipherTextException {
    MailHost mailHost = new MailHost("boo", 1, "username", "password", new GoCipher().encrypt("password"), true, true, "from@from.com", "admin@admin.com", new GoCipher());
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    serverConfigService.updateServerConfig(mailHost, "newArtifactsDir", 10.0, 20.0, "42", true, "http://site_url", "https://secure_site_url", "gist-repo/folder", result, goConfigDao.md5OfConfigFile());
    assertThat(goConfigService.getMailHost(), is(mailHost));
    assertThat(goConfigService.serverConfig().artifactsDir(), is("newArtifactsDir"));
    assertThat(goConfigService.serverConfig().getSiteUrl().getUrl(), is("http://site_url"));
    assertThat(goConfigService.serverConfig().getSecureSiteUrl().getUrl(), is("https://secure_site_url"));
    assertThat(goConfigService.serverConfig().getJobTimeout(), is("42"));
    assertThat(goConfigService.serverConfig().getPurgeStart(), is(10.0));
    assertThat(goConfigService.serverConfig().getPurgeUpto(), is(20.0));
    assertThat(goConfigService.serverConfig().getCommandRepositoryLocation(), is("gist-repo/folder"));
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 15 with GoCipher

use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.

the class ServerConfigServiceIntegrationTest method shouldNotUpdateWhenPortIsInvalid.

@Test
public void shouldNotUpdateWhenPortIsInvalid() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    serverConfigService.updateServerConfig(new MailHost("boo", -1, "username", "password", true, true, "from@from.com", "admin@admin.com"), "artifacts", null, null, "42", true, "http://site_url", "https://secure_site_url", "default", result, goConfigDao.md5OfConfigFile());
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Invalid port."));
    assertThat(goConfigService.getMailHost(), is(new MailHost(new GoCipher())));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)196 Test (org.junit.jupiter.api.Test)117 Test (org.junit.Test)57 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)30 ArrayList (java.util.ArrayList)23 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)22 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)19 HashMap (java.util.HashMap)19 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)17 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)13 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)13 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)13 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)11 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)10 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)10 File (java.io.File)9 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)8 TfsMaterialConfig (com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig)8 Configuration (com.thoughtworks.go.domain.config.Configuration)8