Search in sources :

Example 76 with UserModel

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

the class PermissionsTest method testNamed_PUSH_CREATE.

/**
	 * PUSH_CREATE = PUSH access restriction, CREATE access permission
	 */
@Test
public void testNamed_PUSH_CREATE() throws Exception {
    RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.PUSH;
    UserModel user = new UserModel("test");
    user.setRepositoryPermission(repository.name, AccessPermission.CREATE);
    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));
    assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("named has wrong permission!", AccessPermission.CREATE, 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 77 with UserModel

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

the class PermissionsTest method testTeamMember_VIEW_CREATE.

/**
	 * VIEW_CREATE = VIEW access restriction, CREATE access permission
	 */
@Test
public void testTeamMember_VIEW_CREATE() 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.CREATE);
    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));
    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.CREATE, 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 78 with UserModel

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

the class PermissionsTest method testOwner.

@Test
public void testOwner() throws Exception {
    RepositoryModel repository = new RepositoryModel("~jj/myrepo.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    UserModel user = new UserModel("test");
    repository.addOwner(user.username);
    assertFalse("user SHOULD NOT HAVE a repository permission!", user.hasRepositoryPermission(repository.name));
    assertTrue("owner CAN NOT view!", user.canView(repository));
    assertTrue("owner CAN NOT clone!", user.canClone(repository));
    assertTrue("owner CAN NOT push!", user.canPush(repository));
    assertTrue("owner CAN NOT create ref!", user.canCreateRef(repository));
    assertTrue("owner CAN NOT delete ref!", user.canDeleteRef(repository));
    assertTrue("owner CAN NOT rewind ref!", user.canRewindRef(repository));
    assertEquals("owner has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
    assertTrue("owner CAN NOT fork!", user.canFork(repository));
    assertFalse("owner CAN NOT delete!", user.canDelete(repository));
    assertTrue("owner CAN NOT edit!", user.canEdit(repository));
    // test personal repo owner
    UserModel jj = new UserModel("jj");
    assertFalse("jj SHOULD NOT HAVE a repository permission!", jj.hasRepositoryPermission(repository.name));
    assertTrue("jj CAN NOT view!", jj.canView(repository));
    assertTrue("jj CAN NOT clone!", jj.canClone(repository));
    assertTrue("jj CAN NOT push!", jj.canPush(repository));
    assertTrue("jj CAN NOT create ref!", jj.canCreateRef(repository));
    assertTrue("jj CAN NOT delete ref!", jj.canDeleteRef(repository));
    assertTrue("jj CAN NOT rewind ref!", jj.canRewindRef(repository));
    assertEquals("jj has wrong permission!", AccessPermission.REWIND, jj.getRepositoryPermission(repository).permission);
    assertFalse("jj CAN fork!", jj.canFork(repository));
    assertTrue("jj CAN NOT delete!", jj.canDelete(repository));
    assertTrue("jj CAN NOT edit!", jj.canEdit(repository));
    assertTrue(repository.isOwner(jj.username));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 79 with UserModel

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

the class PermissionsTest method testTeamMember_PUSH_NONE.

/**
	 * PUSH_NONE = PUSH access restriction, NO access permission
	 */
@Test
public void testTeamMember_PUSH_NONE() 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");
    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 80 with UserModel

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

the class PermissionsTest method testRegexMatching.

@Test
public void testRegexMatching() throws Exception {
    RepositoryModel repository = new RepositoryModel("ubercool/_my-r/e~po.git", null, null, new Date());
    repository.authorizationControl = AuthorizationControl.NAMED;
    repository.accessRestriction = AccessRestrictionType.VIEW;
    UserModel user = new UserModel("test");
    user.setRepositoryPermission("ubercool/[A-Z0-9-~_\\./]+", AccessPermission.CLONE);
    assertTrue("user DOES NOT HAVE a repository permission!", user.hasRepositoryPermission(repository.name));
    assertTrue("user CAN NOT view!", user.canView(repository));
    assertTrue("user CAN NOT clone!", user.canClone(repository));
    assertFalse("user CAN push!", user.canPush(repository));
    assertFalse("user CAN create ref!", user.canCreateRef(repository));
    assertFalse("user CAN delete ref!", user.canDeleteRef(repository));
    assertFalse("user CAN rewind ref!", user.canRewindRef(repository));
    assertEquals("user has wrong permission!", AccessPermission.CLONE, user.getRepositoryPermission(repository).permission);
    assertFalse("user CAN fork!", user.canFork(repository));
    assertFalse("user CAN delete!", user.canDelete(repository));
    assertFalse("user CAN edit!", user.canEdit(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