OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
dbClient.organizationDao().insert(dbSession, organizationDto);
// No snapshot attached on the project -> provisioned project
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
// No module properties
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, subModule);
// Sub module properties
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(module.getId()));
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, subModule);
// Sub module properties
// No module property
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, subModule);
// No sub module property
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()));
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, subModule);
// No sub module property
}
@Test
- public void fail_when_no_browse_permission_and_no_scan_permission() {
- userSessionRule.logIn("john").setGlobalPermissions();
+ public void fail_when_no_browse_permission_nor_scan_permission() {
+ userSessionRule.logIn();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
tester.get(FileSourceDao.class).insert(newFileSourceDto(projectFile).setSrcHash("123456").setRevision("987654321"));
ComponentDto module = ComponentTesting.newModuleDto(project);
- userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
dbClient.componentDao().insert(dbSession, module);
// File on module
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
-import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
ComponentFinder componentFinder = new ComponentFinder(dbClient);
underTest = new SearchAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
-
- userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
}
@Test
public void example() {
+ logInAsRoot();
ComponentDto project = insertProject();
insertHomepageLink(project.uuid());
insertCustomLink(project.uuid());
@Test
public void request_by_project_id() throws IOException {
+ logInAsRoot();
ComponentDto project = insertProject();
insertHomepageLink(project.uuid());
@Test
public void request_by_project_key() throws IOException {
+ logInAsRoot();
ComponentDto project = insertProject();
insertHomepageLink(project.uuid());
@Test
public void response_fields() throws IOException {
+ logInAsRoot();
ComponentDto project = insertProject();
ComponentLinkDto homepageLink = insertHomepageLink(project.uuid());
ComponentLinkDto customLink = insertCustomLink(project.uuid());
@Test
public void several_projects() throws IOException {
+ logInAsRoot();
ComponentDto project1 = insertProject();
ComponentDto project2 = insertProject("another", "abcd");
ComponentLinkDto customLink1 = insertCustomLink(project1.uuid());
@Test
public void request_does_not_fail_when_link_has_no_name() throws IOException {
+ logInAsRoot();
ComponentDto project = db.components().insertProject();
ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setType("type");
insertLink(foo);
@Test
public void request_does_not_fail_when_link_has_no_type() throws IOException {
+ logInAsRoot();
ComponentDto project = db.components().insertProject();
ComponentLinkDto foo = new ComponentLinkDto().setComponentUuid(project.uuid()).setHref("foo").setName("name");
insertLink(foo);
}
@Test
- public void global_admin() throws IOException {
- userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
- checkItWorks();
- }
-
- @Test
- public void project_admin() throws IOException {
- userSession.logIn("login");
+ public void project_administrator_can_search_for_links() throws IOException {
ComponentDto project = insertProject();
- userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+
checkItWorks(project);
}
@Test
- public void project_user() throws IOException {
- userSession.logIn("login");
+ public void project_user_can_search_for_links() throws IOException {
ComponentDto project = insertProject();
- userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
+
checkItWorks(project);
}
@Test
public void fail_when_both_id_and_key_are_provided() {
- insertProject();
+ ComponentDto project = insertProject();
+ logInAsRoot();
expectedException.expect(IllegalArgumentException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
- .setParam(PARAM_PROJECT_ID, PROJECT_UUID)
+ .setParam(PARAM_PROJECT_KEY, project.key())
+ .setParam(PARAM_PROJECT_ID, project.uuid())
.execute();
}
assertThat(response.getLinks(0).getName()).isEqualTo("Homepage");
}
- private void checkItWorks() throws IOException {
- checkItWorks(insertProject());
+ private UserSessionRule logInAsRoot() {
+ return userSession.logIn().setRoot();
}
}
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse.Status;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.core.permission.GlobalPermissions.PROVISIONING;
-import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newProjectDto;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- ComponentDbTester componentDb = new ComponentDbTester(db);
- WsActionTester ws;
- DbClient dbClient;
- DbSession dbSession;
+ private WsActionTester ws;
+ private DbClient dbClient;
+ private DbSession dbSession;
@Before
public void setUp() {
@Test
public void json_example() throws IOException {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode(1, "last_period")
.setPeriodDate(1, 956789123456L)
@Test
public void return_status_by_project_id() throws IOException {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode(1, "last_period")
.setPeriodDate(1, 956789123456L)
newMeasureDto(metric, project, snapshot)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
dbSession.commit();
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
String response = ws.newRequest()
- .setParam(PARAM_PROJECT_ID, "project-uuid")
+ .setParam(PARAM_PROJECT_ID, project.uuid())
.execute().getInput();
assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
@Test
public void return_status_by_project_key() throws IOException {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key"));
+ ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("project-key"));
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)
.setPeriodMode(1, "last_period")
.setPeriodDate(1, 956789123456L)
newMeasureDto(metric, project, snapshot)
.setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
dbSession.commit();
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
String response = ws.newRequest()
.setParam(PARAM_PROJECT_KEY, "project-key")
@Test
public void return_undefined_status_if_measure_is_not_found() {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
ProjectStatusWsResponse result = call(snapshot.getUuid());
@Test
public void return_undefined_status_if_snapshot_is_not_found() {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
- componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
- ProjectStatusWsResponse result = callByProjectUuid("project-uuid");
+ ProjectStatusWsResponse result = callByProjectUuid(project.uuid());
assertThat(result.getProjectStatus().getStatus()).isEqualTo(Status.NONE);
assertThat(result.getProjectStatus().getConditionsCount()).isEqualTo(0);
}
@Test
- public void not_fail_with_project_admin_permission() {
- userSession.addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ public void project_administrator_is_allowed_to_get_project_status() {
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
+ userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
call(snapshot.getUuid());
}
@Test
- public void not_fail_with_browse_permission() {
- userSession.addProjectUuidPermissions(UserRole.USER, "project-uuid");
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ public void project_user_is_allowed_to_get_project_status() {
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
+ userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
call(snapshot.getUuid());
}
@Test
public void fail_if_no_snapshot_id_found() {
- userSession.setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn().setRoot();
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Analysis with id 'task-uuid' is not found");
@Test
public void fail_if_insufficient_privileges() {
- userSession.setGlobalPermissions(PROVISIONING);
-
- ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
+ ComponentDto project = db.components().insertProject(db.organizations().insert());
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbSession.commit();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
+
call(snapshot.getUuid());
}
@Test
public void fail_if_project_id_and_ce_task_id_provided() {
+ userSession.logIn().setRoot();
+
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
@Test
public void fail_if_no_parameter_provided() {
+ userSession.logIn().setRoot();
+
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN;
-import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
import static org.sonar.server.qualitygate.QualityGates.SONAR_QUALITYGATE_PROPERTY;
public class SelectActionTest {
public void fail_when_not_quality_gates_admin() throws Exception {
String gateId = String.valueOf(gate.getId());
- userSession.logIn().setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
callByKey(gateId, project.getKey());
import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
import static org.sonar.api.web.page.Page.Scope.COMPONENT;
import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
-import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
}
@Test
- public void work_with_only_system_admin() throws Exception {
+ public void project_administrator_is_allowed_to_get_information() throws Exception {
init(createPages());
componentDbTester.insertProjectAndSnapshot(project);
- userSessionRule.setGlobalPermissions(SYSTEM_ADMIN);
+ userSessionRule.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
execute(project.key());
}
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.web.page.Page;
import org.sonar.api.web.page.PageDefinition;
-import org.sonar.core.permission.GlobalPermissions;
import org.sonar.core.platform.PluginRepository;
import org.sonar.db.Database;
import org.sonar.db.dialect.H2;
}
@Test
- public void return_global_pages_for_anonymous() throws Exception {
+ public void the_returned_global_pages_do_not_include_administration_pages() throws Exception {
init(createPages(), new ResourceTypeTree[] {});
- executeAndVerify("global_pages_for_anonymous.json");
- }
-
- @Test
- public void return_global_pages_for_user() throws Exception {
- init(createPages(), new ResourceTypeTree[] {});
- userSessionRule.logIn("obiwan");
-
- executeAndVerify("global_pages_for_user.json");
- }
-
- @Test
- public void return_global_pages_for_admin_user() throws Exception {
- init(createPages(), new ResourceTypeTree[] {});
- userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
-
- executeAndVerify("global_pages_for_admin.json");
+ executeAndVerify("global_pages.json");
}
@Test
--- /dev/null
+{
+ "globalPages": [
+ {
+ "key": "another_plugin/page",
+ "name": "My Another Page"
+ },
+ {
+ "key": "my_plugin/page",
+ "name": "My Plugin Page"
+ }
+ ]
+}
+++ /dev/null
-{
- "globalPages": [
- {
- "key": "another_plugin/page",
- "name": "My Another Page"
- },
- {
- "key": "my_plugin/page",
- "name": "My Plugin Page"
- }
- ]
-}
+++ /dev/null
-{
- "globalPages": [
- {
- "key": "another_plugin/page",
- "name": "My Another Page"
- },
- {
- "key": "my_plugin/page",
- "name": "My Plugin Page"
- }
- ]
-}
+++ /dev/null
-{
- "globalPages": [
- {
- "key": "another_plugin/page",
- "name": "My Another Page"
- },
- {
- "key": "my_plugin/page",
- "name": "My Plugin Page"
- }
- ]
-}