Search in sources :

Example 36 with RepositoryModel

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

the class PermissionsTest method testTeam_VIEW_VIEW.

/**
 * VIEW_VIEW = VIEW access restriction, VIEW access permission
 */
@Test
public void testTeam_VIEW_VIEW() 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.VIEW);
    assertTrue("team CAN NOT view!", team.canView(repository));
    assertFalse("team CAN 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.VIEW, 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 37 with RepositoryModel

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

the class PermissionsTest method testNamed_CLONE_NONE.

/**
 * CLONE_NONE = CLONE access restriction, NO access permission
 */
@Test
public void testNamed_CLONE_NONE() 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");
    assertTrue("named CAN NOT 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.VIEW, 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 38 with RepositoryModel

use of com.gitblit.models.RepositoryModel 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 39 with RepositoryModel

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

the class PermissionsTest method testTeamMember_CLONE_REWIND.

/**
 * CLONE_REWIND = CLONE access restriction, REWIND access permission
 */
@Test
public void testTeamMember_CLONE_REWIND() 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.REWIND);
    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)

Example 40 with RepositoryModel

use of com.gitblit.models.RepositoryModel 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)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)236 Test (org.junit.Test)146 Date (java.util.Date)135 UserModel (com.gitblit.models.UserModel)116 TeamModel (com.gitblit.models.TeamModel)68 ArrayList (java.util.ArrayList)39 File (java.io.File)21 Repository (org.eclipse.jgit.lib.Repository)20 CloneCommand (org.eclipse.jgit.api.CloneCommand)16 Git (org.eclipse.jgit.api.Git)13 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)13 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)12 GitBlitException (com.gitblit.GitBlitException)11 Label (org.apache.wicket.markup.html.basic.Label)11 PushResult (org.eclipse.jgit.transport.PushResult)10 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)10 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)9 BufferedWriter (java.io.BufferedWriter)9 FileOutputStream (java.io.FileOutputStream)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9