use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class EntitySharesServiceTest method noValidationOnEmptyRequest.
@DisplayName("Don't run validation on initial empty request")
@Test
void noValidationOnEmptyRequest() {
final GRN entity = grnRegistry.newGRN(GRNTypes.DASHBOARD, "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.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 EntityDependencyPermissionCheckerTest method runCheck.
private ImmutableMultimap<GRN, EntityDescriptor> runCheck(boolean isSharingUserAuthorized, boolean isGranteeUserAuthorized) {
final GRN granteeUser = grnRegistry.newGRN("user", "john");
final GRN sharingUser = grnRegistry.newGRN("user", "jane");
final GRN stream = grnRegistry.newGRN("stream", "54e3deadbeefdeadbeef0001");
final GranteeAuthorizer sharingUserAuthorizer = mock(GranteeAuthorizer.class);
final GranteeAuthorizer granteeUserAuthorizer = mock(GranteeAuthorizer.class);
final ImmutableSet<GRN> selectedGrantees = ImmutableSet.of(granteeUser);
final EntityDescriptor dependency = EntityDescriptor.create(stream, "Title", ImmutableSet.of());
final ImmutableSet<EntityDescriptor> dependencies = ImmutableSet.of(dependency);
when(userAuthorizerFactory.create(sharingUser)).thenReturn(sharingUserAuthorizer);
when(userAuthorizerFactory.create(granteeUser)).thenReturn(granteeUserAuthorizer);
when(sharingUserAuthorizer.isPermitted(anyString(), any(GRN.class))).thenReturn(isSharingUserAuthorized);
when(granteeUserAuthorizer.isPermitted("streams:read", stream)).thenReturn(isGranteeUserAuthorized);
final ImmutableMultimap<GRN, EntityDescriptor> checkResult = resolver.check(sharingUser, dependencies, selectedGrantees);
verify(sharingUserAuthorizer, times(1)).isPermitted("streams:read", stream);
verifyNoMoreInteractions(sharingUserAuthorizer);
return checkResult;
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method createWithGrantDTOAndUsernameString.
@Test
public void createWithGrantDTOAndUsernameString() {
final GRN grantee = GRNTypes.USER.toGRN("jane");
final GRN target = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0000");
final GrantDTO grant = dbService.create(GrantDTO.of(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));
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method getOwnersForTargets.
@Test
@MongoDBFixtures("grants.json")
public void getOwnersForTargets() {
final GRN jane = grnRegistry.parse("grn::::user:jane");
final GRN john = grnRegistry.parse("grn::::user:john");
final GRN dashboard1 = grnRegistry.parse("grn::::dashboard:54e3deadbeefdeadbeef0000");
final GRN dashboard2 = grnRegistry.parse("grn::::dashboard:54e3deadbeefdeadbeef0001");
final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
assertThat(dbService.getOwnersForTargets(ImmutableSet.of(dashboard1, dashboard2, stream1))).satisfies(result -> {
assertThat(result.get(dashboard1)).containsExactlyInAnyOrder(jane);
assertThat(result.get(dashboard2)).containsExactlyInAnyOrder(john);
assertThat(result).doesNotContainKey(stream1);
});
}
use of org.graylog.grn.GRN in project graylog2-server by Graylog2.
the class DBGrantServiceTest method getForTarget.
@Test
@MongoDBFixtures("grants.json")
public void getForTarget() {
final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0000");
final GRN stream2 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
assertThat(dbService.getForTarget(stream1)).hasSize(1);
assertThat(dbService.getForTarget(stream2)).hasSize(3);
}
Aggregations