Search in sources :

Example 11 with PluginRoleConfig

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

the class RoleConfigUpdateCommandTest method shouldUpdateExistingRole.

@Test
public void shouldUpdateExistingRole() throws Exception {
    PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    cruiseConfig.server().security().getRoles().add(oldRole);
    RoleConfigCommand command = new RoleConfigUpdateCommand(null, updatedRole, null, null, null, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("foo")), is(equalTo(updatedRole)));
}
Also used : PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 12 with PluginRoleConfig

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

the class RoleConfigUpdateCommandTest method shouldNotContinueWithConfigSaveIfRequestIsNotFresh.

@Test
public void shouldNotContinueWithConfigSaveIfRequestIsNotFresh() {
    PluginRoleConfig oldRole = new PluginRoleConfig("foo", "ldap");
    PluginRoleConfig updatedRole = new PluginRoleConfig("foo", "github");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(true);
    cruiseConfig.server().security().getRoles().add(oldRole);
    when(entityHashingService.md5ForEntity(oldRole)).thenReturn("md5");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    RoleConfigCommand command = new RoleConfigUpdateCommand(goConfigService, updatedRole, null, currentUser, result, entityHashingService, "bad-md5");
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.toString(), containsString("STALE_RESOURCE_CONFIG"));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 13 with PluginRoleConfig

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

the class CcTrayJobStatusChangeHandlerTest method shouldReuseViewersListFromExistingStatusWhenCreatingNewStatus.

@Test
public void shouldReuseViewersListFromExistingStatusWhenCreatingNewStatus() throws Exception {
    Users viewers = new AllowedUsers(s("viewer1", "viewer2"), Collections.singleton(new PluginRoleConfig("admin", "ldap")));
    ProjectStatus oldStatusInCache = new ProjectStatus(projectNameFor("job1"), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor("job1"));
    oldStatusInCache.updateViewers(viewers);
    when(cache.get(projectNameFor("job1"))).thenReturn(oldStatusInCache);
    CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
    ProjectStatus newStatus = handler.statusFor(JobInstanceMother.building("job1"), new HashSet<>());
    assertThat(newStatus.viewers(), is(viewers));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) AllowedUsers(com.thoughtworks.go.config.security.users.AllowedUsers) Users(com.thoughtworks.go.config.security.users.Users) AllowedUsers(com.thoughtworks.go.config.security.users.AllowedUsers) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Date(java.util.Date) Test(org.junit.Test)

Example 14 with PluginRoleConfig

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

the class AllowedUsersTest method usersShouldHaveViewPermissionIfTheyBelongToAllowedPluginRoles.

@Test
public void usersShouldHaveViewPermissionIfTheyBelongToAllowedPluginRoles() throws Exception {
    PluginRoleConfig admin = new PluginRoleConfig("go_admins", "ldap");
    pluginRoleUsersStore.assignRole("foo", admin);
    AllowedUsers users = new AllowedUsers(Collections.emptySet(), Collections.singleton(admin));
    assertTrue(users.contains("FOO"));
    assertTrue(users.contains("foo"));
    assertFalse(users.contains("bar"));
}
Also used : PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Example 15 with PluginRoleConfig

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

the class RoleConfigCreateCommandTest method shouldAddPluginRoleConfig.

@Test
public void shouldAddPluginRoleConfig() throws Exception {
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    PluginRoleConfig role = new PluginRoleConfig("blackbird", "ldap");
    RoleConfigCreateCommand command = new RoleConfigCreateCommand(null, role, extension, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("blackbird")), equalTo(role));
}
Also used : BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)26 Test (org.junit.Test)22 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)8 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)8 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)6 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4 User (com.thoughtworks.go.plugin.access.authorization.models.User)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)2 Users (com.thoughtworks.go.config.security.users.Users)2 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)2 PreAuthenticatedAuthenticationToken (com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 HashedMap (org.apache.commons.collections.map.HashedMap)2 UserDetails (org.springframework.security.userdetails.UserDetails)2