Search in sources :

Example 26 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class EntitySharesServiceTest method noValidationOnEmptyRequest.

@DisplayName("Don't run validation on initial empty request")
@Test
void noValidationOnEmptyRequest() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.DASHBOARD, "54e3deadbeefdeadbeefaffe");
    final EntityShareRequest shareRequest = EntityShareRequest.create(null);
    final User user = createMockUser("hans");
    final Subject subject = mock(Subject.class);
    final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
    assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
        assertThat(validationResult.failed()).isFalse();
        assertThat(validationResult.getErrors()).isEmpty();
    });
}
Also used : GRN(org.graylog.grn.GRN) User(org.graylog2.plugin.database.users.User) Subject(org.apache.shiro.subject.Subject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 27 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class EntityDependencyPermissionCheckerTest method runCheck.

private ImmutableMultimap<GRN, EntityDescriptor> runCheck(boolean isSharingUserAuthorized, boolean isGranteeUserAuthorized) {
    final GRN granteeUser = grnRegistry.newGRN("user", "john");
    final GRN sharingUser = grnRegistry.newGRN("user", "jane");
    final GRN stream = grnRegistry.newGRN("stream", "54e3deadbeefdeadbeef0001");
    final GranteeAuthorizer sharingUserAuthorizer = mock(GranteeAuthorizer.class);
    final GranteeAuthorizer granteeUserAuthorizer = mock(GranteeAuthorizer.class);
    final ImmutableSet<GRN> selectedGrantees = ImmutableSet.of(granteeUser);
    final EntityDescriptor dependency = EntityDescriptor.create(stream, "Title", ImmutableSet.of());
    final ImmutableSet<EntityDescriptor> dependencies = ImmutableSet.of(dependency);
    when(userAuthorizerFactory.create(sharingUser)).thenReturn(sharingUserAuthorizer);
    when(userAuthorizerFactory.create(granteeUser)).thenReturn(granteeUserAuthorizer);
    when(sharingUserAuthorizer.isPermitted(anyString(), any(GRN.class))).thenReturn(isSharingUserAuthorized);
    when(granteeUserAuthorizer.isPermitted("streams:read", stream)).thenReturn(isGranteeUserAuthorized);
    final ImmutableMultimap<GRN, EntityDescriptor> checkResult = resolver.check(sharingUser, dependencies, selectedGrantees);
    verify(sharingUserAuthorizer, times(1)).isPermitted("streams:read", stream);
    verifyNoMoreInteractions(sharingUserAuthorizer);
    return checkResult;
}
Also used : GRN(org.graylog.grn.GRN) GranteeAuthorizer(org.graylog.security.GranteeAuthorizer)

Example 28 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method createWithGrantDTOAndUsernameString.

@Test
public void createWithGrantDTOAndUsernameString() {
    final GRN grantee = GRNTypes.USER.toGRN("jane");
    final GRN target = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0000");
    final GrantDTO grant = dbService.create(GrantDTO.of(grantee, Capability.MANAGE, target), "admin");
    assertThat(grant.id()).isNotBlank();
    assertThat(grant.grantee()).isEqualTo(grantee);
    assertThat(grant.capability()).isEqualTo(Capability.MANAGE);
    assertThat(grant.target()).isEqualTo(target);
    assertThat(grant.createdBy()).isEqualTo("admin");
    assertThat(grant.createdAt()).isBefore(ZonedDateTime.now(ZoneOffset.UTC));
    assertThat(grant.updatedBy()).isEqualTo("admin");
    assertThat(grant.updatedAt()).isBefore(ZonedDateTime.now(ZoneOffset.UTC));
}
Also used : GRN(org.graylog.grn.GRN) Test(org.junit.Test)

Example 29 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getOwnersForTargets.

@Test
@MongoDBFixtures("grants.json")
public void getOwnersForTargets() {
    final GRN jane = grnRegistry.parse("grn::::user:jane");
    final GRN john = grnRegistry.parse("grn::::user:john");
    final GRN dashboard1 = grnRegistry.parse("grn::::dashboard:54e3deadbeefdeadbeef0000");
    final GRN dashboard2 = grnRegistry.parse("grn::::dashboard:54e3deadbeefdeadbeef0001");
    final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
    assertThat(dbService.getOwnersForTargets(ImmutableSet.of(dashboard1, dashboard2, stream1))).satisfies(result -> {
        assertThat(result.get(dashboard1)).containsExactlyInAnyOrder(jane);
        assertThat(result.get(dashboard2)).containsExactlyInAnyOrder(john);
        assertThat(result).doesNotContainKey(stream1);
    });
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 30 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForTarget.

@Test
@MongoDBFixtures("grants.json")
public void getForTarget() {
    final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0000");
    final GRN stream2 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
    assertThat(dbService.getForTarget(stream1)).hasSize(1);
    assertThat(dbService.getForTarget(stream2)).hasSize(3);
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

GRN (org.graylog.grn.GRN)51 User (org.graylog2.plugin.database.users.User)19 DisplayName (org.junit.jupiter.api.DisplayName)16 Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)13 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)11 Subject (org.apache.shiro.subject.Subject)10 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)5 GRNRegistry (org.graylog.grn.GRNRegistry)5 Capability (org.graylog.security.Capability)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 EventBus (com.google.common.eventbus.EventBus)4 Set (java.util.Set)4 DBGrantService (org.graylog.security.DBGrantService)4 ZonedDateTime (java.time.ZonedDateTime)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3