Search in sources :

Example 1 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class SecurityAuthConfigServiceTest method verifyConnection_shouldFailInAbsenceOfPlugin.

@Test
public void verifyConnection_shouldFailInAbsenceOfPlugin() throws Exception {
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
    when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException(""));
    VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
    assertThat(response, is(new VerifyConnectionResponse("failure", "Unable to verify connection, missing plugin: cd.go.ldap", new com.thoughtworks.go.plugin.domain.common.ValidationResult())));
}
Also used : VerifyConnectionResponse(com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ValidationResult(com.thoughtworks.go.plugin.domain.common.ValidationResult) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) Test(org.junit.Test)

Example 2 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class SecurityAuthConfigServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginId.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginId() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(extension.validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("plugin not found"));
    securityAuthConfigService.update(username, "md5", securityAuthConfig, new HttpLocalizedOperationResult());
    assertThat(securityAuthConfig.errors().isEmpty(), is(false));
    assertThat(securityAuthConfig.errors().on("pluginId"), is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) Test(org.junit.Test)

Example 3 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class ElasticProfileServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileUpdating.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileUpdating() throws Exception {
    ElasticProfile elasticProfile = new ElasticProfile("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(elasticAgentExtension.validate(elasticProfile.getPluginId(), elasticProfile.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("some error"));
    elasticProfileService.update(username, "md5", elasticProfile, new HttpLocalizedOperationResult());
    assertThat(elasticProfile.errors().isEmpty(), Matchers.is(false));
    assertThat(elasticProfile.errors().on("pluginId"), Matchers.is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 4 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class ElasticProfileServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating() throws Exception {
    ElasticProfile elasticProfile = new ElasticProfile("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(elasticAgentExtension.validate(elasticProfile.getPluginId(), elasticProfile.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("some error"));
    elasticProfileService.create(username, elasticProfile, new HttpLocalizedOperationResult());
    assertThat(elasticProfile.errors().isEmpty(), Matchers.is(false));
    assertThat(elasticProfile.errors().on("pluginId"), Matchers.is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 5 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class RoleConfigurationValidator method validate.

public void validate(PluginRoleConfig role, String pluginId) {
    try {
        ValidationResult result = authorizationExtension.validateRoleConfiguration(pluginId, role.getConfigurationAsMap(true));
        if (!result.isSuccessful()) {
            for (ValidationError error : result.getErrors()) {
                ConfigurationProperty property = role.getProperty(error.getKey());
                if (property == null) {
                    role.addNewConfiguration(error.getKey(), false);
                    property = role.getProperty(error.getKey());
                }
                property.addError(error.getKey(), error.getMessage());
            }
        }
    } catch (PluginNotFoundException e) {
        role.addError("pluginRole", String.format("Unable to validate `pluginRole` configuration, missing plugin: %s", pluginId));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Aggregations

PluginNotFoundException (com.thoughtworks.go.plugin.access.PluginNotFoundException)9 Test (org.junit.Test)6 Username (com.thoughtworks.go.server.domain.Username)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)2 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)1 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)1 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)1