Search in sources :

Example 71 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserFinderTest method testSearchByRoles.

@Test
public void testSearchByRoles() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    final SUser user30 = createUser("user30");
    final SUser user40 = createUser("user40");
    final SUser user50 = createUser("user50");
    final SUser user60 = createUser("user60");
    final SUser user70 = createUser("user70");
    final SUser user100 = createUser("user100");
    final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
    final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
    group10.addSubgroup(group20);
    group10.addUser(user60);
    group20.addUser(user70);
    ProjectEx prj1 = createProject("prj1");
    ProjectEx prj1_1 = prj1.createProject("prj1_1", "prj1.1");
    ProjectEx prj3 = createProject("prj3");
    RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.LABEL_BUILD), null);
    myFixture.getRolesManager().addRole(role10);
    RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.PIN_UNPIN_BUILD), myFixture.getRolesManager());
    role20.addIncludedRole(role10);
    myFixture.getRolesManager().addRole(role20);
    RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.LABEL_BUILD, Permission.CANCEL_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role30);
    user10.addRole(RoleScope.globalScope(), getSysAdminRole());
    user20.addRole(RoleScope.globalScope(), getProjectAdminRole());
    user30.addRole(RoleScope.projectScope(prj1.getProjectId()), getProjectViewerRole());
    user40.addRole(RoleScope.projectScope(prj1_1.getProjectId()), getProjectViewerRole());
    user50.addRole(RoleScope.projectScope(prj3.getProjectId()), getProjectViewerRole());
    user50.addRole(RoleScope.globalScope(), role30);
    group10.addRole(RoleScope.projectScope(prj1.getProjectId()), role20);
    group10.addRole(RoleScope.projectScope(getRootProject().getProjectId()), getTestRoles().getProjectViewerRole());
    check(null, user10, user20, user30, user40, user50, user60, user70, user100);
    check("role:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:" + getProjectAdminRole().getId() + "))", user20);
    check("role:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10))", user60, user70);
    check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)),method:effective)", user60, user70);
    check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)))", user60, user70);
    check("role:(item:(scope:(project:(" + prj1_1.getExternalId() + ")),role:(id:role10)),method:byPermission)", user10, user20, user50, user60, user70);
    check("role:(scope:global)", user10, user20, user50);
    // todo: error locators
    checkExceptionOnItemsSearch(LocatorProcessException.class, "role:(aaa)");
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) SUser(jetbrains.buildServer.users.SUser) RoleImpl(jetbrains.buildServer.serverSide.impl.auth.RoleImpl) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

Example 72 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserFinderTest method testSearchByPermissions.

@Test
public void testSearchByPermissions() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    final SUser user30 = createUser("user30");
    final SUser user40 = createUser("user40");
    final SUser user50 = createUser("user50");
    final SUser user60 = createUser("user60");
    final SUser user70 = createUser("user70");
    final SUser user100 = createUser("user100");
    final SUserGroup group10 = myFixture.createUserGroup("group1", "group 1", "");
    final SUserGroup group20 = myFixture.createUserGroup("group1.1", "group 1.1", "");
    group10.addSubgroup(group20);
    group20.addUser(user70);
    ProjectEx prj1 = createProject("prj1");
    ProjectEx prj1_1 = prj1.createProject("prj1_1", "prj1.1");
    ProjectEx prj3 = createProject("prj3");
    RoleImpl role10 = new RoleImpl("role10", "custom role", new Permissions(Permission.RUN_BUILD), null);
    myFixture.getRolesManager().addRole(role10);
    RoleImpl role20 = new RoleImpl("role20", "custom role", new Permissions(Permission.VIEW_PROJECT, Permission.CHANGE_SERVER_SETTINGS), myFixture.getRolesManager());
    role20.addIncludedRole(role10);
    myFixture.getRolesManager().addRole(role20);
    RoleImpl role30 = new RoleImpl("role30", "custom role", new Permissions(Permission.LABEL_BUILD, Permission.CANCEL_BUILD), myFixture.getRolesManager());
    myFixture.getRolesManager().addRole(role30);
    user10.addRole(RoleScope.globalScope(), getSysAdminRole());
    user30.addRole(RoleScope.projectScope(prj3.getProjectId()), role10);
    group10.addRole(RoleScope.projectScope(prj1.getProjectId()), role20);
    check(null, user10, user20, user30, user40, user50, user60, user70, user100);
    check("permission:(permission:run_build,project:(id:" + prj1_1.getExternalId() + "))", user10, user70);
    checkExceptionOnItemsSearch(LocatorProcessException.class, "permission:(permission:run_build,permission:label_build,project:(id:" + prj1_1.getExternalId() + "))");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "permission:(permission:run_build,project:(id:a),project:(id:b))");
    assertContains(checkException(LocatorProcessException.class, () -> getFinder().getItems("permission:(project:(id:a))"), null).getMessage(), "Nothing found");
    // global permission check
    check("permission:(permission:run_build)", user10);
    check("permission:(permission:run_build,project:(item:" + prj3.getExternalId() + "))", user10, user30);
    check("permission:(permission:run_build,project:(item:" + prj1_1.getExternalId() + ",item:" + prj3.getExternalId() + "))", user10, user30, // permission in one of the projects
    user70);
    // permission in any project of the first 100
    check("permission:(permission:run_build,project:(count:100))", user10, user30, user70);
}
Also used : ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) SUser(jetbrains.buildServer.users.SUser) RoleImpl(jetbrains.buildServer.serverSide.impl.auth.RoleImpl) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

Example 73 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class UserFinderTest method testHasPassword.

@Test
public void testHasPassword() throws Throwable {
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    user20.setPassword("pwd");
    final SUser user30 = createUser("user30");
    user30.setPassword("");
    final SUser user40 = createUser("user40");
    user40.setPassword("aaa");
    user40.setPassword(null);
    check(null, user10, user20, user30, user40);
    check("hasPassword:true", user20, user30);
    check("hasPassword:false", user10, user40);
    check("hasPassword:any", user10, user20, user30, user40);
    check("username:user20,hasPassword:true", user20);
    check("username:user20,hasPassword:false");
    check("username:user20,hasPassword:any", user20);
    long delay = 500;
    // disable delay in tests
    setInternalProperty("rest.request.users.passwordCheckDelay.ms", String.valueOf(delay));
    final Stopwatch start = Stopwatch.createStarted();
    check("password:pwd", user20);
    System.out.println("Elapsed ms: " + start.elapsed(TimeUnit.MILLISECONDS));
    // check the elapsed time is at least twice the period (once for multiple items search, once - for single items search)
    assertTrue(start.elapsed(TimeUnit.MILLISECONDS) > 2 * delay - 100);
    // check the elapsed time is not more then twice the time wait
    assertTrue(start.elapsed(TimeUnit.MILLISECONDS) < 3 * delay);
    // disable delay in tests
    setInternalProperty("rest.request.users.passwordCheckDelay.ms", "0");
    final Stopwatch start2 = Stopwatch.createStarted();
    check("password:pwd", user20);
    System.out.println("Elapsed ms: " + start2.elapsed(TimeUnit.MILLISECONDS));
    // check the elapsed time without wait is small
    assertTrue(start2.elapsed(TimeUnit.MILLISECONDS) < delay - 1);
    check("password:()", user30);
}
Also used : SUser(jetbrains.buildServer.users.SUser) Stopwatch(com.google.common.base.Stopwatch) Test(org.testng.annotations.Test)

Example 74 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTest method testBuildTriggeringWithCustomFeatures.

@Test
public void testBuildTriggeringWithCustomFeatures() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    buildType1.addBuildFeature("featureType", createMap("a", "b"));
    // add other settings: requirements, features and check that they can be reset
    final SUser user = getOrCreateUser("user");
    // end of setup
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        build.setBuildType(buildTypeEntity);
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        // noinspection ConstantConditions
        assertEquals(1, ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildFeatures().size());
    }
    {
        final Build build = new Build();
        final BuildType buildTypeEntity = new BuildType();
        buildTypeEntity.setId(buildType1.getExternalId());
        PropEntitiesFeature features = new PropEntitiesFeature();
        PropEntityFeature feature = new PropEntityFeature();
        feature.type = "feature2";
        feature.properties = new Properties(createMap("x", "y"), null, Fields.ALL, getBeanContext(myFixture));
        features.propEntities = Arrays.asList(feature);
        buildTypeEntity.setFeatures(features);
        build.setBuildType(buildTypeEntity);
        SQueuedBuild result = build.triggerBuild(user, myFixture, new HashMap<Long, Long>());
        // noinspection ConstantConditions
        Collection<? extends SBuildFeatureDescriptor> actualFeatures = ((BuildPromotionEx) result.getBuildPromotion()).getBuildSettings().getBuildFeatures();
        assertEquals(1, actualFeatures.size());
        assertEquals("feature2", actualFeatures.iterator().next().getType());
    }
}
Also used : Build(jetbrains.buildServer.server.rest.model.build.Build) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 75 with SUser

use of jetbrains.buildServer.users.SUser in project teamcity-rest by JetBrains.

the class BuildTypeTest method testInvestigations.

@Test
public void testInvestigations() {
    final SUser user = createUser("user");
    final BuildTypeEx bt = getRootProject().createProject("Project1", "Project test 1").createBuildType("testBT", "My test build type");
    myFixture.getResponsibilityFacadeEx().setBuildTypeResponsibility(bt, createRespEntry(ResponsibilityEntry.State.TAKEN, user));
    BuildType buildType = new BuildType(new BuildTypeOrTemplate(bt), Fields.LONG, myBeanContext);
    Investigations investigations = buildType.getInvestigations();
    assertEquals(null, investigations.count);
    assertEquals("/app/rest/investigations?locator=buildType:(id:testBT)", investigations.href);
    assertEquals(null, investigations.items);
    buildType = new BuildType(new BuildTypeOrTemplate(bt), new Fields("investigations($long)"), myBeanContext);
    investigations = buildType.getInvestigations();
    assertEquals(new Integer(1), investigations.count);
    assertEquals("/app/rest/investigations?locator=buildType:(id:testBT)", investigations.href);
    assertEquals(1, investigations.items.size());
    assertEquals(ResponsibilityEntry.State.TAKEN.name(), investigations.items.get(0).state);
    buildType = new BuildType(new BuildTypeOrTemplate(bt), new Fields("investigations($long,$locator(assignee(id:" + user.getId() + ")))"), myBeanContext);
    investigations = buildType.getInvestigations();
    assertEquals(new Integer(1), investigations.count);
    assertEquals("/app/rest/investigations?locator=assignee:(id:" + user.getId() + "),buildType:(id:testBT)", investigations.href);
    assertEquals(1, investigations.items.size());
    assertEquals(ResponsibilityEntry.State.TAKEN.name(), investigations.items.get(0).state);
    final SUser user2 = createUser("user2");
    buildType = new BuildType(new BuildTypeOrTemplate(bt), new Fields("investigations($long,count,$locator(assignee(id:" + user2.getId() + ")))"), myBeanContext);
    investigations = buildType.getInvestigations();
    assertEquals(new Integer(0), investigations.count);
    assertEquals("/app/rest/investigations?locator=assignee:(id:" + user2.getId() + "),buildType:(id:testBT)", investigations.href);
    assertNull(investigations.items);
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SUser(jetbrains.buildServer.users.SUser) BuildType(jetbrains.buildServer.server.rest.model.buildType.BuildType) Investigations(jetbrains.buildServer.server.rest.model.buildType.Investigations) Test(org.testng.annotations.Test) ProjectRequestTest(jetbrains.buildServer.server.rest.request.ProjectRequestTest) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

SUser (jetbrains.buildServer.users.SUser)125 Test (org.testng.annotations.Test)70 ApiOperation (io.swagger.annotations.ApiOperation)35 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)35 Build (jetbrains.buildServer.server.rest.model.build.Build)20 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)18 NotNull (org.jetbrains.annotations.NotNull)18 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)15 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)13 Fields (jetbrains.buildServer.server.rest.model.Fields)12 SUserGroup (jetbrains.buildServer.groups.SUserGroup)11 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)10 ServiceLocator (jetbrains.buildServer.ServiceLocator)9 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)9 Nullable (org.jetbrains.annotations.Nullable)9 LocatorProcessException (jetbrains.buildServer.server.rest.errors.LocatorProcessException)8 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)8 java.util (java.util)7 Collectors (java.util.stream.Collectors)7 jetbrains.buildServer.serverSide (jetbrains.buildServer.serverSide)7