Search in sources :

Example 31 with TeamModel

use of com.gitblit.models.TeamModel in project gitblit by gitblit.

the class PermissionsTest method testTeamMember_VIEW_DELETE.

/**
 * VIEW_DELETE = VIEW access restriction, DELETE access permission
 */
@Test
public void testTeamMember_VIEW_DELETE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertTrue("team member CAN NOT clone!", user.canClone(repository));
    assertTrue("team member CAN NOT push!", user.canPush(repository));
    assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
    assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
    assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.DELETE, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 32 with TeamModel

use of com.gitblit.models.TeamModel in project gitblit by gitblit.

the class PermissionsTest method testTeam_CLONE_CLONE.

/**
 * CLONE_CLONE = CLONE access restriction, CLONE access permission
 */
@Test
public void testTeam_CLONE_CLONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.CLONE;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
    assertTrue("team CAN NOT view!", team.canView(repository));
    assertTrue("team CAN NOT clone!", team.canClone(repository));
    assertFalse("team CAN push!", team.canPush(repository));
    assertFalse("team CAN create ref!", team.canCreateRef(repository));
    assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
    assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
    assertEquals("team has wrong permission!", AccessPermission.CLONE, team.getRepositoryPermission(repository).permission);
}
Also used : TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 33 with TeamModel

use of com.gitblit.models.TeamModel in project gitblit by gitblit.

the class PermissionsTest method testTeam_VIEW_PUSH.

/**
 * VIEW_PUSH = VIEW access restriction, PUSH access permission
 */
@Test
public void testTeam_VIEW_PUSH() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
    assertTrue("team CAN NOT view!", team.canView(repository));
    assertTrue("team CAN NOT clone!", team.canClone(repository));
    assertTrue("team CAN NOT push!", team.canPush(repository));
    assertFalse("team CAN create ref!", team.canCreateRef(repository));
    assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
    assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
    assertEquals("team has wrong permission!", AccessPermission.PUSH, team.getRepositoryPermission(repository).permission);
}
Also used : TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 34 with TeamModel

use of com.gitblit.models.TeamModel in project gitblit by gitblit.

the class PermissionsTest method testTeamMember_PUSH_CLONE.

/**
 * PUSH_CLONE = PUSH access restriction, CLONE access permission
 */
@Test
public void testTeamMember_PUSH_CLONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.PUSH;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertTrue("team member CAN NOT clone!", user.canClone(repository));
    assertFalse("team member CAN push!", user.canPush(repository));
    assertFalse("team member CAN create ref!", user.canCreateRef(repository));
    assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.CLONE, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 35 with TeamModel

use of com.gitblit.models.TeamModel in project gitblit by gitblit.

the class PermissionsTest method testTeamMember_NONE_VIEW.

/**
 * NONE_VIEW = NO access restriction, VIEW access permission
 * (not useful scenario)
 */
@Test
public void testTeamMember_NONE_VIEW() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.NONE;
    TeamModel team = new TeamModel("test");
    team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertTrue("team member CAN NOT clone!", user.canClone(repository));
    assertTrue("team member CAN NOT push!", user.canPush(repository));
    assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
    assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
    assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
    assertEquals("team member has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TeamModel (com.gitblit.models.TeamModel)111 RepositoryModel (com.gitblit.models.RepositoryModel)68 Test (org.junit.Test)67 Date (java.util.Date)62 UserModel (com.gitblit.models.UserModel)58 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)8 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 GitBlitException (com.gitblit.GitBlitException)4 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)4 File (java.io.File)4 IOException (java.io.IOException)4 AccessPermission (com.gitblit.Constants.AccessPermission)3 Repository (org.eclipse.jgit.lib.Repository)3 IUserService (com.gitblit.IUserService)2 LdapConnection (com.gitblit.ldap.LdapConnection)2 RefModel (com.gitblit.models.RefModel)2