Search in sources :

Example 96 with GoCipher

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

the class MagicalGoConfigXmlWriterTest method shouldWriteMultipleSearchBases.

@Test
public void shouldWriteMultipleSearchBases() throws Exception {
    BaseConfig base1 = new BaseConfig("base1");
    BaseConfig base2 = new BaseConfig("base2");
    BasesConfig basesConfig = new BasesConfig(base1, base2);
    LdapConfig ldapConfig = new LdapConfig("url", "managerDn", "managerPassword", "managerPassword", false, basesConfig, "filter");
    SecurityConfig securityConfig = new SecurityConfig(ldapConfig, new PasswordFileConfig("some_path"), false);
    ServerConfig serverConfig = new ServerConfig(securityConfig, new MailHost(new GoCipher()));
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    cruiseConfig.setServerConfig(serverConfig);
    xmlWriter.write(cruiseConfig, output, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(output.toString());
    BasesConfig actualBasesConfig = holder.config.server().security().ldapConfig().getBasesConfig();
    assertThat(actualBasesConfig.size(), is(2));
    assertThat(actualBasesConfig, hasItems(base1, base2));
}
Also used : 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 97 with GoCipher

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

the class PipelineConfigServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig(UUID.randomUUID().toString(), new GitMaterialConfig("FOO"));
    goConfigService.addPipeline(pipelineConfig, groupName);
    repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName);
    repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().add(repoConfig1);
            cruiseConfig.getConfigRepos().add(repoConfig2);
            return cruiseConfig;
        }
    });
    GoCipher goCipher = new GoCipher();
    goConfigService.updateServerConfig(new MailHost(goCipher), new LdapConfig(goCipher), new PasswordFileConfig("path"), false, goConfigService.configFileMd5(), "artifacts", null, null, "0", null, null, "foo");
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
    remoteDownstreamPipelineName = "remote-downstream";
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstreamPipelineName, pipelineConfig, new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
    PartialConfig partialConfigFromRepo2 = PartialConfigMother.withPipeline("independent-pipeline", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigFromRepo2);
    result = new HttpLocalizedOperationResult();
    headCommitBeforeUpdate = configRepository.getCurrentRevCommit().name();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) ExpectedException(org.junit.rules.ExpectedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper)

Example 98 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 99 with GoCipher

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

the class PipelineConfigTest method shouldGetOnlySecureVariables.

@Test
public void shouldGetOnlySecureVariables() throws InvalidCipherTextException {
    PipelineConfig pipelineConfig = new PipelineConfig();
    EnvironmentVariableConfig username = new EnvironmentVariableConfig("username", "ram");
    pipelineConfig.addEnvironmentVariable(username);
    GoCipher goCipher = mock(GoCipher.class);
    when(goCipher.encrypt("=%HG*^&*&^")).thenReturn("encrypted");
    EnvironmentVariableConfig password = new EnvironmentVariableConfig(goCipher, "password", "=%HG*^&*&^", true);
    pipelineConfig.addEnvironmentVariable(password);
    List<EnvironmentVariableConfig> plainTextVariables = pipelineConfig.getSecureVariables();
    assertThat(plainTextVariables, hasItem(password));
    assertThat(plainTextVariables, not(hasItem(username)));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 100 with GoCipher

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

the class PipelineConfigTest method shouldGetOnlyPlainTextVariables.

@Test
public void shouldGetOnlyPlainTextVariables() throws InvalidCipherTextException {
    PipelineConfig pipelineConfig = new PipelineConfig();
    EnvironmentVariableConfig username = new EnvironmentVariableConfig("username", "ram");
    pipelineConfig.addEnvironmentVariable(username);
    GoCipher goCipher = mock(GoCipher.class);
    when(goCipher.encrypt("=%HG*^&*&^")).thenReturn("encrypted");
    EnvironmentVariableConfig password = new EnvironmentVariableConfig(goCipher, "password", "=%HG*^&*&^", true);
    pipelineConfig.addEnvironmentVariable(password);
    EnvironmentVariablesConfig plainTextVariables = pipelineConfig.getPlainTextVariables();
    assertThat(plainTextVariables, not(hasItem(password)));
    assertThat(plainTextVariables, hasItem(username));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Aggregations

GoCipher (com.thoughtworks.go.security.GoCipher)143 Test (org.junit.Test)122 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)36 HashMap (java.util.HashMap)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)14 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Matchers.containsString (org.hamcrest.Matchers.containsString)12 ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)9 Configuration (com.thoughtworks.go.domain.config.Configuration)9 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)9 BaseConfig (com.thoughtworks.go.config.server.security.ldap.BaseConfig)8 BasesConfig (com.thoughtworks.go.config.server.security.ldap.BasesConfig)8 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)8 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)8 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)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