Search in sources :

Example 6 with GoCipher

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

the class ServerConfigServiceTest method shouldSetMessageAsMergedWhenMergingServerConfigChanges.

@Test
public void shouldSetMessageAsMergedWhenMergingServerConfigChanges() {
    GoConfigService goConfigService = mock(GoConfigService.class);
    UserService userService = mock(UserService.class);
    ServerConfigService serverConfigService = new ServerConfigService(goConfigService, userService);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    MailHost mailHost = new MailHost(new GoCipher());
    when(goConfigService.updateServerConfig(mailHost, true, "md5", null, null, null, null, "http://site", "https://site", "location")).thenReturn(ConfigSaveState.MERGED);
    serverConfigService.updateServerConfig(mailHost, null, null, null, null, true, "http://site", "https://site", "location", result, "md5");
    assertThat(result.localizable(), Is.is(LocalizedMessage.composite(LocalizedMessage.string("SAVED_CONFIGURATION_SUCCESSFULLY"), LocalizedMessage.string("CONFIG_MERGED"))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) MailHost(com.thoughtworks.go.config.MailHost) Test(org.junit.Test)

Example 7 with GoCipher

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

the class P4MaterialConfigTest method shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided.

@Test
public void shouldThrowErrorsIfBothPasswordAndEncryptedPasswordAreProvided() {
    P4MaterialConfig materialConfig = new P4MaterialConfig("foo/bar, 80", "password", "encryptedPassword", new GoCipher());
    materialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(materialConfig.errors().on("password"), is("You may only specify `password` or `encrypted_password`, not both!"));
    assertThat(materialConfig.errors().on("encryptedPassword"), is("You may only specify `password` or `encrypted_password`, not both!"));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 8 with GoCipher

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

the class P4MaterialConfigTest method setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged.

@Test
public void setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged() throws Exception {
    P4MaterialConfig materialConfig = new P4MaterialConfig("", "");
    materialConfig.setPassword("notSecret");
    Map<String, String> map = new HashMap<>();
    map.put(P4MaterialConfig.PASSWORD, "secret");
    map.put(P4MaterialConfig.PASSWORD_CHANGED, "1");
    materialConfig.setConfigAttributes(map);
    assertThat(ReflectionUtil.getField(materialConfig, "password"), is(nullValue()));
    assertThat(materialConfig.getPassword(), is("secret"));
    assertThat(materialConfig.getEncryptedPassword(), is(new GoCipher().encrypt("secret")));
    // Dont change
    map.put(SvnMaterialConfig.PASSWORD, "Hehehe");
    map.put(SvnMaterialConfig.PASSWORD_CHANGED, "0");
    materialConfig.setConfigAttributes(map);
    assertThat(ReflectionUtil.getField(materialConfig, "password"), is(nullValue()));
    assertThat(materialConfig.getPassword(), is("secret"));
    assertThat(materialConfig.getEncryptedPassword(), is(new GoCipher().encrypt("secret")));
    // Dont change
    map.put(SvnMaterialConfig.PASSWORD, "");
    map.put(SvnMaterialConfig.PASSWORD_CHANGED, "1");
    materialConfig.setConfigAttributes(map);
    assertThat(materialConfig.getPassword(), is(nullValue()));
    assertThat(materialConfig.getEncryptedPassword(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 9 with GoCipher

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

the class P4MaterialConfigTest method shouldValidateWhetherTheEncryptedPasswordIsCorrect.

@Test
public void shouldValidateWhetherTheEncryptedPasswordIsCorrect() {
    P4MaterialConfig materialConfig = new P4MaterialConfig("foo/bar, 80", "", "encryptedPassword", new GoCipher());
    materialConfig.validate(new ConfigSaveValidationContext(null));
    assertThat(materialConfig.errors().on("encryptedPassword"), is("Encrypted password value for P4 material with serverAndPort 'foo/bar, 80' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.Test)

Example 10 with GoCipher

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

the class SvnMaterialConfigTest method setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged.

@Test
public void setConfigAttributes_shouldUpdatePasswordWhenPasswordChangedBooleanChanged() throws Exception {
    SvnMaterialConfig svnMaterial = new SvnMaterialConfig("", "", "notSoSecret", false);
    Map<String, String> map = new HashMap<>();
    map.put(SvnMaterialConfig.PASSWORD, "secret");
    map.put(SvnMaterialConfig.PASSWORD_CHANGED, "1");
    svnMaterial.setConfigAttributes(map);
    assertThat(ReflectionUtil.getField(svnMaterial, "password"), is(nullValue()));
    assertThat(svnMaterial.getPassword(), is("secret"));
    assertThat(svnMaterial.getEncryptedPassword(), Is.is(new GoCipher().encrypt("secret")));
    // Dont change
    map.put(SvnMaterialConfig.PASSWORD, "Hehehe");
    map.put(SvnMaterialConfig.PASSWORD_CHANGED, "0");
    svnMaterial.setConfigAttributes(map);
    assertThat(ReflectionUtil.getField(svnMaterial, "password"), is(nullValue()));
    assertThat(svnMaterial.getPassword(), is("secret"));
    assertThat(svnMaterial.getEncryptedPassword(), is(new GoCipher().encrypt("secret")));
    map.put(SvnMaterialConfig.PASSWORD, "");
    map.put(SvnMaterialConfig.PASSWORD_CHANGED, "1");
    svnMaterial.setConfigAttributes(map);
    assertThat(svnMaterial.getPassword(), is(nullValue()));
    assertThat(svnMaterial.getEncryptedPassword(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) HashMap(java.util.HashMap) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) 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