Search in sources :

Example 21 with SecurityAuthConfig

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

the class RevokeStaleAccessTokenServiceTest method shouldDoNothingWhenAuthConfigHasNotChangedDuringUpdateAuthConfig.

// on entity update
@Test
void shouldDoNothingWhenAuthConfigHasNotChangedDuringUpdateAuthConfig() {
    BasicCruiseConfig config = new BasicCruiseConfig();
    config.server().security().securityAuthConfigs().add(authConfig1);
    config.server().security().securityAuthConfigs().add(authConfig2);
    when(goConfigService.getConfigForEditing()).thenReturn(config);
    when(accessTokenService.findAllTokensForAllUsers(AccessTokenFilter.active)).thenReturn(Arrays.asList(authConfig1_token1, authConfig1_token2, authConfig2_token1));
    service.initialize();
    verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
    service.onEntityConfigChange(new SecurityAuthConfig());
    verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 22 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig 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 23 with SecurityAuthConfig

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

the class SecurityAuthConfigServiceTest method shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig.

@Test
public void shouldPerformPluginValidationsBeforeAddingSecurityAuthConfig() {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap", create("key", false, "value"));
    Username username = new Username("username");
    securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
    verify(extension).validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 24 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig 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 RecordNotFoundException(""));
    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) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ValidationResult(com.thoughtworks.go.plugin.domain.common.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 25 with SecurityAuthConfig

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

the class SecurityAuthConfigServiceTest method shouldGetSecurityAuthConfigByGivenId.

@Test
public void shouldGetSecurityAuthConfigByGivenId() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.securityAuthConfigs().add(authConfig);
    when(goConfigService.security()).thenReturn(securityConfig);
    assertThat(securityAuthConfigService.findProfile("ldap"), is(authConfig));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)81 Test (org.junit.jupiter.api.Test)46 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)28 Test (org.junit.Test)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)14 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)14 User (com.thoughtworks.go.plugin.access.authorization.models.User)11 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)9 Username (com.thoughtworks.go.server.domain.Username)9 UserDetails (org.springframework.security.userdetails.UserDetails)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)7 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)5 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)5 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)4 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)4 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)4 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)4 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)4