Search in sources :

Example 91 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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.toString(), containsString("UNAUTHORIZED_TO_EDIT"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 92 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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);
    thrown.expectMessage("some foo object id cannot be null.");
    command.isValid(cruiseConfig);
}
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.Test)

Example 93 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class PluginProfileCommandTest method shouldContinueWithConfigSaveIfUserIsAuthorized.

@Test
public void shouldContinueWithConfigSaveIfUserIsAuthorized() 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));
    assertThat(result.httpCode(), is(200));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 94 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult 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.Test)

Example 95 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class RoleConfigCommandTest method shouldContinueWithConfigSaveIfUserIsAuthorized.

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

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14