Search in sources :

Example 16 with GoCipher

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

the class ServerConfigServiceIntegrationTest method shouldNotUpdateWhenEmailIsInvalid.

@Test
public void shouldNotUpdateWhenEmailIsInvalid() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    serverConfigService.updateServerConfig(new MailHost("boo", 1, "username", "password", true, true, "from", "admin@admin.com"), "artifacts", null, null, "42", true, "http://site_url", "https://secure_site_url", "default", result, goConfigDao.md5OfConfigFile());
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("From address is not a valid email address."));
    assertThat(goConfigService.getMailHost(), is(new MailHost(new GoCipher())));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 17 with GoCipher

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

the class ServerConfigServiceIntegrationTest method updateServerConfig_ShouldFailWhenAllowAutoLoginIsTurnedOffWithNoAdminsRemaining.

@Test
public void updateServerConfig_ShouldFailWhenAllowAutoLoginIsTurnedOffWithNoAdminsRemaining() throws IOException {
    configHelper.enableSecurity();
    userService.deleteAll();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    serverConfigService.updateServerConfig(new MailHost(new GoCipher()), "artifacts", null, null, "42", false, "http://site_url", "https://secure_site_url", "default", result, goConfigDao.md5OfConfigFile());
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), containsString("Cannot disable auto login with no admins enabled."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 18 with GoCipher

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

the class SvnMaterialTest method shouldErrorOutIfDecryptionFails.

@Test
public void shouldErrorOutIfDecryptionFails() throws InvalidCipherTextException {
    GoCipher mockGoCipher = mock(GoCipher.class);
    String fakeCipherText = "fake cipher text";
    when(mockGoCipher.decrypt(fakeCipherText)).thenThrow(new InvalidCipherTextException("exception"));
    SvnMaterial material = new SvnMaterial("/foo", "username", null, false, mockGoCipher);
    ReflectionUtil.setField(material, "encryptedPassword", fakeCipherText);
    try {
        material.getPassword();
        fail("Should have thrown up");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Could not decrypt the password to get the real password"));
    }
}
Also used : InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) GoCipher(com.thoughtworks.go.security.GoCipher) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) InvalidCipherTextException(org.bouncycastle.crypto.InvalidCipherTextException) Test(org.junit.Test)

Example 19 with GoCipher

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

the class TfsMaterialConfigUpdateTest method shouldDecryptTfsPassword.

@Test
public void shouldDecryptTfsPassword() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.decrypt("encrypted")).thenReturn("password");
    TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "secret", "walk_this_path");
    ReflectionUtil.setField(materialConfig, "encryptedPassword", "encrypted");
    materialConfig.ensureEncrypted();
    assertThat(materialConfig.getPassword(), is("password"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) Test(org.junit.Test)

Example 20 with GoCipher

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

the class TfsMaterialConfigUpdateTest method shouldEncryptTfsPasswordAndMarkPasswordAsNull.

@Test
public void shouldEncryptTfsPasswordAndMarkPasswordAsNull() throws Exception {
    GoCipher mockGoCipher = mock(GoCipher.class);
    when(mockGoCipher.encrypt("password")).thenReturn("encrypted");
    TfsMaterialConfig materialConfig = new TfsMaterialConfig(mockGoCipher, new UrlArgument("http://10.4.4.101:8080/tfs/Sample"), "loser", "CORPORATE", "password", "walk_this_path");
    materialConfig.ensureEncrypted();
    assertThat(materialConfig.getPassword(), is(nullValue()));
    assertThat(materialConfig.getEncryptedPassword(), is("encrypted"));
}
Also used : UrlArgument(com.thoughtworks.go.util.command.UrlArgument) GoCipher(com.thoughtworks.go.security.GoCipher) 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