Search in sources :

Example 16 with RepositoryModel

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

Example 17 with RepositoryModel

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

the class PermissionsTest method testTeamMember_PUSH_PUSH.

/**
 * PUSH_PUSH = PUSH access restriction, PUSH access permission
 */
@Test
public void testTeamMember_PUSH_PUSH() 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.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 18 with RepositoryModel

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

the class PermissionsTest method testTeamMember_PUSH_REWIND.

/**
 * PUSH_REWIND = PUSH access restriction, REWIND access permission
 */
@Test
public void testTeamMember_PUSH_REWIND() 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.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 19 with RepositoryModel

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

the class PermissionsTest method testTeam_CLONE_PUSH.

/**
 * CLONE_PUSH = CLONE access restriction, PUSH access permission
 */
@Test
public void testTeam_CLONE_PUSH() 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.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 20 with RepositoryModel

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

the class PermissionsTest method testTeamMember_CLONE_VIEW.

/**
 * CLONE_VIEW = CLONE access restriction, VIEW access permission
 */
@Test
public void testTeamMember_CLONE_VIEW() 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.VIEW);
    UserModel user = new UserModel("test");
    user.teams.add(team);
    assertTrue("team member CAN NOT view!", user.canView(repository));
    assertFalse("team member CAN 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.VIEW, 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

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