Search in sources :

Example 36 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class PermissionIndexerTest method initializeOnStartup_grants_access_to_user_and_group.

@Test
public void initializeOnStartup_grants_access_to_user_and_group() {
    ComponentDto project = createAndIndexProject();
    UserDto user1 = userDbTester.insertUser();
    UserDto user2 = userDbTester.insertUser();
    GroupDto group = userDbTester.insertGroup();
    userDbTester.insertMember(group, user2);
    userDbTester.insertProjectPermissionOnUser(user1, USER, project);
    userDbTester.insertProjectPermissionOnGroup(group, USER, project);
    indexOnStartup();
    // anonymous
    verifyAnyoneNotAuthorized(project);
    // has direct access
    verifyAuthorized(project, user1);
    // has access through group
    verifyAuthorized(project, user1, group);
    // no access
    verifyNotAuthorized(project, user2);
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 37 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AuthorizationTypeSupportTest method createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups.

@Test
public void createQueryFilter_sets_filter_on_anyone_and_user_id_and_group_ids_if_user_is_logged_in_and_has_groups() {
    GroupDto group1 = GroupTesting.newGroupDto().setId(10);
    GroupDto group2 = GroupTesting.newGroupDto().setId(11);
    userSession.logIn().setUserId(1234).setGroups(group1, group2);
    HasParentQueryBuilder filter = (HasParentQueryBuilder) underTest.createQueryFilter();
    assertJson(filter.toString()).isSimilarTo("{" + "  \"has_parent\": {" + "    \"query\": {" + "      \"bool\": {" + "        \"filter\": {" + "          \"bool\": {" + "            \"should\": [" + "              {" + "                \"term\": {" + "                  \"allowAnyone\": true" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"userIds\": 1234" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"groupIds\": 10" + "                }" + "              }," + "              {" + "                \"term\": {" + "                  \"groupIds\": 11" + "                }" + "              }" + "            ]" + "          }" + "        }" + "      }" + "    }," + "    \"parent_type\": \"authorization\"" + "  }" + "}");
}
Also used : GroupDto(org.sonar.db.user.GroupDto) HasParentQueryBuilder(org.elasticsearch.index.query.HasParentQueryBuilder) Test(org.junit.Test)

Example 38 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method fail_if_administrator_of_other_organization_only.

@Test
public void fail_if_administrator_of_other_organization_only() throws Exception {
    OrganizationDto org1 = db.organizations().insert();
    OrganizationDto org2 = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org1, "the-group");
    loginAsAdmin(org2);
    expectedException.expect(ForbiddenException.class);
    newRequest().setParam(PARAM_GROUP_ID, group.getId().toString()).setParam(PARAM_PERMISSION, PROVISIONING).execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 39 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method fail_if_not_administrator_of_organization.

@Test
public void fail_if_not_administrator_of_organization() throws Exception {
    GroupDto group = db.users().insertGroup();
    loginAsAdmin(db.getDefaultOrganization());
    expectedException.expect(IllegalArgumentException.class);
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 40 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class AddGroupActionTest method adding_global_permission_fails_if_not_administrator_of_organization.

@Test
public void adding_global_permission_fails_if_not_administrator_of_organization() throws Exception {
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
    // user is administrator of another organization
    userSession.logIn().addPermission(ADMINISTER, "anotherOrg");
    expectedException.expect(ForbiddenException.class);
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_PERMISSION, PROVISIONING).execute();
}
Also used : GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)424 Test (org.junit.Test)387 UserDto (org.sonar.db.user.UserDto)148 ComponentDto (org.sonar.db.component.ComponentDto)127 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)70 OrganizationDto (org.sonar.db.organization.OrganizationDto)42 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)36 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)34 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)28 DbSession (org.sonar.db.DbSession)20 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)17 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)13 UserGroupDto (org.sonar.db.user.UserGroupDto)12 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)12 TestResponse (org.sonar.server.ws.TestResponse)11 Qualitygates (org.sonarqube.ws.Qualitygates)10 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)9 SearchGroupsResponse (org.sonarqube.ws.Qualityprofiles.SearchGroupsResponse)9