Search in sources :

Example 31 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForTargetExcludingGrantee.

@Test
@MongoDBFixtures("grants.json")
public void getForTargetExcludingGrantee() {
    final GRN stream = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
    final GRN grantee = grnRegistry.parse("grn::::user:john");
    assertThat(dbService.getForTargetExcludingGrantee(stream, grantee)).hasSize(2);
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 32 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForGranteesOrGlobalWithCapability.

@Test
@MongoDBFixtures("grants.json")
public void getForGranteesOrGlobalWithCapability() {
    final GRN jane = grnRegistry.newGRN("user", "jane");
    final GRN john = grnRegistry.newGRN("user", "john");
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(jane), Capability.MANAGE)).hasSize(1);
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(jane), Capability.OWN)).hasSize(1);
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(john), Capability.VIEW)).hasSize(2);
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(jane, john), Capability.VIEW)).hasSize(3);
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(jane, john), Capability.MANAGE)).hasSize(1);
    assertThat(dbService.getForGranteesOrGlobalWithCapability(ImmutableSet.of(jane, john), Capability.OWN)).hasSize(2);
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 33 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method hasGrantFor.

@Test
@MongoDBFixtures("grants.json")
public void hasGrantFor() {
    final GRN jane = grnRegistry.parse("grn::::user:jane");
    final GRN dashboard1 = grnRegistry.parse("grn::::dashboard:54e3deadbeefdeadbeef0000");
    final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0000");
    final GRN stream2 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0001");
    assertThat(dbService.hasGrantFor(jane, Capability.VIEW, stream1)).isTrue();
    assertThat(dbService.hasGrantFor(jane, Capability.MANAGE, stream2)).isTrue();
    assertThat(dbService.hasGrantFor(jane, Capability.OWN, dashboard1)).isTrue();
    assertThat(dbService.hasGrantFor(jane, Capability.MANAGE, stream1)).isFalse();
    assertThat(dbService.hasGrantFor(jane, Capability.VIEW, dashboard1)).isFalse();
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 34 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForGranteesOrGlobal.

@Test
@MongoDBFixtures("grants.json")
public void getForGranteesOrGlobal() {
    final GRN jane = grnRegistry.newGRN("user", "jane");
    final GRN john = grnRegistry.newGRN("user", "john");
    assertThat(dbService.getForGranteesOrGlobal(Collections.singleton(jane))).hasSize(4);
    assertThat(dbService.getForGranteesOrGlobal(Collections.singleton(john))).hasSize(3);
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 35 with GRN

use of org.graylog.grn.GRN in project graylog2-server by Graylog2.

the class ViewSharingToGrantsMigrationTest method migrateAllOfInstanceShares.

@Test
@DisplayName("migrate all-of-instance shares")
void migrateAllOfInstanceShares() throws Exception {
    final GRN everyone = GRNRegistry.GLOBAL_USER_GRN;
    when(roleService.load(anyString())).thenThrow(new NotFoundException());
    final GRN dashboard2 = GRNTypes.DASHBOARD.toGRN("54e3deadbeefdeadbeef0003");
    assertThat(grantService.hasGrantFor(everyone, Capability.VIEW, dashboard2)).isFalse();
    migration.upgrade();
    assertThat(grantService.hasGrantFor(everyone, Capability.VIEW, dashboard2)).isTrue();
    assertThat(grantService.hasGrantFor(everyone, Capability.OWN, dashboard2)).isFalse();
    assertThat(grantService.hasGrantFor(everyone, Capability.MANAGE, dashboard2)).isFalse();
    assertDeletedViewSharing("54e3deadbeefdeadbeef0003");
}
Also used : GRN(org.graylog.grn.GRN) NotFoundException(org.graylog2.database.NotFoundException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

GRN (org.graylog.grn.GRN)51 User (org.graylog2.plugin.database.users.User)19 DisplayName (org.junit.jupiter.api.DisplayName)16 Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)13 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)11 Subject (org.apache.shiro.subject.Subject)10 ImmutableSet (com.google.common.collect.ImmutableSet)7 Collectors (java.util.stream.Collectors)5 GRNRegistry (org.graylog.grn.GRNRegistry)5 Capability (org.graylog.security.Capability)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 EventBus (com.google.common.eventbus.EventBus)4 Set (java.util.Set)4 DBGrantService (org.graylog.security.DBGrantService)4 ZonedDateTime (java.time.ZonedDateTime)3 Collection (java.util.Collection)3 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3