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