Search in sources :

Example 1 with ADMINISTER

use of org.sonar.db.permission.GlobalPermission.ADMINISTER in project sonarqube by SonarSource.

the class UserPermissionDaoTest method deleteByUserId.

@Test
public void deleteByUserId() {
    UserDto user1 = insertUser();
    UserDto user2 = insertUser();
    ComponentDto project = db.components().insertPrivateProject();
    db.users().insertPermissionOnUser(user1, SCAN);
    db.users().insertPermissionOnUser(user1, ADMINISTER);
    db.users().insertProjectPermissionOnUser(user1, ADMINISTER_QUALITY_GATES.getKey(), project);
    db.users().insertPermissionOnUser(user2, SCAN);
    db.users().insertProjectPermissionOnUser(user2, ADMINISTER_QUALITY_GATES.getKey(), project);
    underTest.deleteByUserUuid(dbSession, user1);
    dbSession.commit();
    assertThat(db.select("select user_uuid as \"userUuid\", component_uuid as \"projectUuid\", role as \"permission\" from user_roles")).extracting((row) -> row.get("userUuid"), (row) -> row.get("projectUuid"), (row) -> row.get("permission")).containsOnly(tuple(user2.getUuid(), null, SCAN.getKey()), tuple(user2.getUuid(), project.uuid(), ADMINISTER_QUALITY_GATES.getKey()));
}
Also used : IntStream(java.util.stream.IntStream) ISSUE_ADMIN(org.sonar.api.web.UserRole.ISSUE_ADMIN) QUALITY_PROFILE_ADMIN(org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN) Arrays(java.util.Arrays) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PROVISION_PROJECTS(org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS) Random(java.util.Random) ADMINISTER(org.sonar.db.permission.GlobalPermission.ADMINISTER) DbSession(org.sonar.db.DbSession) DEFAULT_PAGE_SIZE(org.sonar.db.permission.PermissionQuery.DEFAULT_PAGE_SIZE) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) ADMIN(org.sonar.api.web.UserRole.ADMIN) Uuids(org.sonar.core.util.Uuids) SCAN(org.sonar.db.permission.GlobalPermission.SCAN) Arrays.asList(java.util.Arrays.asList) SYSTEM_ADMIN(org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN) PROVISIONING(org.sonar.core.permission.GlobalPermissions.PROVISIONING) ADMINISTER_QUALITY_GATES(org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES) DbTester(org.sonar.db.DbTester) Tuple(org.assertj.core.groups.Tuple) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Test(org.junit.Test) NoOpAuditPersister(org.sonar.db.audit.NoOpAuditPersister) Consumer(java.util.function.Consumer) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) Arrays.stream(java.util.Arrays.stream) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ADMINISTER

use of org.sonar.db.permission.GlobalPermission.ADMINISTER in project sonarqube by SonarSource.

the class ListActionTest method obfuscate_credentials_in_webhook_URLs.

@Test
public void obfuscate_credentials_in_webhook_URLs() {
    String url = "http://foo:barouf@toto/bop";
    String expectedUrl = "http://***:******@toto/bop";
    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null, null);
    webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
    webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
    webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null, null);
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    List<Webhooks.ListResponseElement> elements = response.getWebhooksList();
    assertThat(elements).hasSize(2).extracting(Webhooks.ListResponseElement::getUrl).containsOnly(expectedUrl);
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ComponentFinder(org.sonar.server.component.ComponentFinder) DbTester.create(org.sonar.db.DbTester.create) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PROJECT_KEY_PARAM(org.sonar.server.webhook.ws.WebhooksWsParameters.PROJECT_KEY_PARAM) ADMINISTER(org.sonar.db.permission.GlobalPermission.ADMINISTER) AssertionsForClassTypes.tuple(org.assertj.core.api.AssertionsForClassTypes.tuple) ADMIN(org.sonar.api.web.UserRole.ADMIN) WebhookTesting.newGlobalWebhook(org.sonar.db.webhook.WebhookTesting.newGlobalWebhook) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) UserSessionRule.standalone(org.sonar.server.tester.UserSessionRule.standalone) Configuration(org.sonar.api.config.Configuration) ResourceTypes(org.sonar.api.resources.ResourceTypes) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) WebhookDbTester(org.sonar.db.webhook.WebhookDbTester) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) WebhookDeliveryTesting.newDto(org.sonar.db.webhook.WebhookDeliveryTesting.newDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Webhooks(org.sonarqube.ws.Webhooks) ComponentDbTester(org.sonar.db.component.ComponentDbTester) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UnauthorizedException(org.sonar.server.exceptions.UnauthorizedException) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ProjectDto(org.sonar.db.project.ProjectDto) WebhookDeliveryDbTester(org.sonar.db.webhook.WebhookDeliveryDbTester) Mockito.mock(org.mockito.Mockito.mock) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Aggregations

List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 ADMIN (org.sonar.api.web.UserRole.ADMIN)2 DbTester (org.sonar.db.DbTester)2 ComponentDto (org.sonar.db.component.ComponentDto)2 ADMINISTER (org.sonar.db.permission.GlobalPermission.ADMINISTER)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Arrays.stream (java.util.Arrays.stream)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Random (java.util.Random)1 Consumer (java.util.function.Consumer)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1