Search in sources :

Example 1 with GoCipher

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

Example 2 with GoCipher

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

Example 3 with GoCipher

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) BasesConfig(com.thoughtworks.go.config.server.security.ldap.BasesConfig) BaseConfig(com.thoughtworks.go.config.server.security.ldap.BaseConfig) Test(org.junit.Test)

Example 4 with GoCipher

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

Example 5 with GoCipher

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);
    }
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) JDOMParseException(org.jdom2.input.JDOMParseException) 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