use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.
the class TestOccurrenceRequestTest method testWithoutSessionUser.
@Test
public void testWithoutSessionUser() {
final SFinishedBuild build = build().in(myBuildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).finish();
FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
mockRequest.setRequestURL("http://test/httpAuth/app/rest/testOccurrences?locator=build:" + build.getBuildId());
TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:" + build.getBuildId(), "", null, mockRequest);
assertEquals(new Integer(1), testOccurrences.getCount());
}
use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.
the class TestOccurrenceRequestTest method testInvocationsAreFoundCorrectly2.
@Test
@TestFor(issues = { "TW-70206" })
public void testInvocationsAreFoundCorrectly2() {
if (true)
throw new SkipException("Reverted correct behaviour due to TW-70587");
final BuildTypeImpl buildType = registerBuildType("buildConf1", "project");
final SFinishedBuild build = build().in(buildType).withTest("aaa", false).withTest("aaa", false).withTest("aaa", true).finish();
String fields = "testCounters(failed,success,all,duration),testOccurrence(id,name,muted,status,invocations($locator(count:90000),testCounters(all,success,failed),testOccurrence(id,name,status,muted)))";
String locator = "currentlyFailing:true,affectedProject:" + buildType.getProject().getExternalId();
FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
mockRequest.setRequestURL(String.format("http://test/httpAuth/app/rest/testOccurrences?locator=%s&fields=%s", locator, fields));
TestOccurrences testOccurrences = myRequest.getTestOccurrences(locator, fields, null, mockRequest);
assertEquals("Should return exactly one 'grouping' test run.", 1, testOccurrences.items.size());
TestOccurrence grouping = testOccurrences.items.get(0);
assertNotNull("Should contain invocations node.", grouping.getInvocations());
assertEquals("Should contain exactly 3 occurrences.", 3, grouping.getInvocations().items.size());
}
use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.
the class TestOccurrenceRequestTest method testWontFetchItemsWhenNotNeededWithDefaultFieldsValue.
@Test
public void testWontFetchItemsWhenNotNeededWithDefaultFieldsValue() {
BeanContext ctx = BaseFinderTest.getBeanContext(myFixture);
myRequest.initForTests(ctx.getServiceLocator(), new TestOccurrenceFinderDenyingItemsFetch(), ctx.getApiUrlBuilder(), ctx);
final SFinishedBuild build = build().in(myBuildType).withTest(BuildBuilder.TestData.test("aaa").duration(76)).finish();
FakeHttpServletRequest mockRequest = new FakeHttpServletRequest();
mockRequest.setRequestURL("http://test/httpAuth/app/rest/testOccurrences?locator=build:" + build.getBuildId());
TestOccurrences testOccurrences = myRequest.getTestOccurrences("build:" + build.getBuildId(), "", null, mockRequest);
assertEquals(new Integer(1), testOccurrences.getCount());
}
use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.
the class UserRequestTest method testUserEnityExposure.
@Test
void testUserEnityExposure() throws Throwable {
myFixture.getServerSettings().setPerProjectPermissionsEnabled(true);
final SUser user1 = createUser("user1");
final SUser user2 = createUser("user2");
// filling all user fields
user1.updateUserAccount("user1", "Display Name1", "email1@domain.com");
user2.updateUserAccount("user2", "Display Name2", "email2@domain.com");
SUserGroup group1 = myFixture.createUserGroup("key1", "name1", "description");
group1.addUser(user1);
group1.addUser(user2);
user1.addRole(RoleScope.globalScope(), getProjectViewerRole());
user2.addRole(RoleScope.globalScope(), getProjectViewerRole());
user1.setLastLoginTimestamp(new Date());
user2.setLastLoginTimestamp(new Date());
user1.setPassword("secret");
user2.setPassword("secret");
myFixture.getUserAvatarsManager().saveAvatar(user1, new BufferedImage(1, 1, 1));
myFixture.getUserAvatarsManager().saveAvatar(user2, new BufferedImage(1, 1, 1));
enable2FA(user1);
enable2FA(user2);
SecurityContextImpl securityContext = myFixture.getSecurityContext();
user2.addRole(RoleScope.globalScope(), getProjectAdminRole());
SFinishedBuild build10 = build().in(myBuildType).by(user1).finish();
SFinishedBuild build20 = build().in(myBuildType).by(user2).finish();
BuildRequest buildRequest = new BuildRequest();
buildRequest.initForTests(BaseFinderTest.getBeanContext(myFixture));
// if changed, the checks below should be changed
assertEquals(15, getSubEntitiesNames(User.class).size());
final String fields = "triggered(user($long,hasPassword))";
{
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
// not included in response
assertNull(user.getPassword());
// submit-only
assertNull(user.getLocator());
// obsolete
assertNull(user.getRealm());
}
{
Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
// not included in response
assertNull(user.getPassword());
// submit-only
assertNull(user.getLocator());
// obsolete
assertNull(user.getRealm());
}
securityContext.runAs(user1, () -> {
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
assertNull(user.getPassword());
});
securityContext.runAs(user2, () -> {
Build build = buildRequest.serveBuild("id:" + build10.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNotNull(user.getEmail());
assertNotNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNotNull(user.getProperties());
assertNotNull(user.getRoles());
assertNotNull(user.getGroups());
assertNotNull(user.getHasPassword());
assertNotNull(user.getAvatars());
assertNotNull(user.getEnabled2FA());
assertNull(user.getPassword());
});
securityContext.runAs(user1, () -> {
Build build = buildRequest.serveBuild("id:" + build20.getBuildId(), fields, new FakeHttpServletRequest());
// check that all is present
User user = build.getTriggered().user;
assertNotNull(user.getUsername());
assertNotNull(user.getName());
assertNotNull(user.getId());
assertNull(user.getEmail());
assertNull(user.getLastLogin());
assertNotNull(user.getHref());
assertNull(user.getProperties());
assertNull(user.getRoles());
assertNull(user.getGroups());
assertNull(user.getHasPassword());
assertNull(user.getPassword());
assertNotNull(user.getAvatars());
assertNull(user.getEnabled2FA());
});
}
use of jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest in project teamcity-rest by JetBrains.
the class TwoFactorRequestTest method testKeyRegeneration.
@Test
public void testKeyRegeneration() throws Throwable {
final SUser user = createUser("user");
myFixture.getSecurityContext().runAs(user, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
TwoFactorCredentials credentials = myRequest.setupTwoFactor();
myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
final String hashedRecovery = myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY));
myRequest.serveRecoveryKeys();
final String newHashedRecovery = myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY));
Assert.assertNotEquals(hashedRecovery, newHashedRecovery);
}
});
}
Aggregations