Search in sources :

Example 1 with MongoConnection

use of org.graylog2.database.MongoConnection in project graylog2-server by Graylog2.

the class UserServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    this.mongoConnection = mongoRule.getMongoConnection();
    this.configuration = new Configuration();
    this.userFactory = new UserImplFactory(configuration);
    this.permissions = new Permissions(ImmutableSet.of(new RestPermissions()));
    this.userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionsResolver);
    when(roleService.getAdminRoleObjectId()).thenReturn("deadbeef");
}
Also used : RestPermissions(org.graylog2.shared.security.RestPermissions) Configuration(org.graylog2.Configuration) RestPermissions(org.graylog2.shared.security.RestPermissions) Permissions(org.graylog2.shared.security.Permissions) Before(org.junit.Before)

Example 2 with MongoConnection

use of org.graylog2.database.MongoConnection in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetPermissionsForUser.

@Test
public void testGetPermissionsForUser() throws Exception {
    final InMemoryRolePermissionResolver permissionResolver = mock(InMemoryRolePermissionResolver.class);
    final UserService userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionResolver);
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    user.setName("user");
    final Role role = createRole("Foo");
    user.setRoleIds(Collections.singleton(role.getId()));
    user.setPermissions(Collections.singletonList("hello:world"));
    when(permissionResolver.resolveStringPermission(role.getId())).thenReturn(Collections.singleton("foo:bar"));
    assertThat(userService.getPermissionsForUser(user)).containsOnly("users:passwordchange:user", "users:edit:user", "foo:bar", "hello:world");
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) UserService(org.graylog2.shared.users.UserService) InMemoryRolePermissionResolver(org.graylog2.security.InMemoryRolePermissionResolver) Test(org.junit.Test)

Example 3 with MongoConnection

use of org.graylog2.database.MongoConnection in project graylog2-server by Graylog2.

the class V20161125161400_AlertReceiversMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    final MongoConnection mongoConnection = mock(MongoConnection.class);
    final DB database = mock(DB.class);
    when(mongoConnection.getDatabase()).thenReturn(database);
    when(database.getCollection(eq("streams"))).thenReturn(dbCollection);
    this.alertReceiversMigration = new V20161125161400_AlertReceiversMigration(clusterConfigService, streamService, alarmCallbackConfigurationService, mongoConnection);
}
Also used : MongoConnection(org.graylog2.database.MongoConnection) DB(com.mongodb.DB) Before(org.junit.Before)

Example 4 with MongoConnection

use of org.graylog2.database.MongoConnection in project graylog2-server by Graylog2.

the class V20170110150100_FixAlertConditionsMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    this.clusterConfigService = spy(new ClusterConfigServiceImpl(objectMapperProvider, fongoRule.getConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), new ClusterEventBus()));
    final MongoConnection mongoConnection = spy(fongoRule.getConnection());
    final MongoDatabase mongoDatabase = spy(fongoRule.getDatabase());
    when(mongoConnection.getMongoDatabase()).thenReturn(mongoDatabase);
    this.collection = spy(mongoDatabase.getCollection("streams"));
    when(mongoDatabase.getCollection("streams")).thenReturn(collection);
    this.migration = new V20170110150100_FixAlertConditionsMigration(mongoConnection, clusterConfigService);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) MongoConnection(org.graylog2.database.MongoConnection) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) ClusterEventBus(org.graylog2.events.ClusterEventBus) MongoDatabase(com.mongodb.client.MongoDatabase) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)3 Configuration (org.graylog2.Configuration)2 MongoConnection (org.graylog2.database.MongoConnection)2 DB (com.mongodb.DB)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)1 ClusterEventBus (org.graylog2.events.ClusterEventBus)1 InMemoryRolePermissionResolver (org.graylog2.security.InMemoryRolePermissionResolver)1 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)1 Permissions (org.graylog2.shared.security.Permissions)1 RestPermissions (org.graylog2.shared.security.RestPermissions)1 Role (org.graylog2.shared.users.Role)1 UserService (org.graylog2.shared.users.UserService)1 Test (org.junit.Test)1