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