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"))));
}
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!"));
}
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()));
}
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."));
}
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()));
}
Aggregations