Search in sources :

Example 61 with UserModel

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

the class PermissionsTest method testNamed_VIEW_NONE.

/**
	 * VIEW_NONE = VIEW access restriction, NO access permission
	 */
@Test
public void testNamed_VIEW_NONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    UserModel user = new UserModel("test");
    assertFalse("named CAN view!", user.canView(repository));
    assertFalse("named CAN clone!", user.canClone(repository));
    assertFalse("named CAN push!", user.canPush(repository));
    assertFalse("named CAN create ref!", user.canCreateRef(repository));
    assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("named has wrong permission!", AccessPermission.NONE, user.getRepositoryPermission(repository).permission);
    repository.allowForks = false;
    user.canFork = false;
    assertFalse("named CAN fork!", user.canFork(repository));
    user.canFork = true;
    assertFalse("named CAN fork!", user.canFork(repository));
    repository.allowForks = true;
    assertFalse("named CAN NOT fork!", user.canFork(repository));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 62 with UserModel

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

the class PermissionsTest method testRegexMatching2.

@Test
public void testRegexMatching2() throws Exception {
    RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, null, new Date());
    personal.authorizationControl = AuthorizationControl.NAMED;
    personal.accessRestriction = AccessRestrictionType.VIEW;
    UserModel user = new UserModel("test");
    // permit all repositories excluding all personal rpeositories
    user.setRepositoryPermission("[^~].*", AccessPermission.CLONE);
    // permitall  ~ubercool repositories
    user.setRepositoryPermission("~ubercool/.*", AccessPermission.CLONE);
    // personal
    assertTrue("user DOES NOT HAVE a repository permission!", user.hasRepositoryPermission(personal.name));
    assertTrue("user CAN NOT view!", user.canView(personal));
    assertTrue("user CAN NOT clone!", user.canClone(personal));
    assertFalse("user CAN push!", user.canPush(personal));
    assertFalse("user CAN create ref!", user.canCreateRef(personal));
    assertFalse("user CAN delete ref!", user.canDeleteRef(personal));
    assertFalse("user CAN rewind ref!", user.canRewindRef(personal));
    assertEquals("user has wrong permission!", AccessPermission.CLONE, user.getRepositoryPermission(personal).permission);
    assertFalse("user CAN fork!", user.canFork(personal));
    assertFalse("user CAN delete!", user.canDelete(personal));
    assertFalse("user CAN edit!", user.canEdit(personal));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 63 with UserModel

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

the class PermissionsTest method testNamed_CLONE_DELETE.

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

Example 64 with UserModel

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

the class PermissionsTest method testTeamMember_VIEW_PUSH.

/**
	 * VIEW_PUSH = VIEW access restriction, PUSH access permission
	 */
@Test
public void testTeamMember_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);
    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));
    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.PUSH, 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 65 with UserModel

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

the class PermissionsTest method testAnonymous_CLONE.

@Test
public void testAnonymous_CLONE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.CLONE;
    UserModel user = UserModel.ANONYMOUS;
    assertTrue("anonymous CAN NOT view!", user.canView(repository));
    assertFalse("anonymous CAN clone!", user.canClone(repository));
    assertFalse("anonymous CAN push!", user.canPush(repository));
    assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
    assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("anonymous has wrong permission!", AccessPermission.VIEW, user.getRepositoryPermission(repository).permission);
    repository.allowForks = false;
    assertFalse("anonymous CAN fork!", user.canFork(repository));
    repository.allowForks = true;
    assertFalse("anonymous CAN fork!", user.canFork(repository));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Aggregations

UserModel (com.gitblit.models.UserModel)230 Test (org.junit.Test)127 RepositoryModel (com.gitblit.models.RepositoryModel)116 Date (java.util.Date)88 TeamModel (com.gitblit.models.TeamModel)58 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)16 File (java.io.File)15 HashMap (java.util.HashMap)11 Label (org.apache.wicket.markup.html.basic.Label)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Repository (org.eclipse.jgit.lib.Repository)9 HashSet (java.util.HashSet)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ProjectModel (com.gitblit.models.ProjectModel)7 Map (java.util.Map)7 GitBlitException (com.gitblit.GitBlitException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 List (java.util.List)6 Fragment (org.apache.wicket.markup.html.panel.Fragment)5