use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class GroupRequestTest method testUsers.
@Test
void testUsers() {
SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
final SUser user1 = createUser("user1");
final SUser user2 = createUser("user2");
group1.addUser(user1);
group1.addUser(user2);
SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
final SUser user3 = createUser("user3");
group2.addUser(user3);
{
Group result = myRequest.serveGroup("key:key1", "$long,users($long)");
assertNotNull(result.users);
assertNotNull(result.users.users);
assertEquals(2, result.users.users.size());
assertEquals(Long.valueOf(user1.getId()), result.users.users.get(0).getId());
assertEquals(Long.valueOf(user2.getId()), result.users.users.get(1).getId());
}
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class InvestigationRequestTest method testAssignInvestigation.
@Test
void testAssignInvestigation() throws Throwable {
final SUser user2 = createUser("user2");
Investigation investigation = new Investigation();
investigation.state = "taken";
investigation.assignee = new User();
investigation.assignee.setId(user2.getId());
investigation.assignment = new Comment();
investigation.assignment.text = "comment here";
investigation.scope = new ProblemScope();
investigation.scope.project = new Project();
investigation.scope.project.id = myProject.getExternalId();
investigation.target = new ProblemTarget();
investigation.target.tests = new Tests();
jetbrains.buildServer.server.rest.model.problem.Test test = new jetbrains.buildServer.server.rest.model.problem.Test();
test.name = "testname";
investigation.target.tests.items = Collections.singletonList(test);
investigation.resolution = new Resolution();
investigation.resolution.type = Resolution.ResolutionType.manually;
investigation.resolution.time = "20900512T163700";
assertEmpty(myInvestigationFinder.getItems(null).myEntries);
createBuildWithFailedTest("testname");
Investigation result = myRequest.createInstance(investigation, "$long");
assertEquals("testname", result.target.tests.items.get(0).name);
List<InvestigationWrapper> currentInvestigations = myInvestigationFinder.getItems(null).myEntries;
assertEquals(1, currentInvestigations.size());
InvestigationWrapper investigationWrapper = currentInvestigations.get(0);
assertEquals(ResponsibilityEntry.State.TAKEN, investigationWrapper.getState());
assertEquals(user2.getId(), investigationWrapper.getResponsibleUser().getId());
assertEquals("comment here", investigationWrapper.getComment());
assertEquals(null, investigationWrapper.getProblemRE());
assertEquals(myProject.getProjectId(), investigationWrapper.getTestRE().getProjectId());
assertEquals("testname", investigationWrapper.getTestRE().getTestName().getAsString());
assertEquals(myProject.getProjectId(), investigationWrapper.getAssignmentProject().getProjectId());
myRequest.deleteInstance(investigationWrapper.getId());
assertEmpty(myInvestigationFinder.getItems(null).myEntries);
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildPromotionFinderTest method testPivateTags.
@Test
public void testPivateTags() {
final SProject project = createProject("prj", "project");
final BuildTypeEx buildConf1 = (BuildTypeEx) project.createBuildType("buildConf1", "buildConf1");
final BuildPromotion build10 = build().in(buildConf1).finish().getBuildPromotion();
final BuildPromotion build20 = build().in(buildConf1).tag("aaa").finish().getBuildPromotion();
final BuildPromotion build30 = build().in(buildConf1).tag("aAa").finish().getBuildPromotion();
final BuildPromotion build40 = build().in(buildConf1).finish().getBuildPromotion();
SUser user1 = getOrCreateUser("user1");
build40.setPrivateTags(Collections.singletonList("bbb"), user1);
final BuildPromotion build45 = build().in(buildConf1).finish().getBuildPromotion();
build45.setPrivateTags(Collections.singletonList("aAa"), user1);
final BuildPromotion build50 = build().in(buildConf1).finish().getBuildPromotion();
SUser user2 = getOrCreateUser("user2");
build50.setPrivateTags(Collections.singletonList("bbb"), user2);
check(null, build50, build45, build40, build30, build20, build10);
String userFilter = ",owner:(id:" + user1.getId() + ")";
check("tag:(name:aaa,private:true)", build45);
check("tag:(name:aaa,private:false)", build30, build20);
check("tag:(name:aaa,private:any)", build45, build30, build20);
// might be worth switching to private tags search, but this is the current behavior
check("tag:(name:aaa" + userFilter + ")");
check("tag:(name:aaa" + userFilter + ",private:true)", build45);
// might be worth reporting an error
check("tag:(name:aaa" + userFilter + ",private:false)");
check("tag:(name:aaa" + userFilter + ",private:any)", build45, build30, build20);
check("tag:(private:any)", build50, build45, build40, build30, build20);
check("tag:(private:any" + userFilter + ")", build45, build40, build30, build20);
// might be worth switching to private tags search, but this is the current behavior
check("tag:(" + userFilter.substring(1) + ")");
check("tag:(private:true" + userFilter + ")", build45, build40);
// might be worth reporting an error
check("tag:(private:false" + userFilter + ")");
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class BuildTypeFinderTest method testUserSelectedDimension.
@Test
public void testUserSelectedDimension() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
myBuildType.remove();
final SProject project10 = createProject("p10", "project 10");
final SProject project20 = createProject("p20", "project 20");
final SProject project10_10 = project10.createProject("p10_10", "p10 child1");
final SProject project10_20 = project10.createProject("p10_20", "p10 child2");
final SProject project10_30 = project10.createProject("p10_30", "p10 child3");
final SProject project30 = createProject(project10.getProjectId(), "project 30");
final SProject project40 = createProject("p40", "project 40");
final SBuildType p10_bt10 = project10.createBuildType("p10_bt10", "10-10");
final SBuildType p10_bt20 = project10.createBuildType("p10_bt20", "10-02");
final SBuildType p10_bt30 = project10.createBuildType("p10_bt30", "10-30");
final SBuildType p10_10_bt10 = project10_10.createBuildType("p10_10_bt10", "10_10-10");
final SBuildType p10_10_bt20 = project10_10.createBuildType("p10_10_bt20", "10_10-20");
final SBuildType p10_10_bt30 = project10_10.createBuildType("p10_10_bt30", "10_10-30");
final SBuildType p10_30_bt10 = project10_30.createBuildType("p10_30_bt10", "10_30-10");
final SBuildType p10_30_bt20 = project10_30.createBuildType("p10_30_bt20", "10_30-20");
final SBuildType p10_30_bt30 = project10_30.createBuildType("p10_30_bt30", "10_30-30");
final SBuildType p20_bt10 = project20.createBuildType("p20_bt10", "20-10");
final SBuildType p20_bt20 = project20.createBuildType("p20_bt20", "20-20");
final SBuildType p20_bt30 = project20.createBuildType("p20_bt30", "20-30");
final SBuildType p30_bt10 = project30.createBuildType("p30_bt10", "30-10");
final SBuildType p30_bt20 = project30.createBuildType("p30_bt20", "xxx 30-20");
final SBuildType p30_bt30 = project30.createBuildType("p30_bt30", "30-30");
final SBuildType p40_bt10 = project40.createBuildType("p40_bt10", "40-10");
final SBuildType p40_bt20 = project40.createBuildType("p40_bt20", "40-20");
final SBuildType p40_bt30 = project40.createBuildType("p40_bt30", "40-30");
final SUser user2 = createUser("user2");
user2.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
// default sorting is hierarchy-based + name-based within the same level
checkBuildTypes("selectedByUser:(username:user2)", p10_bt20, p10_bt10, p10_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30);
checkBuildTypes("selectedByUser:(user:(username:user2))", p10_bt20, p10_bt10, p10_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30);
checkBuildTypes("selectedByUser:(user:(username:user2),mode:selected_and_unknown)", p10_bt20, p10_bt10, p10_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30);
checkBuildTypes("selectedByUser:(user:(username:user2),mode:all_with_order)", p10_bt20, p10_bt10, p10_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30);
user2.setVisibleProjects(Arrays.asList(project10.getProjectId(), project10_30.getProjectId(), project10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
user2.setProjectsOrder(Arrays.asList(project10.getProjectId(), project10_30.getProjectId(), project10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
checkBuildTypes("selectedByUser:(username:user2)", p10_bt20, p10_bt10, p10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30);
checkBuildTypes("selectedByUser:(user:(username:user2),mode:selected_and_unknown)", p10_bt20, p10_bt10, p10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30);
checkBuildTypes("selectedByUser:(user:(username:user2),mode:all_with_order)", p10_bt20, p10_bt10, p10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30);
final SUser user1 = createUser("user1");
user1.addRole(RoleScope.projectScope(project10.getProjectId()), getProjectViewerRole());
user1.addRole(RoleScope.projectScope(project20.getProjectId()), getProjectViewerRole());
user1.addRole(RoleScope.projectScope(project30.getProjectId()), getProjectViewerRole());
user1.setVisibleProjects(Arrays.asList(project10.getProjectId(), project10_20.getProjectId(), project10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
user1.setProjectsOrder(Arrays.asList(project10.getProjectId(), project10_20.getProjectId(), project10_10.getProjectId(), project40.getProjectId(), project30.getProjectId()));
user1.setBuildTypesOrder(project10, Arrays.asList(p10_bt30, p10_bt10), Arrays.asList(p10_bt20));
// p10_10_bt30 is in "unknown" state
user1.setBuildTypesOrder(project10_10, Arrays.asList(p10_10_bt20), Arrays.asList(p10_10_bt10));
user1.setBuildTypesOrder(project10_30, Arrays.asList(p10_30_bt30, p10_30_bt20, p10_30_bt10), Collections.<SBuildType>emptyList());
user1.setBuildTypesOrder(project20, Arrays.asList(p20_bt10, p20_bt30), Arrays.asList(p20_bt20));
user1.setBuildTypesOrder(project40, Arrays.asList(p40_bt10, p40_bt30), Arrays.asList(p40_bt20));
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(username:user1),project:(id:" + project10.getExternalId() + ")", p10_bt30, p10_bt10);
checkBuildTypes("selectedByUser:(username:user1),project:(id:" + project30.getExternalId() + ")", p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:" + project10.getExternalId() + ")", p10_bt30, p10_bt10);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown),project:(id:" + project30.getExternalId() + ")", p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:" + project10.getExternalId() + ")", p10_bt30, p10_bt10, p10_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order),project:(id:" + project30.getExternalId() + ")", p30_bt10, p30_bt30, p30_bt20);
SecurityContextImpl securityContext = myFixture.getSecurityContext();
securityContext.runAs(user1, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
securityContext.runAs(user1, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(current)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(current),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(current),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
securityContext.runAs(user2, () -> {
checkExceptionOnItemsSearch(AuthorizationFailedException.class, "selectedByUser:(user:(username:user1),mode:selected_and_unknown)");
});
securityContext.runAs(user2, () -> {
checkExceptionOnItemsSearch(AuthorizationFailedException.class, "selectedByUser:(user:(username:user1),mode:all_with_order)");
});
RoleImpl role_viewUsers = new RoleImpl("role_viewUsers", "custom role", new Permissions(Permission.VIEW_ALL_USERS, Permission.VIEW_USER_PROFILE), null);
myFixture.getRolesManager().addRole(role_viewUsers);
user2.addRole(RoleScope.globalScope(), role_viewUsers);
securityContext.runAs(user2, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
user2.addRole(RoleScope.projectScope(project40.getProjectId()), getProjectViewerRole());
checkBuildTypes("selectedByUser:(username:user2)", p10_bt20, p10_bt10, p10_bt30, p10_30_bt10, p10_30_bt20, p10_30_bt30, p10_10_bt10, p10_10_bt20, p10_10_bt30, p40_bt10, p40_bt20, p40_bt30);
securityContext.runAs(user2, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
user1.addRole(RoleScope.projectScope(project40.getProjectId()), getProjectViewerRole());
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p40_bt10, p40_bt30, p30_bt10, p30_bt30, p30_bt20);
securityContext.runAs(user2, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p40_bt10, p40_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p40_bt10, p40_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p40_bt10, p40_bt30, p40_bt20, p30_bt10, p30_bt30, p30_bt20);
}
});
user2.removeRole(RoleScope.projectScope(project40.getProjectId()), getProjectViewerRole());
assertEmpty(user2.getPermissionsGrantedForProject(project40.getProjectId()).toList());
/* this fails as ProjectManager is not secure in this test
securityContext.runAs(user2, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
*/
user1.removeRole(RoleScope.projectScope(project40.getProjectId()), getProjectViewerRole());
user2.addRole(RoleScope.globalScope(), getProjectAdminRole());
securityContext.runAs(user2, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
checkBuildTypes("selectedByUser:(username:user1)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:selected_and_unknown)", p10_bt30, p10_bt10, p10_10_bt20, p10_10_bt30, p30_bt10, p30_bt30, p30_bt20);
checkBuildTypes("selectedByUser:(user:(username:user1),mode:all_with_order)", p10_bt30, p10_bt10, p10_bt20, p10_10_bt20, p10_10_bt30, p10_10_bt10, p30_bt10, p30_bt30, p30_bt20);
}
});
checkExceptionOnItemsSearch(BadRequestException.class, "selectedByUser:(user:(username:user2),mode:selected)");
// add checks after ProjectEx.setOwnProjectsOrder / setOwnBuildTypesOrder
}
use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.
the class TestOccurrenceFinderTest method testTestRunFromPersonalBuild.
@Test
public void testTestRunFromPersonalBuild() throws Throwable {
final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
SUser user = myFixture.createUserAccount("andrey");
user.addRole(RoleScope.projectScope(buildType.getProjectId()), myFixture.getTestRoles().getProjectViewerRole());
final SFinishedBuild personalBuild = build().in(buildType).personalForUser(user.getUsername()).withTest(BuildBuilder.TestData.test("aaa")).finish();
final SFinishedBuild regularBuild = build().in(buildType).withTest(BuildBuilder.TestData.test("aaa")).finish();
TestRunDataWithBuild personalRun = t("aaa", Status.NORMAL, 1, personalBuild.getBuildId());
TestRunDataWithBuild regularRun = t("aaa", Status.NORMAL, 2, regularBuild.getBuildId());
myServer.getSecurityContext().runAs(user, () -> {
check("test:(name:aaa)", TEST_MATCHER, regularRun);
check("test:(name:aaa),includePersonal:true", TEST_MATCHER, personalRun, regularRun);
check("test:(name:aaa),includePersonal:false", TEST_MATCHER, regularRun);
});
}
Aggregations