use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class JobXmlViewModelTest method shouldMaskSecureVariables.
@Test
public void shouldMaskSecureVariables() throws IOException, DocumentException {
EnvironmentVariableConfig envVariable = new EnvironmentVariableConfig(null, "stdVariable", "value1", false);
EnvironmentVariableConfig secureEnvVariable = new EnvironmentVariableConfig(new GoCipher(), "secureVariable", "value2", true);
EnvironmentVariablesConfig environmentVariablesConfig = new EnvironmentVariablesConfig();
environmentVariablesConfig.add(envVariable);
environmentVariablesConfig.add(secureEnvVariable);
when(jobPlan.getVariables()).thenReturn(environmentVariablesConfig);
DOMDocument document = (DOMDocument) jobXmlViewModel.toXml(xmlWriterContext);
Assert.assertThat(document.asXML(), containsString("<environmentvariables><variable name=\"stdVariable\"><![CDATA[value1]]></variable><variable name=\"secureVariable\"><![CDATA[****]]></variable></environmentvariables>"));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldMigrateLdapManagerPasswordWithNewlineAndSpaces_XslMigrationFrom88To90.
@Test
public void shouldMigrateLdapManagerPasswordWithNewlineAndSpaces_XslMigrationFrom88To90() throws Exception {
String plainText = "something";
String encryptedValue = new GoCipher().encrypt(plainText);
String encryptedValueWithWhitespaceAndNewline = new StringBuilder(encryptedValue).insert(2, "\r\n" + " ").toString();
String content = ConfigFileFixture.config("<server artifactsdir='artifacts'>\n" + "<security>\n" + " <ldap uri='url' managerDn='manager-dn' encryptedManagerPassword='" + encryptedValueWithWhitespaceAndNewline + "'>\n" + " <bases>\n" + " <base value='base' />\n" + " </bases>\n" + " </ldap>\n" + " </security>" + " </server>", 88);
CruiseConfig config = ConfigMigrator.loadWithMigration(content).config;
assertThat(config.server().security().ldapConfig().currentManagerPassword(), is(plainText));
assertThat(config.server().security().ldapConfig().getEncryptedManagerPassword(), is(encryptedValue));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class ServerConfigServiceIntegrationTest method shouldReturnErrorResultWhenLdapSearchFails.
@Test
public void shouldReturnErrorResultWhenLdapSearchFails() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
LdapConfig invalidLdapConfig = new LdapConfig(new GoCipher());
serverConfigService.validateLdapSettings(invalidLdapConfig, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings. Reason: An LDAP connection URL must be supplied."));
result = new HttpLocalizedOperationResult();
invalidLdapConfig = new LdapConfig("ldap://some_loser_url", MANAGER_DN, MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
serverConfigService.validateLdapSettings(invalidLdapConfig, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings. Reason: some_loser_url:389; nested exception is javax.naming.CommunicationException: some_loser_url:389 [Root exception is java.net.UnknownHostException: some_loser_url]"));
result = new HttpLocalizedOperationResult();
invalidLdapConfig = new LdapConfig(LDAP_URL, "invalidDN=1", MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
serverConfigService.validateLdapSettings(invalidLdapConfig, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings." + " Reason: [LDAP: error code 49 - Unable to bind as user 'invalidDN=1' because no such entry" + " exists in the server.]; nested exception is javax.naming.AuthenticationException:" + " [LDAP: error code 49 - Unable to bind as user 'invalidDN=1' because no such entry exists in the server.]"));
result = new HttpLocalizedOperationResult();
invalidLdapConfig = new LdapConfig(LDAP_URL, MANAGER_DN, "wrong_password", null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
serverConfigService.validateLdapSettings(invalidLdapConfig, result);
assertThat(result.isSuccessful(), is(false));
assertThat(result.message(localizer), is("Cannot connect to ldap, please check the settings." + " Reason: [LDAP: error code 49 - Unable to bind as user 'cn=Active Directory Ldap User," + "ou=SomeSystems,ou=Accounts,ou=Principal,dc=corp,dc=somecompany,dc=com' because the provided" + " password was incorrect.]; nested exception is javax.naming.AuthenticationException:" + " [LDAP: error code 49 - Unable to bind as user 'cn=Active Directory Ldap User," + "ou=SomeSystems,ou=Accounts,ou=Principal,dc=corp,dc=somecompany,dc=com' because the provided" + " password was incorrect.]"));
result = new HttpLocalizedOperationResult();
LdapConfig validConfig = new LdapConfig(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, null, true, new BasesConfig(new BaseConfig(SEARCH_BASE)), SEARCH_FILTER);
serverConfigService.validateLdapSettings(validConfig, result);
assertThat("Expected no message. Got: " + result.message(localizer), result.isSuccessful(), is(true));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldMigrateEncryptedEnvironmentVariablesWithNewlineAndSpaces_XslMigrationFrom88To90.
@Test
public void shouldMigrateEncryptedEnvironmentVariablesWithNewlineAndSpaces_XslMigrationFrom88To90() throws Exception {
String plainText = "something";
String encryptedValue = new GoCipher().encrypt(plainText);
String encryptedValueWithWhitespaceAndNewline = new StringBuilder(encryptedValue).insert(2, "\r\n" + " ").toString();
String content = configWithPipeline("<pipeline name='some_pipeline'>" + "<environmentvariables>\n" + " <variable name=\"var_name\" secure=\"true\"><encryptedValue>" + encryptedValueWithWhitespaceAndNewline + "</encryptedValue></variable>\n" + " </environmentvariables>" + " <materials>" + " <svn url='svnurl'/>" + " </materials>" + " <stage name='some_stage'>" + " <jobs>" + " <job name='some_job'>" + " </job>" + " </jobs>" + " </stage>" + "</pipeline>", 88);
CruiseConfig config = ConfigMigrator.loadWithMigration(content).config;
assertThat(config.allPipelines().get(0).getVariables().get(0).getValue(), is(plainText));
assertThat(config.allPipelines().get(0).getVariables().get(0).getEncryptedValue(), is(encryptedValue));
}
use of com.thoughtworks.go.security.GoCipher in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotThrowUpWhenTfsWorkspaceIsNotSpecified.
@Test
public void shouldNotThrowUpWhenTfsWorkspaceIsNotSpecified() {
CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("tfs_pipeline");
PipelineConfig tfs_pipeline = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("tfs_pipeline"));
tfs_pipeline.materialConfigs().clear();
tfs_pipeline.addMaterialConfig(new TfsMaterialConfig(new GoCipher(), new UrlArgument("http://tfs.com"), "username", "CORPORATE", "password", "$/project_path"));
try {
xmlWriter.write(cruiseConfig, output, false);
} catch (Exception e) {
fail("should not fail as workspace name is not mandatory anymore " + e);
}
}
Aggregations