Search in sources :

Example 21 with GRN

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

the class EntityDependencyResolverTest method resolve.

@Test
@DisplayName("Try a regular depency resolve")
void resolve() {
    final String TEST_TITLE = "Test Stream Title";
    final EntityExcerpt streamExcerpt = EntityExcerpt.builder().type(ModelTypes.STREAM_V1).id(ModelId.of("54e3deadbeefdeadbeefaffe")).title(TEST_TITLE).build();
    when(contentPackService.listAllEntityExcerpts()).thenReturn(ImmutableSet.of(streamExcerpt));
    final EntityDescriptor streamDescriptor = EntityDescriptor.builder().type(ModelTypes.STREAM_V1).id(ModelId.of("54e3deadbeefdeadbeefaffe")).build();
    when(contentPackService.resolveEntities(any())).thenReturn(ImmutableSet.of(streamDescriptor));
    when(grnDescriptorService.getDescriptor(any(GRN.class))).thenAnswer(a -> {
        GRN grnArg = a.getArgument(0);
        return GRNDescriptor.builder().grn(grnArg).title("dummy").build();
    });
    final GRN dashboard = grnRegistry.newGRN("dashboard", "33e3deadbeefdeadbeefaffe");
    final ImmutableSet<org.graylog.security.entities.EntityDescriptor> missingDependencies = entityDependencyResolver.resolve(dashboard);
    assertThat(missingDependencies).hasSize(1);
    assertThat(missingDependencies.asList().get(0)).satisfies(descriptor -> {
        assertThat(descriptor.id().toString()).isEqualTo("grn::::stream:54e3deadbeefdeadbeefaffe");
        assertThat(descriptor.title()).isEqualTo(TEST_TITLE);
        assertThat(descriptor.owners()).hasSize(1);
        assertThat(descriptor.owners().asList().get(0).grn().toString()).isEqualTo("grn::::user:jane");
    });
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) GRN(org.graylog.grn.GRN) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with GRN

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

the class EntitySharesServiceTest method validateOwnerless.

@DisplayName("Validates we can modify ownerless entitites")
@Test
void validateOwnerless() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.DASHBOARD, "54e3deadbeefdeadbeefaffe");
    final GRN horst = grnRegistry.newGRN(GRNTypes.USER, "horst");
    final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(horst, Capability.MANAGE));
    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 23 with GRN

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

the class EntitySharesServiceTest method showShareForVisibleGrantee.

@DisplayName("Only show shares for visible grantees")
@Test
void showShareForVisibleGrantee() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
    final EntityShareRequest shareRequest = EntityShareRequest.create(null);
    final User user = createMockUser("hans");
    final GRN janeGRN = grnRegistry.newGRN(GRNTypes.USER, "jane");
    when(granteeService.getAvailableGrantees(user)).thenReturn(ImmutableSet.of(Grantee.createUser(janeGRN, "jane")));
    final Subject subject = mock(Subject.class);
    final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
    assertThat(entityShareResponse.activeShares()).satisfies(activeShares -> {
        assertThat(activeShares).hasSize(1);
        assertThat(activeShares.iterator().next().grantee()).isEqualTo(janeGRN);
    });
}
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 24 with GRN

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

the class EntitySharesServiceTest method validateLastOwnerCannotBeRemovedByChangingCapability.

@DisplayName("Validates we cannot remove the last owner by changing the own capability")
@Test
void validateLastOwnerCannotBeRemovedByChangingCapability() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.EVENT_DEFINITION, "54e3deadbeefdeadbeefaffe");
    final GRN bob = grnRegistry.newGRN(GRNTypes.USER, "bob");
    final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(bob, Capability.VIEW));
    final User user = createMockUser("requestingUser");
    when(granteeService.getAvailableGrantees(user)).thenReturn(ImmutableSet.of(Grantee.createUser(bob, "bob")));
    final Subject subject = mock(Subject.class);
    final EntityShareResponse entityShareResponse = entitySharesService.prepareShare(entity, shareRequest, user, subject);
    assertThat(entityShareResponse.validationResult()).satisfies(validationResult -> {
        assertThat(validationResult.failed()).isTrue();
        assertThat(validationResult.getErrors()).isNotEmpty();
        assertThat(validationResult.getErrors().get(EntityShareRequest.SELECTED_GRANTEE_CAPABILITIES)).contains("Removing the following owners <[grn::::user:bob]> will leave the entity ownerless.");
    });
}
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 25 with GRN

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

the class EntitySharesServiceTest method noSharesforInvisibleGrantees.

@DisplayName("Only show shares for visible grantees")
@Test
void noSharesforInvisibleGrantees() {
    final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "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.activeShares()).satisfies(activeShares -> {
        assertThat(activeShares).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)

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