Search in sources :

Example 66 with SUser

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

the class UserFinderTest method testInvalidLocators.

@Test
public void testInvalidLocators() throws Throwable {
    final SUser user10 = createUser("user1");
    check(null, user10);
    check("id:" + user10.getId(), user10);
    checkExceptionOnItemsSearch(LocatorProcessException.class, "aaa:bbb");
    checkExceptionOnItemsSearch(NotFoundException.class, "xxx");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "id:" + user10.getId() + ",aaa:bbb");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "id:" + user10.getId() + ",aaa:bbb");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "id:" + user10.getId() + ",xxx");
    checkExceptionOnItemSearch(LocatorProcessException.class, "aaa:bbb");
    checkExceptionOnItemSearch(NotFoundException.class, "xxx");
    checkExceptionOnItemSearch(LocatorProcessException.class, "id:" + user10.getId() + ",aaa:bbb");
    checkExceptionOnItemSearch(LocatorProcessException.class, "id:" + user10.getId() + ",xxx");
    try {
        getFinder().getItems("aaa:bbb");
        fail("No exception is thrown");
    } catch (Exception e) {
        String message = e.getMessage();
        assertContains(message, "username");
        assertContains(message, "id");
        assertContains(message, "group");
        assertContains(message, "role");
        assertNotContains(message, "hasPassword", false);
    }
}
Also used : SUser(jetbrains.buildServer.users.SUser) LocatorProcessException(jetbrains.buildServer.server.rest.errors.LocatorProcessException) AuthorizationFailedException(jetbrains.buildServer.server.rest.errors.AuthorizationFailedException) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Test(org.testng.annotations.Test)

Example 67 with SUser

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

the class UserFinderTest method testNameEmail.

@Test
public void testNameEmail() throws Throwable {
    final SUser user05 = createUser("user05");
    final SUser user06 = createUser("user06");
    user06.updateUserAccount(user06.getUsername(), "User 06", "user06@anotherAcme.com");
    final SUser user10 = createUser("user10");
    user10.updateUserAccount(user10.getUsername(), "User 10", "user10@acme.com");
    final SUser user20 = createUser("user20");
    user20.updateUserAccount(user20.getUsername(), "User 20", "user20@acme.com");
    final SUser user30 = createUser("user30");
    user30.updateUserAccount(user30.getUsername(), "", "");
    final SUser user40 = createUser("user40");
    user40.updateUserAccount(user40.getUsername(), null, null);
    check(null, user05, user06, user10, user20, user30, user40);
    check("name:User 20", user20);
    check("name:(value:User .0,matchType:matches)", user10, user20);
    check("email:(value:@acme.com,matchType:ends-with)", user10, user20);
// check("name:(matchType:exists)", user06, user10, user20, user30);
}
Also used : SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Example 68 with SUser

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

the class UserFinderTest method testEmptyLocator.

@Test
public void testEmptyLocator() throws Throwable {
    final SUser user1 = createUser("user1");
    BaseFinderTest.checkException(BadRequestException.class, new Runnable() {

        public void run() {
            myUserFinder.getItem(null);
        }
    }, "searching for users with null locator");
    BaseFinderTest.checkException(BadRequestException.class, new Runnable() {

        public void run() {
            myUserFinder.getItem("");
        }
    }, "searching for users with empty locator");
}
Also used : SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Example 69 with SUser

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

the class UserFinderTest method testBasic1.

@Test
public void testBasic1() throws Throwable {
    final SUser user1 = createUser("user1");
    final SUser user2 = createUser(String.valueOf(user1.getId()));
    check("id:" + user1.getId(), user1);
    assertEquals(Long.valueOf(1), getFinder().getItems("id:" + user1.getId()).myActuallyProcessedCount);
    checkExceptionOnItemSearch(NotFoundException.class, "id:" + user1.getId() + "1");
    checkExceptionOnItemsSearch(NotFoundException.class, "id:" + user1.getId() + "1");
    check("username:" + user2.getUsername(), user2);
    assertEquals(Long.valueOf(1), getFinder().getItems("username:" + user2.getUsername()).myActuallyProcessedCount);
    check("username:" + "user1", user1);
    check("id:" + user1.getId() + ",username:" + "USER1", user1);
    check("username:" + "USER1", user1);
    checkExceptionOnItemSearch(NotFoundException.class, "username:" + user2.getUsername() + "1");
    checkExceptionOnItemsSearch(NotFoundException.class, "username:" + user2.getUsername() + "1");
    check("id:" + user1.getId() + ",username:" + "user1", user1);
    checkExceptionOnItemSearch(NotFoundException.class, "id:" + user1.getId() + ",username:" + "user1" + "x");
    check("id:" + user1.getId() + ",username:" + "user1" + "x");
    checkExceptionOnItemSearch(LocatorProcessException.class, "xxx:yyy");
    checkExceptionOnItemsSearch(LocatorProcessException.class, "xxx:yyy");
}
Also used : SUser(jetbrains.buildServer.users.SUser) Test(org.testng.annotations.Test)

Example 70 with SUser

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

the class UserFinderTest method testCurrentUser.

@Test
public void testCurrentUser() throws Throwable {
    final SUser user1 = createUser("user1");
    BaseFinderTest.checkException(NotFoundException.class, new Runnable() {

        public void run() {
            myUserFinder.getItem("current");
        }
    }, "getting current user");
    SecurityContextImpl securityContext = myFixture.getSecurityContext();
    securityContext.runAs(user1, new SecurityContextEx.RunAsAction() {

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

        public void run() {
            try {
                securityContext.runAsSystem(new SecurityContextEx.RunAsAction() {

                    @Override
                    public void run() throws Throwable {
                        myUserFinder.getItem("current");
                    }
                });
            } catch (Throwable throwable) {
                ExceptionUtil.rethrowAsRuntimeException(throwable);
            }
        }
    }, "getting current user under system");
}
Also used : SecurityContextImpl(jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) 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