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);
}
}
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);
}
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");
}
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");
}
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");
}
Aggregations