Search in sources :

Example 66 with SecurityAuthConfig

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

the class SecurityAuthConfigCommandTest method shouldContinueWithConfigSaveIfUserIsAuthorized.

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

Example 67 with SecurityAuthConfig

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

the class SecurityAuthConfigCommandTest method shouldValidateWithErrorIfNameIsNull.

@Test
public void shouldValidateWithErrorIfNameIsNull() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig(null, "ldap");
    cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
    SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
    assertThatThrownBy(() -> command.isValid(cruiseConfig)).hasMessageContaining(EntityType.SecurityAuthConfig.idCannotBeBlank());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) Test(org.junit.jupiter.api.Test)

Example 68 with SecurityAuthConfig

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

the class SecurityAuthConfigCommandTest method shouldPassValidationIfNameIsNotNull.

@Test
public void shouldPassValidationIfNameIsNotNull() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("foo", "ldap");
    cruiseConfig.server().security().securityAuthConfigs().add(securityAuthConfig);
    when(extension.validateAuthConfig(eq("ldap"), ArgumentMatchers.anyMap())).thenReturn(new ValidationResult());
    SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
    boolean isValid = command.isValid(cruiseConfig);
    assertTrue(isValid);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 69 with SecurityAuthConfig

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

the class SecurityAuthConfigDeleteCommandTest method shouldNotValidateIfProfileIsInUseByRole.

@Test
public void shouldNotValidateIfProfileIsInUseByRole() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("foo", "ldap");
    cruiseConfig.server().security().addRole(new PluginRoleConfig("blackbird", "foo"));
    SecurityAuthConfigDeleteCommand command = new SecurityAuthConfigDeleteCommand(null, authConfig, null, null, new HttpLocalizedOperationResult());
    assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(GoConfigInvalidException.class).hasMessageContaining("The security auth config 'foo' is being referenced by role(s): blackbird.");
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.jupiter.api.Test)

Example 70 with SecurityAuthConfig

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

the class SecurityAuthConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    SecurityAuthConfig oldAuthConfig = new SecurityAuthConfig("foo", "ldap");
    SecurityAuthConfig newAuthConfig = new SecurityAuthConfig("foo", "github");
    cruiseConfig.server().security().securityAuthConfigs().add(oldAuthConfig);
    EntityHashingService entityHashingService = mock(EntityHashingService.class);
    when(entityHashingService.hashForEntity(oldAuthConfig)).thenReturn("digest");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(goConfigService, newAuthConfig, null, currentUser, result, entityHashingService, "bad-digest");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("Someone has modified the configuration for"));
    ;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) 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