| | |
| | | import org.junit.BeforeClass;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.AccessPermission;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.RpcServlet;
|
| | | import com.gitblit.models.RegistrantAccessPermission;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.FederationProposal;
|
| | | import com.gitblit.models.FederationSet;
|
| | |
| | | model.description = "created by RpcUtils";
|
| | | model.owner = "garbage";
|
| | | model.accessRestriction = AccessRestrictionType.VIEW;
|
| | | model.authorizationControl = AuthorizationControl.AUTHENTICATED;
|
| | |
|
| | | // create
|
| | | assertTrue("Failed to create repository!",
|
| | |
| | | RepositoryModel retrievedRepository = findRepository(model.name);
|
| | | assertNotNull("Failed to find " + model.name, retrievedRepository);
|
| | | assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
|
| | | assertEquals(AuthorizationControl.AUTHENTICATED, retrievedRepository.authorizationControl);
|
| | |
|
| | | // rename and change access restriciton
|
| | | String originalName = model.name;
|
| | | model.name = "garbagerepo2.git";
|
| | | model.accessRestriction = AccessRestrictionType.PUSH;
|
| | | model.authorizationControl = AuthorizationControl.NAMED;
|
| | | assertTrue("Failed to update repository!", RpcUtils.updateRepository(originalName, model,
|
| | | url, account, password.toCharArray()));
|
| | |
|
| | |
| | | UserModel testMember = new UserModel("justadded");
|
| | | assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));
|
| | |
|
| | | List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,
|
| | | List<RegistrantAccessPermission> permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,
|
| | | password.toCharArray());
|
| | | assertEquals("Membership roster is not empty!", 0, members.size());
|
| | | members.add(testMember.username);
|
| | | assertEquals("Membership permissions is not empty!", 0, permissions.size());
|
| | | permissions.add(new RegistrantAccessPermission(testMember.username, AccessPermission.PUSH, PermissionType.EXPLICIT, RegistrantType.USER, null, true));
|
| | | assertTrue(
|
| | | "Failed to set memberships!",
|
| | | RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,
|
| | | "Failed to set member permissions!",
|
| | | RpcUtils.setRepositoryMemberPermissions(retrievedRepository, permissions, url, account,
|
| | | password.toCharArray()));
|
| | | members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,
|
| | | permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,
|
| | | password.toCharArray());
|
| | | boolean foundMember = false;
|
| | | for (String member : members) {
|
| | | if (member.equalsIgnoreCase(testMember.username)) {
|
| | | for (RegistrantAccessPermission permission : permissions) {
|
| | | if (permission.registrant.equalsIgnoreCase(testMember.username)) {
|
| | | foundMember = true;
|
| | | assertEquals(AccessPermission.PUSH, permission.permission);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | // Create the A-Team
|
| | | TeamModel aTeam = new TeamModel("A-Team");
|
| | | aTeam.users.add("admin");
|
| | | aTeam.repositories.add("helloworld.git");
|
| | | aTeam.addRepositoryPermission("helloworld.git");
|
| | | assertTrue(RpcUtils.createTeam(aTeam, url, account, password.toCharArray()));
|
| | |
|
| | | aTeam = null;
|
| | |
| | | }
|
| | | assertNotNull(aTeam);
|
| | | assertTrue(aTeam.hasUser("admin"));
|
| | | assertTrue(aTeam.hasRepository("helloworld.git"));
|
| | | assertTrue(aTeam.hasRepositoryPermission("helloworld.git"));
|
| | |
|
| | | RepositoryModel helloworld = null;
|
| | | Map<String, RepositoryModel> repositories = RpcUtils.getRepositories(url, account,
|
| | |
| | | assertTrue(helloworldTeams.contains(aTeam.name));
|
| | |
|
| | | // set no teams
|
| | | assertTrue(RpcUtils.setRepositoryTeams(helloworld, new ArrayList<String>(), url, account,
|
| | | List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();
|
| | | for (String team : helloworldTeams) {
|
| | | permissions.add(new RegistrantAccessPermission(team, AccessPermission.NONE, PermissionType.EXPLICIT, RegistrantType.TEAM, null, true));
|
| | | }
|
| | | assertTrue(RpcUtils.setRepositoryTeamPermissions(helloworld, permissions, url, account,
|
| | | password.toCharArray()));
|
| | | helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account,
|
| | | password.toCharArray());
|
| | |
| | | // restore setting
|
| | | newValue = !newValue;
|
| | | updated.put(Keys.web.showRepositorySizes, String.valueOf(newValue));
|
| | | success = RpcUtils.updateSettings(updated, url, account, password.toCharArray());
|
| | | assertTrue("Failed to update server settings", success);
|
| | | settings = RpcUtils.getSettings(url, account, password.toCharArray());
|
| | | showSizes = settings.get(Keys.web.showRepositorySizes).getBoolean(true);
|
| | | assertEquals(newValue, showSizes);
|
| | | }
|
| | |
|
| | | @Test
|