use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class RpcTests method testFork.
@Test
public void testFork() throws Exception {
// test forking by an administrator
// admins are all-powerful and can fork the unforakable :)
testFork(account, password, true, true);
testFork(account, password, false, true);
// test forking by a permitted normal user
UserModel forkUser = new UserModel("forkuser");
forkUser.password = forkUser.username;
forkUser.canFork = true;
RpcUtils.deleteUser(forkUser, url, account, password.toCharArray());
RpcUtils.createUser(forkUser, url, account, password.toCharArray());
testFork(forkUser.username, forkUser.password, true, true);
testFork(forkUser.username, forkUser.password, false, false);
RpcUtils.deleteUser(forkUser, url, account, password.toCharArray());
// test forking by a non-permitted normal user
UserModel noForkUser = new UserModel("noforkuser");
noForkUser.password = noForkUser.username;
noForkUser.canFork = false;
RpcUtils.deleteUser(noForkUser, url, account, password.toCharArray());
RpcUtils.createUser(noForkUser, url, account, password.toCharArray());
testFork(forkUser.username, forkUser.password, true, false);
testFork(forkUser.username, forkUser.password, false, false);
RpcUtils.deleteUser(noForkUser, url, account, password.toCharArray());
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class RpcTests method testUserAdministration.
@Test
public void testUserAdministration() throws IOException {
UserModel user = new UserModel("garbage");
user.canAdmin = true;
user.password = "whocares";
// create
assertTrue("Failed to create user!", RpcUtils.createUser(user, url, account, password.toCharArray()));
UserModel retrievedUser = findUser(user.username);
assertNotNull("Failed to find " + user.username, retrievedUser);
assertTrue("Retrieved user can not administer Gitblit", retrievedUser.canAdmin);
// rename and toggle admin permission
String originalName = user.username;
user.username = "garbage2";
user.canAdmin = false;
assertTrue("Failed to update user!", RpcUtils.updateUser(originalName, user, url, account, password.toCharArray()));
retrievedUser = findUser(user.username);
assertNotNull("Failed to find " + user.username, retrievedUser);
assertTrue("Retrieved user did not update", !retrievedUser.canAdmin);
// delete
assertTrue("Failed to delete " + user.username, RpcUtils.deleteUser(retrievedUser, url, account, password.toCharArray()));
retrievedUser = findUser(user.username);
assertNull("Failed to delete " + user.username, retrievedUser);
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class UserModelTest method whenDisplayNameIsNullUsernameIsUsed.
@Test
public void whenDisplayNameIsNullUsernameIsUsed() {
String username = "test";
UserModel userModel = new UserModel(username);
userModel.displayName = null;
assertEquals("When displayName is null the username has to be returnd from getDisplayName().", username, userModel.getDisplayName());
}
use of com.gitblit.models.UserModel in project gitblit by gitblit.
the class PermissionsTest method testNamed_PUSH_PUSH.
/**
* PUSH_PUSH = PUSH access restriction, PUSH access permission
*/
@Test
public void testNamed_PUSH_PUSH() 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.PUSH);
assertTrue("named CAN NOT view!", user.canView(repository));
assertTrue("named CAN NOT clone!", user.canClone(repository));
assertTrue("named CAN NOT 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.PUSH, 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_NONE_CREATE.
/**
* NONE_CREATE = NO access restriction, CREATE access permission
* (not useful scenario)
*/
@Test
public void testTeamMember_NONE_CREATE() throws Exception {
RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
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));
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);
}
Aggregations