Search in sources :

Example 1 with MockAuthorityHolder

use of jetbrains.buildServer.serverSide.impl.MockAuthorityHolder in project teamcity-rest by JetBrains.

the class ServerRequestTest method test_user_needs_view_agent_details_permission_to_access_avaliable_agents.

@Test(description = "TW-68673")
public void test_user_needs_view_agent_details_permission_to_access_avaliable_agents() throws Throwable {
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    mockUser.globalPerms = new Permissions(Permission.VIEW_AGENT_DETAILS);
    myFixture.getSecurityContext().runAs(mockUser, () -> {
        LicensingData data = myRequest.getLicensingData("maxAgents,serverLicenseType,agentsLeft");
        assertNull(data.maxAgents);
        assertNull(data.serverLicenseType);
        assertNotNull(data.getAgentsLeft());
    });
}
Also used : LicensingData(jetbrains.buildServer.server.rest.model.server.LicensingData) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 2 with MockAuthorityHolder

use of jetbrains.buildServer.serverSide.impl.MockAuthorityHolder in project teamcity-rest by JetBrains.

the class ServerRequestTest method test_user_needs_manage_server_licenses_permission_to_access_licensing_data.

@Test
public void test_user_needs_manage_server_licenses_permission_to_access_licensing_data() throws Throwable {
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    myFixture.getSecurityContext().runAs(mockUser, () -> {
        LicensingData data = myRequest.getLicensingData("maxAgents,serverLicenseType,agentsLeft");
        assertNull(data.maxAgents);
        assertNull(data.serverLicenseType);
        assertNull(data.getAgentsLeft());
    });
    mockUser.globalPerms = new Permissions(Permission.MANAGE_SERVER_LICENSES);
    myFixture.getSecurityContext().runAs(mockUser, () -> {
        LicensingData data = myRequest.getLicensingData("maxAgents,serverLicenseType,agentsLeft");
        assertNotNull(data.maxAgents);
        assertNotNull(data.serverLicenseType);
        assertNotNull(data.getAgentsLeft());
    });
}
Also used : LicensingData(jetbrains.buildServer.server.rest.model.server.LicensingData) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 3 with MockAuthorityHolder

use of jetbrains.buildServer.serverSide.impl.MockAuthorityHolder in project teamcity-rest by JetBrains.

the class AbstractAgentPoolResolverTest method basicProjectsConnection.

public void basicProjectsConnection() throws Throwable {
    jetbrains.buildServer.serverSide.agentPools.AgentPool realPool = myFixture.getAgentPoolManager().createNewAgentPool("testAgentPool");
    Set<String> allProjectIds = new HashSet<>();
    Set<String> visibleProjectNames = new HashSet<>();
    MockAuthorityHolder mockUser = new MockAuthorityHolder();
    Permissions viewProjectPermissions = new Permissions(Permission.VIEW_PROJECT);
    for (int i = 0; i < 5; i++) {
        ProjectEx project = createProject("visibleProject" + i);
        mockUser.projectPerms.put(project.getProjectId(), viewProjectPermissions);
        allProjectIds.add(project.getProjectId());
        visibleProjectNames.add(project.getName());
    }
    List<ProjectEx> invisibleProjects = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ProjectEx project = createProject("invisibleProject" + i);
        allProjectIds.add(project.getProjectId());
        invisibleProjects.add(project);
    }
    myFixture.getAgentPoolManager().associateProjectsWithPool(realPool.getAgentPoolId(), allProjectIds);
    Mock fieldSelectionSetMock = mock(DataFetchingFieldSelectionSet.class);
    fieldSelectionSetMock.stubs().method("contains").with(eq("excludedCount")).will(returnValue(true));
    myDataFetchingEnvironment.setSelectionSet((DataFetchingFieldSelectionSet) fieldSelectionSetMock.proxy());
    AgentPoolProjectsConnection connection = myFixture.getSecurityContext().runAs(mockUser, () -> myResolver.projects(new AgentPool(realPool), new ProjectsFilter(), myDataFetchingEnvironment));
    connection.getEdges().getData().forEach(edge -> {
        String name = edge.getNode().getData().getName();
        assertTrue("Project '" + name + "' is visible, but shouldn't be.", visibleProjectNames.contains(name));
    });
    assertEquals(visibleProjectNames.size(), connection.getCount());
    assertEquals(new Integer(invisibleProjects.size()), connection.getExcludedCount());
}
Also used : ProjectsFilter(jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter) AgentPoolProjectsConnection(jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection) AgentPool(jetbrains.buildServer.server.graphql.model.agentPool.AgentPool) Mock(org.jmock.Mock) ProjectEx(jetbrains.buildServer.serverSide.impl.ProjectEx) Permissions(jetbrains.buildServer.serverSide.auth.Permissions) jetbrains.buildServer.serverSide.agentPools(jetbrains.buildServer.serverSide.agentPools) MockAuthorityHolder(jetbrains.buildServer.serverSide.impl.MockAuthorityHolder)

Aggregations

Permissions (jetbrains.buildServer.serverSide.auth.Permissions)3 MockAuthorityHolder (jetbrains.buildServer.serverSide.impl.MockAuthorityHolder)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)2 LicensingData (jetbrains.buildServer.server.rest.model.server.LicensingData)2 Test (org.testng.annotations.Test)2 AgentPool (jetbrains.buildServer.server.graphql.model.agentPool.AgentPool)1 AgentPoolProjectsConnection (jetbrains.buildServer.server.graphql.model.connections.agentPool.AgentPoolProjectsConnection)1 ProjectsFilter (jetbrains.buildServer.server.graphql.model.filter.ProjectsFilter)1 jetbrains.buildServer.serverSide.agentPools (jetbrains.buildServer.serverSide.agentPools)1 ProjectEx (jetbrains.buildServer.serverSide.impl.ProjectEx)1 Mock (org.jmock.Mock)1