Search in sources :

Example 6 with FakeHttpServletRequest

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());
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) Test(org.testng.annotations.Test)

Example 7 with FakeHttpServletRequest

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());
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) TestOccurrence(jetbrains.buildServer.server.rest.model.problem.TestOccurrence) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 8 with FakeHttpServletRequest

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());
}
Also used : BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) TestOccurrences(jetbrains.buildServer.server.rest.model.problem.TestOccurrences) Test(org.testng.annotations.Test)

Example 9 with FakeHttpServletRequest

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());
    });
}
Also used : SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) SecurityContextImpl(jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl) FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) User(jetbrains.buildServer.server.rest.model.user.User) SUser(jetbrains.buildServer.users.SUser) Build(jetbrains.buildServer.server.rest.model.build.Build) SFinishedBuild(jetbrains.buildServer.serverSide.SFinishedBuild) SUser(jetbrains.buildServer.users.SUser) SUserGroup(jetbrains.buildServer.groups.SUserGroup) BufferedImage(java.awt.image.BufferedImage) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Example 10 with FakeHttpServletRequest

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);
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Aggregations

FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)10 Test (org.testng.annotations.Test)10 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)7 TestOccurrences (jetbrains.buildServer.server.rest.model.problem.TestOccurrences)6 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)4 SUser (jetbrains.buildServer.users.SUser)4 TwoFactorCredentials (jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials)3 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)3 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)3 TestFor (jetbrains.buildServer.util.TestFor)3 TestOccurrence (jetbrains.buildServer.server.rest.model.problem.TestOccurrence)2 BeanContext (jetbrains.buildServer.server.rest.util.BeanContext)2 SkipException (org.testng.SkipException)2 BufferedImage (java.awt.image.BufferedImage)1 SUserGroup (jetbrains.buildServer.groups.SUserGroup)1 Build (jetbrains.buildServer.server.rest.model.build.Build)1 User (jetbrains.buildServer.server.rest.model.user.User)1 SecurityContextImpl (jetbrains.buildServer.serverSide.impl.auth.SecurityContextImpl)1