Search in sources :

Example 16 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForGranteeWithCapability.

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

Example 17 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class DBGrantServiceTest method ensure.

@Test
@MongoDBFixtures("grants.json")
public void ensure() {
    final GRN jane = grnRegistry.parse("grn::::user:jane");
    final GRN stream1 = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0000");
    final GRN newStream = grnRegistry.parse("grn::::stream:54e3deadbeefdeadbeef0888");
    // Matches existing grant. Returns original
    final GrantDTO stream1Grant = dbService.getForTargetAndGrantee(stream1, jane).get(0);
    GrantDTO result = dbService.ensure(jane, Capability.VIEW, stream1, "admin");
    assertThat(result).isEqualTo(stream1Grant);
    // Updates to a higher capability
    result = dbService.ensure(jane, Capability.MANAGE, stream1, "admin");
    assertThat(result.capability()).isEqualTo(Capability.MANAGE);
    // Don't downgrade to a lower capability
    result = dbService.ensure(jane, Capability.VIEW, stream1, "admin");
    assertThat(result.capability()).isEqualTo(Capability.MANAGE);
    // Create a new grant
    assertThat(dbService.ensure(jane, Capability.MANAGE, newStream, "admin")).isNotNull();
    assertThat(dbService.getForTarget(newStream)).satisfies(grantDTOS -> {
        assertThat(grantDTOS.size()).isEqualTo(1);
        assertThat(grantDTOS.get(0).grantee()).isEqualTo(jane);
        assertThat(grantDTOS.get(0).capability()).isEqualTo(Capability.MANAGE);
        assertThat(grantDTOS.get(0).target()).isEqualTo(newStream);
    });
}
Also used : GRN(org.graylog.grn.GRN) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 18 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class DBGrantServiceTest method getForGrantee.

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

Example 19 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class V20200204122000_MigrateUntypedViewsToDashboardsTest method doesNotChangeTypedViews.

@Test
@MongoDBFixtures("V20200204122000_MigrateUntypedViewsToDashboardsTest/typed_views.json")
public void doesNotChangeTypedViews() throws Exception {
    this.migration.upgrade();
    final MigrationCompleted migrationCompleted = captureMigrationCompleted();
    assertThat(migrationCompleted.viewIds()).isEmpty();
    verify(this.viewsCollection, times(1)).find(any(Bson.class));
    verify(this.viewsCollection, never()).updateOne(any(BasicDBObject.class), any(Document.class));
    verify(this.searchesCollection, never()).updateOne(any(BasicDBObject.class), any(Document.class));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Document(org.bson.Document) MigrationCompleted(org.graylog.plugins.views.migrations.V20200204122000_MigrateUntypedViewsToDashboards.V20200204122000_MigrateUntypedViewsToDashboards.MigrationCompleted) Bson(org.bson.conversions.Bson) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 20 with MongoDBFixtures

use of org.graylog.testing.mongodb.MongoDBFixtures in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method listExcerpts.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void listExcerpts() {
    final Set<EntityExcerpt> excerpts = facade.listEntityExcerpts();
    final EntityExcerpt excerpt = excerpts.iterator().next();
    assertThat(excerpt.title()).isEqualTo("title");
    assertThat(excerpt.id()).isEqualTo(ModelId.of("5d4032513d2746703d1467f6"));
    assertThat(excerpt.type()).isEqualTo(ModelTypes.EVENT_DEFINITION_V1);
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)167 Test (org.junit.Test)167 Entity (org.graylog2.contentpacks.model.entities.Entity)47 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)47 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)42 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)24 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)23 DateTime (org.joda.time.DateTime)17 ObjectId (org.bson.types.ObjectId)15 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)15 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)11 AbstractMap (java.util.AbstractMap)10 MigrationCompleted (org.graylog.plugins.views.migrations.V20191203120602_MigrateSavedSearchesToViewsSupport.V20191203120602_MigrateSavedSearchesToViews.MigrationCompleted)10 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)10 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)10 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)10 GRN (org.graylog.grn.GRN)9 PipelineEntity (org.graylog2.contentpacks.model.entities.PipelineEntity)9 Document (org.bson.Document)8