Search in sources :

Example 21 with SUser

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

the class UserFinderTest method testLastLogin.

@Test
public void testLastLogin() throws Throwable {
    final SUser user10 = createUser("user10");
    final SUser user20 = createUser("user20");
    final SUser user30 = createUser("user30");
    final MockTimeService time = new MockTimeService(Dates.now().getTime());
    myServer.setTimeService(time);
    user10.setLastLoginTimestamp(time.getNow());
    // 10 minutes
    time.jumpTo(600);
    user20.setLastLoginTimestamp(time.getNow());
    // another 10
    time.jumpTo(600);
    check(null, user10, user20, user30);
    check("lastLogin:-30m", user10, user20);
    check("lastLogin:-15m", user20);
    check("lastLogin:-15m,username:user20", user20);
    check("lastLogin:-5m");
}
Also used : SUser(jetbrains.buildServer.users.SUser) MockTimeService(jetbrains.buildServer.MockTimeService) Test(org.testng.annotations.Test)

Example 22 with SUser

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

the class UserFinderTest method testSecurity.

@Test
public void testSecurity() throws Throwable {
    myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    final SecurityContextImpl securityContext = myFixture.getSecurityContext();
    securityContext.runAs(user1, new SecurityContextEx.RunAsAction() {

        @Override
        public void run() throws Throwable {
            checkExceptionOnItemsSearch(AuthorizationFailedException.class, null);
            // this works as this is single item search actually
            check("user2", user2);
            checkExceptionOnItemsSearch(AuthorizationFailedException.class, "group:ALL_USERS_GROUP");
            check("user1", user1);
            checkException(AuthorizationFailedException.class, new Runnable() {

                @Override
                public void run() {
                    ((UserFinder) getFinder()).getItem("user2", true);
                }
            }, null);
        }
    });
}
Also used : SecurityContextImpl(jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Example 23 with SUser

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

the class UserFinderTest method testGroupLocator.

@Test
public void testGroupLocator() throws Throwable {
    SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    final SUser user25 = createUser("user25");
    group1.addUser(user1);
    group1.addUser(user2);
    group1.addUser(user25);
    SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
    final SUser user3 = createUser("user3");
    group2.addUser(user3);
    group2.addUser(user25);
    check(null, user1, user2, user25, user3);
    check("group:(key:" + group1.getKey() + ")", user1, user2, user25);
    check("group:(key:" + group2.getKey() + ")", user3, user25);
    check("group:(key:" + getUserGroupManager().getAllUsersGroup().getKey() + ")", user1, user2, user25, user3);
    check("group:(key:" + group1.getKey() + "),username:user1", user1);
    checkExceptionOnItemSearch(NotFoundException.class, "group:(key:XXX)");
    checkExceptionOnItemsSearch(NotFoundException.class, "group:(key:XXX)");
    check("group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")", user25);
}
Also used : SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

Example 24 with SUser

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

the class UserFinderTest method testSingleLocator.

@Test
public void testSingleLocator() throws Throwable {
    final SUser user1 = createUser("user1");
    {
        SUser result = myUserFinder.getItem("user1");
        assertNotNull(result);
        assertEquals(user1.getId(), result.getId());
    }
    BaseFinderTest.checkException(NotFoundException.class, new Runnable() {

        public void run() {
            myUserFinder.getItem("user1" + "2");
        }
    }, null);
}
Also used : SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Example 25 with SUser

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

the class UserFinderTest method testLogicOps.

@Test
public void testLogicOps() throws Throwable {
    SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser("user2");
    final SUser user3 = createUser("user3");
    final SUser user4 = createUser("user4");
    group1.addUser(user1);
    group1.addUser(user2);
    SUserGroup group2 = myFixture.createUserGroup("key2", "name2", "description");
    group2.addUser(user3);
    group2.addUser(user2);
    check(null, user1, user2, user3, user4);
    check("group:(key:" + group1.getKey() + ")", user1, user2);
    // todo: should actually return sorted
    check("group:(key:" + group2.getKey() + ")", user3, user2);
    check("group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")", user2);
    check("group:(key:" + group1.getKey() + "),and:(group:(key:" + group2.getKey() + "))", user2);
    check("and:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + "))", user2);
    check("or:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + "))", user1, user2, user3);
    check("not:(group:(key:" + group1.getKey() + "))", user3, user4);
    check("not:(or:(group:(key:" + group1.getKey() + "),group:(key:" + group2.getKey() + ")))", user4);
    // Only single 'and' dimension is supported in locator
    checkExceptionOnItemsSearch(LocatorProcessException.class, "and:(group:(key:" + group1.getKey() + ")),and:group:(key:" + group2.getKey() + "))");
}
Also used : SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) Test(org.testng.annotations.Test)

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