Search in sources :

Example 1 with ValidationError

use of com.thoughtworks.go.plugin.domain.common.ValidationError in project gocd by gocd.

the class SecurityAuthConfigServiceTest method verifyConnection_shouldFailForAInvalidAuthConfig.

@Test
public void verifyConnection_shouldFailForAInvalidAuthConfig() throws Exception {
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap", new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue()));
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("password", "Password cannot be blank"));
    validationResult.addError(new ValidationError("username", "Username cannot be blank"));
    VerifyConnectionResponse validationFailed = new VerifyConnectionResponse("validation-failed", "Connection check passed", validationResult);
    when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(validationFailed);
    VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
    assertThat(response, is(validationFailed));
    assertThat(ldap.getProperty("username").errors().get("username").get(0), is("Username cannot be blank"));
    assertThat(ldap.getProperty("password").errors().get("password").get(0), is("Password cannot be blank"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) VerifyConnectionResponse(com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ValidationError(com.thoughtworks.go.plugin.domain.common.ValidationError) ValidationResult(com.thoughtworks.go.plugin.domain.common.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 2 with ValidationError

use of com.thoughtworks.go.plugin.domain.common.ValidationError in project gocd by gocd.

the class SecurityAuthConfigService method mapErrors.

private void mapErrors(VerifyConnectionResponse response, SecurityAuthConfig authConfig) {
    com.thoughtworks.go.plugin.domain.common.ValidationResult validationResult = response.getValidationResult();
    if (validationResult == null) {
        return;
    }
    for (ValidationError error : validationResult.getErrors()) {
        ConfigurationProperty property = authConfig.getProperty(error.getKey());
        if (property == null) {
            authConfig.addNewConfiguration(error.getKey(), false);
            property = authConfig.getProperty(error.getKey());
        }
        property.addError(error.getKey(), error.getMessage());
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ValidationError(com.thoughtworks.go.plugin.domain.common.ValidationError)

Aggregations

ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 ValidationError (com.thoughtworks.go.plugin.domain.common.ValidationError)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)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 Test (org.junit.jupiter.api.Test)1