Search in sources :

Example 36 with SecurityAuthConfig

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

the class SecurityAuthConfigDeleteCommandTest method shouldRaiseExceptionInCaseProfileDoesNotExist.

@Test
public void shouldRaiseExceptionInCaseProfileDoesNotExist() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
    assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
    SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
    assertThatThrownBy(() -> command.update(cruiseConfig)).isInstanceOf(RecordNotFoundException.class);
    assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Example 37 with SecurityAuthConfig

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

the class SecurityAuthConfigDeleteCommandTest method shouldValidateIfProfileIsNotInUseByPipeline.

@Test
public void shouldValidateIfProfileIsNotInUseByPipeline() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
    assertThat(cruiseConfig.server().security().securityAuthConfigs(), is(empty()));
    SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
    assertTrue(command.isValid(cruiseConfig));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Example 38 with SecurityAuthConfig

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

the class PluginProfileCommandTest method shouldValidateIfSecurityAuthConfigIdIsNull.

@Test
public void shouldValidateIfSecurityAuthConfigIdIsNull() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig(null, "some-plugin", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
    cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
    PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
    assertThatThrownBy(() -> command.isValid(cruiseConfig)).hasMessageContaining(EntityType.ElasticProfile.idCannotBeBlank());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.jupiter.api.Test)

Example 39 with SecurityAuthConfig

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

the class PluginProfileCommandTest method shouldContinueWithConfigSaveIfUserIsAdmin.

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

Example 40 with SecurityAuthConfig

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

the class PluginProfileCommandTest method shouldNotContinueWithConfigSaveIfUserIsUnauthorized.

@Test
public void shouldNotContinueWithConfigSaveIfUserIsUnauthorized() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    PluginProfileCommand command = new StubSecurityAuthConfigCommand(goConfigService, securityAuthConfig, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.message(), equalTo("Unauthorized to edit."));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) 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