Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Stream reference dependencies for entity sharing #17891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-17882.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Fixed error when attempting to share entities with stream dependencies."

issues = ["17882"]
pulls = ["17891"]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.graylog2.contentpacks.model.ModelId;
import org.graylog2.contentpacks.model.ModelType;
import org.graylog2.contentpacks.model.ModelTypes;
import org.graylog2.contentpacks.model.entities.EntityExcerpt;

import javax.annotation.Nullable;
import javax.inject.Inject;
Expand Down Expand Up @@ -85,6 +84,12 @@ public ImmutableSet<EntityDescriptor> resolve(GRN entity) {
final Set<ModelType> ignoredDeps = IGNORED_DEPENDENCIES.getOrDefault(entity.grnType(), ImmutableSet.of());
return !ignoredDeps.contains(dep.type());
})
// TODO: Work around from using the content pack dependency resolver:
// We've added stream_title content pack entities in https://github.com/Graylog2/graylog2-server/pull/17089,
// but in this context we want to return the actual dependent Stream to add additional permissions to.
.map(descriptor -> ModelTypes.STREAM_REF_V1.equals(descriptor.type())
? org.graylog2.contentpacks.model.entities.EntityDescriptor.create(descriptor.id(), ModelTypes.STREAM_V1)
: descriptor)
.map(descriptor -> grnRegistry.newGRN(descriptor.type().name(), descriptor.id().id()))
.filter(dependency -> !entity.equals(dependency)) // Don't include the given entity in dependencies
.collect(ImmutableSet.toImmutableSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,38 @@ void resolveWithInclompleteDependency() {
assertThat(descriptor.title()).isEqualTo("unknown dependency: <grn::::stream:54e3deadbeefdeadbeefaffe>");
});
}

@Test
@DisplayName("Try a stream reference dependency resolve")
void resolveStreamReference() {
final String TEST_TITLE = "Test Stream Title";
final EntityExcerpt streamExcerpt = EntityExcerpt.builder()
.type(ModelTypes.STREAM_V1)
.id(ModelId.of("54e3deadbeefdeadbeefaffe"))
.title(TEST_TITLE).build();
final EntityExcerpt streamRefExcerpt = EntityExcerpt.builder()
.type(ModelTypes.STREAM_REF_V1)
.id(ModelId.of("54e3deadbeefdeadbeefaffe"))
.title(TEST_TITLE).build();
when(contentPackService.listAllEntityExcerpts()).thenReturn(ImmutableSet.of(streamExcerpt, streamRefExcerpt));

final EntityDescriptor streamDescriptor = EntityDescriptor.builder().type(ModelTypes.STREAM_REF_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");
});
}
}
Loading