Search in sources :

Example 41 with GoCipher

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

the class EnvironmentVariablesConfig method setConfigAttributes.

@Override
public void setConfigAttributes(Object attributes) {
    this.clear();
    if (attributes != null) {
        for (Map attributeMap : (List<Map>) attributes) {
            EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(new GoCipher());
            try {
                environmentVariableConfig.setConfigAttributes(attributeMap);
                this.add(environmentVariableConfig);
            } catch (IllegalArgumentException e) {
                continue;
            }
        }
    }
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 42 with GoCipher

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

the class ServerConfigTest method shouldIgnoreErrorsFieldOnEquals.

@Test
public void shouldIgnoreErrorsFieldOnEquals() throws Exception {
    ServerConfig one = new ServerConfig(new SecurityConfig(), new MailHost(new GoCipher()), new SiteUrl("siteURL"), new SecureSiteUrl("secureURL"));
    one.addError("siteUrl", "I dont like this url");
    assertThat(one, is(new ServerConfig(new SecurityConfig(), new MailHost(new GoCipher()), new SiteUrl("siteURL"), new SecureSiteUrl("secureURL"))));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SecureSiteUrl(com.thoughtworks.go.domain.SecureSiteUrl) SiteUrl(com.thoughtworks.go.domain.SiteUrl) SecureSiteUrl(com.thoughtworks.go.domain.SecureSiteUrl) Test(org.junit.jupiter.api.Test)

Example 43 with GoCipher

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

the class ServerConfigTest method shouldNotUpdatePasswordForMailHostIfNotChangedOrNull.

@Test
public void shouldNotUpdatePasswordForMailHostIfNotChangedOrNull() throws IOException {
    File cipherFile = new SystemEnvironment().getDESCipherFile();
    FileUtils.deleteQuietly(cipherFile);
    FileUtils.writeStringToFile(cipherFile, "269298bc31c44620", UTF_8);
    GoCipher goCipher = new GoCipher();
    MailHost mailHost = new MailHost("abc", 12, "admin", "p", null, true, true, "anc@mail.com", "anc@mail.com", goCipher);
    ServerConfig serverConfig = new ServerConfig(null, mailHost, null, null);
    assertThat(serverConfig.mailHost().getPassword(), is("p"));
    String encryptedPassword = serverConfig.mailHost().getEncryptedPassword();
    serverConfig.updateMailHost(new MailHost("abc", 12, "admin", "p", encryptedPassword, false, /* Password Not Changed */
    true, "anc@mail.com", "anc@mail.com", goCipher));
    assertThat(serverConfig.mailHost().getPassword(), is("p"));
    assertThat(serverConfig.mailHost().getEncryptedPassword(), is(encryptedPassword));
    serverConfig.updateMailHost(new MailHost("abc", 12, "admin", null, "", true, true, "anc@mail.com", "anc@mail.com"));
    assertThat(serverConfig.mailHost().getPassword(), is(nullValue()));
    assertThat(serverConfig.mailHost().getEncryptedPassword(), is(nullValue()));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoCipher(com.thoughtworks.go.security.GoCipher) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 44 with GoCipher

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

the class MaterialConfigsTest method shouldSetTfsConfigAttributesForMaterial.

@Test
public void shouldSetTfsConfigAttributesForMaterial() {
    MaterialConfigs materialConfigs = new MaterialConfigs();
    Map<String, String> tfsAttrMap = new HashMap<>();
    tfsAttrMap.put(TfsMaterialConfig.URL, "foo");
    tfsAttrMap.put(TfsMaterialConfig.USERNAME, "bar");
    tfsAttrMap.put(TfsMaterialConfig.PASSWORD, "baz");
    tfsAttrMap.put(TfsMaterialConfig.PROJECT_PATH, "to_hell");
    tfsAttrMap.put(TfsMaterialConfig.MATERIAL_NAME, "crapy_material");
    tfsAttrMap.put(TfsMaterialConfig.DOMAIN, "CORPORATE");
    Map<String, Object> attributeMap = new HashMap<>();
    attributeMap.put(AbstractMaterialConfig.MATERIAL_TYPE, TfsMaterialConfig.TYPE);
    attributeMap.put(TfsMaterialConfig.TYPE, tfsAttrMap);
    materialConfigs.setConfigAttributes(attributeMap);
    TfsMaterialConfig tfsMaterialConfig = tfs(new GoCipher(), new UrlArgument("foo"), "bar", "CORPORATE", "baz", "to_hell");
    tfsMaterialConfig.setName(new CaseInsensitiveString("crapy_material"));
    assertThat(materialConfigs.first(), is(tfsMaterialConfig));
    assertThat(tfsMaterialConfig.getPassword(), is("baz"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) TfsMaterialConfig(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig) Test(org.junit.jupiter.api.Test)

Example 45 with GoCipher

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

the class PasswordDeserializerTest method shouldErrorOutWhenBothPasswordAndEncryptedPasswordAreGivenForDeserialization.

@Test
public void shouldErrorOutWhenBothPasswordAndEncryptedPasswordAreGivenForDeserialization() throws CryptoException {
    SvnMaterialConfig svnMaterialConfig = svn();
    PasswordDeserializer passwordDeserializer = new PasswordDeserializer();
    passwordDeserializer.deserialize("password", new GoCipher().encrypt("encryptedPassword"), svnMaterialConfig);
    assertThat(svnMaterialConfig.errors().getAllOn("password"), is(Arrays.asList("You may only specify `password` or `encrypted_password`, not both!")));
    assertThat(svnMaterialConfig.errors().getAllOn("encryptedPassword"), is(Arrays.asList("You may only specify `password` or `encrypted_password`, not both!")));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) 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