Search in sources :

Example 21 with UserModel

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());
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 22 with UserModel

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);
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 23 with UserModel

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());
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 24 with UserModel

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));
}
Also used : UserModel(com.gitblit.models.UserModel) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 25 with UserModel

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);
}
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

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