Search in sources :

Example 51 with UserModel

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

the class Issue0259Test method testTeam.

/**
	 * Test a single team that has multiple repository permissions that all match.
	 * Here defined order IS important.  The first permission match wins so it is
	 * important to define permissions from most-specific match to least-specific
	 * match.
	 *
	 * If the defined permissions are:
	 *   R:.*
	 *   RWD:projects/.*
	 * then the expected result is R for all repositories because it is first.
	 *
	 * But if the defined permissions are:
	 *   RWD:projects/.*
	 *   R:.*
	 * then the expected result is RWD for projects/test.git and R for test.git
	 *
	 * @param reverseOrder
	 * @throws Exception
	 */
private void testTeam(boolean reverseOrder) throws Exception {
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    TeamModel t1 = new TeamModel("t1");
    if (reverseOrder) {
        t1.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
        t1.setRepositoryPermission(".*", AccessPermission.CLONE);
    } else {
        t1.setRepositoryPermission(".*", AccessPermission.CLONE);
        t1.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
    }
    UserModel a = new UserModel("a");
    a.teams.add(t1);
    // simulate a repository rename
    a.setRepositoryPermission("projects/renamed.git", null);
    t1.setRepositoryPermission("projects/renamed.git", null);
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertTrue(a.canClone(test));
    assertFalse(a.canDeleteRef(test));
    assertTrue(a.canClone(projects_test));
    if (reverseOrder) {
        // RWD permission is found first
        assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
        assertTrue(a.canDeleteRef(projects_test));
    } else {
        // R permission is found first
        assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(projects_test).permission);
        assertFalse(a.canDeleteRef(projects_test));
    }
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 52 with UserModel

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

the class Issue0259Test method testTeams.

/**
	 * Tests multiple teams each with a regex permisson that will match.  The
	 * highest matching permission should be used.  Order should be irrelevant.
	 *
	 * @param reverseOrder
	 * @throws Exception
	 */
private void testTeams(boolean reverseOrder) throws Exception {
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    TeamModel t1 = new TeamModel("t1");
    t1.setRepositoryPermission(".*", AccessPermission.CLONE);
    TeamModel t2 = new TeamModel("t2");
    t2.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
    UserModel a = new UserModel("a");
    if (reverseOrder) {
        a.teams.add(t2);
        a.teams.add(t1);
    } else {
        a.teams.add(t1);
        a.teams.add(t2);
    }
    // simulate a repository rename
    a.setRepositoryPermission("projects/renamed.git", null);
    t1.setRepositoryPermission("projects/renamed.git", null);
    t2.setRepositoryPermission("projects/renamed.git", null);
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
    assertTrue(a.canClone(test));
    assertTrue(a.canClone(projects_test));
    assertFalse(a.canDeleteRef(test));
    assertTrue(a.canDeleteRef(projects_test));
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 53 with UserModel

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

the class Issue0271Test method testFile.

/**
	 * Test the provided users.conf file for expected access permissions.
	 *
	 * @throws Exception
	 */
@Test
public void testFile() throws Exception {
    File realmFile = new File("src/test/resources/issue0271.conf");
    ConfigUserService service = new ConfigUserService(realmFile);
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel teama_test = repo("teama/test.git", AccessRestrictionType.VIEW);
    UserModel a = service.getUserModel("a");
    UserModel b = service.getUserModel("b");
    UserModel c = service.getUserModel("c");
    // assert V for test.git
    assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.VIEW, b.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.VIEW, c.getRepositoryPermission(test).permission);
    // assert expected permissions for teama/test.git
    assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(teama_test).permission);
    assertEquals(AccessPermission.PUSH, b.getRepositoryPermission(teama_test).permission);
    assertEquals(AccessPermission.CREATE, c.getRepositoryPermission(teama_test).permission);
}
Also used : UserModel(com.gitblit.models.UserModel) ConfigUserService(com.gitblit.ConfigUserService) RepositoryModel(com.gitblit.models.RepositoryModel) File(java.io.File) Test(org.junit.Test)

Example 54 with UserModel

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

the class LdapAuthenticationTest method testAuthenticate.

@Test
public void testAuthenticate() {
    UserModel userOneModel = ldap.authenticate("UserOne", "userOnePassword".toCharArray());
    assertNotNull(userOneModel);
    assertNotNull(userOneModel.getTeam("git_admins"));
    assertNotNull(userOneModel.getTeam("git_users"));
    UserModel userOneModelFailedAuth = ldap.authenticate("UserOne", "userTwoPassword".toCharArray());
    assertNull(userOneModelFailedAuth);
    UserModel userTwoModel = ldap.authenticate("UserTwo", "userTwoPassword".toCharArray());
    assertNotNull(userTwoModel);
    assertNotNull(userTwoModel.getTeam("git_users"));
    assertNull(userTwoModel.getTeam("git_admins"));
    assertNotNull(userTwoModel.getTeam("git admins"));
    UserModel userThreeModel = ldap.authenticate("UserThree", "userThreePassword".toCharArray());
    assertNotNull(userThreeModel);
    assertNotNull(userThreeModel.getTeam("git_users"));
    assertNull(userThreeModel.getTeam("git_admins"));
    UserModel userFourModel = ldap.authenticate("UserFour", "userFourPassword".toCharArray());
    assertNotNull(userFourModel);
    assertNotNull(userFourModel.getTeam("git_users"));
    assertNull(userFourModel.getTeam("git_admins"));
    assertNull(userFourModel.getTeam("git admins"));
}
Also used : UserModel(com.gitblit.models.UserModel) Test(org.junit.Test)

Example 55 with UserModel

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

the class LdapAuthenticationTest method testAuthenticationManagerAdminPropertyTeamsNotInLdap.

@Test
public void testAuthenticationManagerAdminPropertyTeamsNotInLdap() {
    settings.put(Keys.realm.ldap.maintainTeams, "false");
    UserModel userOneModel = auth.authenticate("UserOne", "userOnePassword".toCharArray(), null);
    assertNotNull(userOneModel);
    assertNotNull(userOneModel.getTeam("git_admins"));
    assertNull(userOneModel.getTeam("git admins"));
    assertNotNull(userOneModel.getTeam("git_users"));
    assertTrue(userOneModel.canAdmin);
    assertTrue(userOneModel.canAdmin());
    assertFalse(userOneModel.getTeam("git_admins").canAdmin);
    assertFalse(userOneModel.getTeam("git_users").canAdmin);
    UserModel userOneModelFailedAuth = auth.authenticate("UserOne", "userTwoPassword".toCharArray(), null);
    assertNull(userOneModelFailedAuth);
    UserModel userTwoModel = auth.authenticate("UserTwo", "userTwoPassword".toCharArray(), null);
    assertNotNull(userTwoModel);
    assertNotNull(userTwoModel.getTeam("git_users"));
    assertNull(userTwoModel.getTeam("git_admins"));
    assertNotNull(userTwoModel.getTeam("git admins"));
    assertFalse(userTwoModel.canAdmin);
    assertTrue(userTwoModel.canAdmin());
    assertTrue(userTwoModel.getTeam("git admins").canAdmin);
    assertFalse(userTwoModel.getTeam("git_users").canAdmin);
    UserModel userThreeModel = auth.authenticate("UserThree", "userThreePassword".toCharArray(), null);
    assertNotNull(userThreeModel);
    assertNotNull(userThreeModel.getTeam("git_users"));
    assertNull(userThreeModel.getTeam("git_admins"));
    assertNull(userThreeModel.getTeam("git admins"));
    assertFalse(userThreeModel.canAdmin);
    assertFalse(userThreeModel.canAdmin());
    assertFalse(userThreeModel.getTeam("git_users").canAdmin);
    UserModel userFourModel = auth.authenticate("UserFour", "userFourPassword".toCharArray(), null);
    assertNotNull(userFourModel);
    assertNotNull(userFourModel.getTeam("git_users"));
    assertNull(userFourModel.getTeam("git_admins"));
    assertNull(userFourModel.getTeam("git admins"));
    assertFalse(userFourModel.canAdmin);
    assertFalse(userFourModel.canAdmin());
    assertFalse(userFourModel.getTeam("git_users").canAdmin);
}
Also used : UserModel(com.gitblit.models.UserModel) 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