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