use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class PermissionsTest method testOwnerPersonalRepository.
@Test
public void testOwnerPersonalRepository() throws Exception {
RepositoryModel repository = new RepositoryModel("~test/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("user CAN NOT view!", user.canView(repository));
assertTrue("user CAN NOT clone!", user.canClone(repository));
assertTrue("user CAN NOT push!", user.canPush(repository));
assertTrue("user CAN NOT create ref!", user.canCreateRef(repository));
assertTrue("user CAN NOT delete ref!", user.canDeleteRef(repository));
assertTrue("user CAN NOT rewind ref!", user.canRewindRef(repository));
assertEquals("user has wrong permission!", AccessPermission.REWIND, user.getRepositoryPermission(repository).permission);
assertFalse("user CAN fork!", user.canFork(repository));
assertTrue("user CAN NOT delete!", user.canDelete(repository));
assertTrue("user CAN NOT edit!", user.canEdit(repository));
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class PermissionsTest method testNamed_VIEW_CREATE.
/**
* VIEW_CREATE = VIEW access restriction, CREATE access permission
*/
@Test
public void testNamed_VIEW_CREATE() 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");
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));
}
use of com.gitblit.models.UserModel 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);
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class PermissionsTest method testTeamMember_CLONE_DELETE.
/**
* CLONE_DELETE = CLONE access restriction, DELETE access permission
*/
@Test
public void testTeamMember_CLONE_DELETE() 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.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);
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class PermissionsTest method testNamed_NONE_NONE.
/**
* NONE_NONE = NO access restriction, NO access permission
*/
@Test
public void testNamed_NONE_NONE() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
UserModel user = new UserModel("test");
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 ref!", user.canDeleteRef(repository));
assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
assertEquals("named has wrong permission!", AccessPermission.REWIND, 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));
assertFalse("named CAN delete!", user.canDelete(repository));
assertFalse("named CAN edit!", user.canEdit(repository));
}
Aggregations