use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntityOwnershipService method registerNewSearch.
public void registerNewSearch(String id, User user) {
final GRN grn = grnRegistry.newGRN(GRNTypes.SEARCH, id);
registerNewEntity(grn, user);
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method ignoreInvisibleOwners.
@DisplayName("The validation should ignore invisble owners")
@Test
void ignoreInvisibleOwners() {
final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of());
final Set<GRN> allGrantees = dbGrantService.getAll().stream().map(GrantDTO::grantee).collect(Collectors.toSet());
lenient().when(granteeService.getAvailableGrantees(any())).thenReturn(allGrantees.stream().filter(g -> g.toString().equals("grn::::user:invisible")).map(g -> Grantee.createUser(g, g.entity())).collect(Collectors.toSet()));
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();
});
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method validateLastOwnerCannotBeRemoved.
// TODO Test more EntitySharesService functionality
@DisplayName("Validates we cannot remove the last owner")
@Test
void validateLastOwnerCannotBeRemoved() {
final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of());
// This test can also see the "invisible user"
final Set<GRN> allGrantees = dbGrantService.getAll().stream().map(GrantDTO::grantee).collect(Collectors.toSet());
lenient().when(granteeService.getAvailableGrantees(any())).thenReturn(allGrantees.stream().map(g -> Grantee.createUser(g, g.entity())).collect(Collectors.toSet()));
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()).isTrue();
assertThat(validationResult.getErrors()).isNotEmpty();
assertThat(validationResult.getErrors().get(EntityShareRequest.SELECTED_GRANTEE_CAPABILITIES).toString()).contains("Removing the following owners").contains("grn::::user:jane").contains("grn::::user:invisible");
});
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method validateOwnerSwitch.
@DisplayName("Validates we can switch owners")
@Test
void validateOwnerSwitch() {
final GRN entity = grnRegistry.newGRN(GRNTypes.STREAM, "54e3deadbeefdeadbeefaffe");
final GRN horst = grnRegistry.newGRN(GRNTypes.USER, "horst");
final EntityShareRequest shareRequest = EntityShareRequest.create(ImmutableMap.of(horst, Capability.OWN));
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 DBGrantServiceTest method createWithGranteeCapabilityAndTarget.
@Test
public void createWithGranteeCapabilityAndTarget() {
final GRN grantee = GRNTypes.USER.toGRN("jane");
final GRN target = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0000");
final GrantDTO grant = dbService.create(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));
}
Aggregations