use of org.graylog2.plugin.rest.ValidationResult 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.graylog2.plugin.rest.ValidationResult 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.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class NotificationTestData method getDummyContext.
public static EventNotificationContext getDummyContext(NotificationDto notificationDto, String userName) {
final EventDto eventDto = EventDto.builder().alert(true).eventDefinitionId("EventDefinitionTestId").eventDefinitionType("notification-test-v1").eventTimestamp(Tools.nowUTC()).processingTimestamp(Tools.nowUTC()).id("TEST_NOTIFICATION_ID").streams(ImmutableSet.of(Stream.DEFAULT_EVENTS_STREAM_ID)).message("Notification test message triggered from user <" + userName + ">").source(Stream.DEFAULT_STREAM_ID).keyTuple(ImmutableList.of("testkey")).key("testkey").originContext(EventOriginContext.elasticsearchMessage("testIndex_42", "b5e53442-12bb-4374-90ed-0deadbeefbaz")).priority(2).fields(ImmutableMap.of("field1", "value1", "field2", "value2")).build();
final EventDefinitionDto eventDefinitionDto = EventDefinitionDto.builder().alert(true).id(TEST_NOTIFICATION_ID).title("Event Definition Test Title").description("Event Definition Test Description").config(new EventProcessorConfig() {
@Override
public String type() {
return "test-dummy-v1";
}
@Override
public ValidationResult validate() {
return null;
}
@Override
public EventProcessorConfigEntity toContentPackEntity(EntityDescriptorIds entityDescriptorIds) {
return null;
}
}).fieldSpec(ImmutableMap.of()).priority(2).keySpec(ImmutableList.of()).notificationSettings(new EventNotificationSettings() {
@Override
public long gracePeriodMs() {
return 0;
}
@Override
public // disable to avoid errors in getBacklogForEvent()
long backlogSize() {
return 0;
}
@Override
public Builder toBuilder() {
return null;
}
}).build();
return EventNotificationContext.builder().notificationId(TEST_NOTIFICATION_ID).notificationConfig(notificationDto.config()).event(eventDto).eventDefinition(eventDefinitionDto).build();
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class EventDefinitionDtoTest method testValidateWithEmptyTitle.
@Test
public void testValidateWithEmptyTitle() {
final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().title("").build();
final ValidationResult validationResult = invalidEventDefinition.validate();
assertThat(validationResult.failed()).isTrue();
assertThat(validationResult.getErrors()).containsOnlyKeys("title");
}
use of org.graylog2.plugin.rest.ValidationResult in project graylog2-server by Graylog2.
the class EventDefinitionDtoTest method setUp.
@Before
public void setUp() throws Exception {
final AggregationEventProcessorConfig configMock = mock(AggregationEventProcessorConfig.class);
when(configMock.validate()).thenReturn(new ValidationResult());
testSubject = EventDefinitionDto.builder().title("foo").description("bar").priority(1).alert(false).config(configMock).keySpec(ImmutableList.<String>builder().build()).notificationSettings(EventNotificationSettings.withGracePeriod(0)).build();
}
Aggregations