use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.
the class SecretConfigDeleteCommand method update.
@Override
public void update(CruiseConfig preprocessedConfig) {
SecretConfig configToBeDeleted = findExistingProfile(preprocessedConfig);
getPluginProfiles(preprocessedConfig).remove(configToBeDeleted);
}
use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.
the class SecretConfigCreateCommandTest method shouldInvokePluginValidations.
@Test
public void shouldInvokePluginValidations() throws Exception {
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("key", "error"));
SecretConfig newSecretConfig = new SecretConfig("foo", "file", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
RuleAwarePluginProfileCommand command = new SecretConfigCreateCommand(mock(GoConfigService.class), newSecretConfig, extension, null, new HttpLocalizedOperationResult());
when(extension.validateSecretsConfig(eq("file"), anyMap())).thenReturn(validationResult);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(RecordNotFoundException.class).hasMessageContaining(EntityType.SecretConfig.notFoundMessage(newSecretConfig.getId()));
}
use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.
the class SecretConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.
@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
SecretConfig oldConfig = new SecretConfig("foo", "docker");
SecretConfig newConfig = new SecretConfig("foo", "aws");
cruiseConfig.getSecretConfigs().add(oldConfig);
EntityHashingService entityHashingService = mock(EntityHashingService.class);
when(entityHashingService.hashForEntity(oldConfig)).thenReturn("digest");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
SecretConfigUpdateCommand command = new SecretConfigUpdateCommand(goConfigService, newConfig, null, currentUser, result, entityHashingService, "bad-digest");
assertThat(command.canContinue(cruiseConfig), is(false));
assertThat(result.toString(), containsString("Someone has modified the configuration for"));
}
use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.
the class SecretConfigUpdateCommandTest method shouldUpdateExistingSecretConfig.
@Test
public void shouldUpdateExistingSecretConfig() throws Exception {
SecretConfig oldConfig = new SecretConfig("foo", "docker");
SecretConfig newConfig = new SecretConfig("foo", "aws");
cruiseConfig.getSecretConfigs().add(oldConfig);
SecretConfigUpdateCommand command = new SecretConfigUpdateCommand(null, newConfig, null, null, null, null, null);
command.update(cruiseConfig);
assertThat(cruiseConfig.getSecretConfigs().find("foo"), is(equalTo(newConfig)));
}
use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.
the class SecretConfigDeleteCommandTest method shouldRaiseExceptionInCaseSecretConfigDoesNotExist.
@Test
public void shouldRaiseExceptionInCaseSecretConfigDoesNotExist() {
SecretConfig secretConfig = new SecretConfig("foo", "file-based");
assertThat(cruiseConfig.getSecretConfigs(), is(empty()));
SecretConfigDeleteCommand command = new SecretConfigDeleteCommand(null, secretConfig, Collections.emptySet(), null, null, new HttpLocalizedOperationResult());
assertThrows(RecordNotFoundException.class, () -> command.update(cruiseConfig));
assertThat(cruiseConfig.getSecretConfigs(), is(empty()));
}
Aggregations