Search in sources :

Example 1 with ValidationResult

use of com.thoughtworks.go.plugin.domain.common.ValidationResult 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 ValidationResult

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

the class SecurityAuthConfigServiceTest method verifyConnection_shouldSendConnectionFailedResponseOnUnSuccessfulVerification.

@Test
public void verifyConnection_shouldSendConnectionFailedResponseOnUnSuccessfulVerification() throws Exception {
    VerifyConnectionResponse success = new VerifyConnectionResponse("failure", "Connection check failed", new ValidationResult());
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
    when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(success);
    VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
    assertThat(response, is(success));
}
Also used : VerifyConnectionResponse(com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ValidationResult(com.thoughtworks.go.plugin.domain.common.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 3 with ValidationResult

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

the class SecurityAuthConfigServiceTest method verifyConnection_shouldSendSuccessResponseOnSuccessfulVerification.

@Test
public void verifyConnection_shouldSendSuccessResponseOnSuccessfulVerification() throws Exception {
    VerifyConnectionResponse success = new VerifyConnectionResponse("success", "Connection check passed", new ValidationResult());
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
    when(extension.verifyConnection("cd.go.ldap", ldap.getConfigurationAsMap(true))).thenReturn(success);
    VerifyConnectionResponse response = securityAuthConfigService.verifyConnection(ldap);
    assertThat(response, is(success));
}
Also used : VerifyConnectionResponse(com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ValidationResult(com.thoughtworks.go.plugin.domain.common.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)3 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)3 Test (org.junit.jupiter.api.Test)3 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 ValidationError (com.thoughtworks.go.plugin.domain.common.ValidationError)1