Search in sources :

Example 6 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class RuleAwarePluginProfileCommandTest method shouldContinueWithConfigSaveIfUserIsAuthorized.

@Test
public void shouldContinueWithConfigSaveIfUserIsAuthorized() throws Exception {
    SecretConfig securityAuthConfig = new SecretConfig("ldap", "cd.go.ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RuleAwarePluginProfileCommand command = new StubSecretConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("ldap"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(true));
    assertThat(result.httpCode(), is(200));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Example 7 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigDeleteCommandTest method shouldNotValidateIfSecretConfigIsInUseByPipeline.

@Test
public void shouldNotValidateIfSecretConfigIsInUseByPipeline() {
    SecretConfig secretConfig = new SecretConfig("foo", "file-based");
    Set<SecretConfigUsage> usageInfo = new HashSet<>(Arrays.asList(new SecretConfigUsage("gocd", "P1", "S1", "J1", "template1")));
    SecretConfigDeleteCommand command = new SecretConfigDeleteCommand(null, secretConfig, usageInfo, null, null, new HttpLocalizedOperationResult());
    GoConfigInvalidException goConfigInvalidException = assertThrows(GoConfigInvalidException.class, () -> {
        command.isValid(cruiseConfig);
    });
    assertThat(goConfigInvalidException.getMessage(), is("The secret config 'foo' is being referenced by pipeline(s): P1."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) SecretConfigUsage(com.thoughtworks.go.domain.SecretConfigUsage) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigDeleteCommandTest method shouldDeleteASecretConfig.

@Test
public void shouldDeleteASecretConfig() {
    SecretConfig secretConfig = new SecretConfig("foo", "file-based");
    cruiseConfig.getSecretConfigs().add(secretConfig);
    SecretConfigDeleteCommand command = new SecretConfigDeleteCommand(null, secretConfig, Collections.emptySet(), null, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.getSecretConfigs(), is(empty()));
}
Also used : SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Example 9 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigDeleteCommandTest method shouldValidateIfSecretConfigIsNotInUseByPipeline.

@Test
public void shouldValidateIfSecretConfigIsNotInUseByPipeline() {
    SecretConfig secretConfig = new SecretConfig("foo", "file-based");
    SecretConfigDeleteCommand command = new SecretConfigDeleteCommand(null, secretConfig, Collections.emptySet(), null, null, new HttpLocalizedOperationResult());
    assertThat(command.isValid(cruiseConfig), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecretConfig(com.thoughtworks.go.config.SecretConfig) Test(org.junit.jupiter.api.Test)

Example 10 with SecretConfig

use of com.thoughtworks.go.config.SecretConfig in project gocd by gocd.

the class SecretConfigCreateCommandTest method shouldAddSecretConfig.

@Test
public void shouldAddSecretConfig() throws Exception {
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    SecretConfig secretConfig = new SecretConfig("CreateTest", "File");
    SecretConfigCreateCommand command = new SecretConfigCreateCommand(null, secretConfig, extension, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.getSecretConfigs().find("CreateTest"), equalTo(secretConfig));
}
Also used : SecretConfig(com.thoughtworks.go.config.SecretConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SecretConfig (com.thoughtworks.go.config.SecretConfig)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 Test (org.junit.jupiter.api.Test)13 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)2 SecretConfigs (com.thoughtworks.go.config.SecretConfigs)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)1 SecretConfigUsage (com.thoughtworks.go.domain.SecretConfigUsage)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 EntityHashingService (com.thoughtworks.go.server.service.EntityHashingService)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HashSet (java.util.HashSet)1