Search in sources :

Example 26 with GoCipher

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

the class TfsMaterialConfigUpdateTest method validate_shouldEnsureMandatoryFieldsAreNotBlank.

@Test
public void validate_shouldEnsureMandatoryFieldsAreNotBlank() {
    TfsMaterialConfig tfsMaterialConfig = new TfsMaterialConfig(new GoCipher(), new UrlArgument(""), "", "CORPORATE", "", "");
    tfsMaterialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(tfsMaterialConfig.errors().on(TfsMaterialConfig.URL), is("URL cannot be blank"));
    assertThat(tfsMaterialConfig.errors().on(TfsMaterialConfig.USERNAME), is("Username cannot be blank"));
    assertThat(tfsMaterialConfig.errors().on(TfsMaterialConfig.PROJECT_PATH), is("Project Path cannot be blank"));
}
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 27 with GoCipher

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

the class TfsMaterialTest method shouldEncryptTfsPasswordAndMarkPasswordAsNull.

@Test
public void shouldEncryptTfsPasswordAndMarkPasswordAsNull() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
    TfsMaterial tfsMaterial = new TfsMaterial(mockGoCipher, new UrlArgument("/foo"), "username", DOMAIN, "password", "");
    tfsMaterial.ensureEncrypted();
    assertThat(tfsMaterial.getPassword(), is(nullValue()));
    assertThat(tfsMaterial.getEncryptedPassword(), is("encrypted"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 28 with GoCipher

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

the class P4MaterialTest method shouldEncryptP4Password.

@Test
public void shouldEncryptP4Password() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
    P4Material p4Material = new P4Material("example.com:1818", "view", mockGoCipher);
    p4Material.setPassword("password");
    p4Material.ensureEncrypted();
    assertThat(p4Material.getEncryptedPassword(), is("encrypted"));
    assertThat(p4Material.getPassword(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 29 with GoCipher

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

the class GoConfigMigrationIntegrationTest method setUp.

@Before
public void setUp() throws Exception {
    File file = temporaryFolder.newFolder();
    configFile = new File(file, "cruise-config.xml");
    new SystemEnvironment().setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, configFile.getAbsolutePath());
    GoConfigFileHelper.clearConfigVersions();
    configRepository = new ConfigRepository(systemEnvironment);
    configRepository.initialize();
    serverHealthService.removeAllLogs();
    currentGoServerVersion = serverVersion.version();
    loader = new MagicalGoConfigXmlLoader(new ConfigCache(), ConfigElementImplementationRegistryMother.withNoPlugins());
    password = UUID.randomUUID().toString();
    encryptedPassword = new GoCipher().encrypt(password);
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) File(java.io.File) Before(org.junit.Before)

Example 30 with GoCipher

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

the class PluggableTaskTest method testConfigAsMap.

@Test
public void testConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), null, new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = task.configAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(PluggableTask.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Map(java.util.Map) Test(org.junit.jupiter.api.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