Exemplo n.º 1
0
 def test_insert_data(self, mock_nl_start, mock_dm_start):
     fw = Framework(config_path)
     fw.start()
     test_dict = {'a': 1, 'b': 2}
     with patch('database.datamanager.DataManager.insert_data') as mock_insert_data:
         fw.insert_data(test_dict)
         mock_insert_data.assert_called_with(test_dict)
Exemplo n.º 2
0
    def test_dont_drop_permissions(self, mock_setgid, mock_setuid,
                                   mock_setgroups):
        fw = Framework(config_path)
        fw.drop_permissions()

        self.assertFalse(mock_setuid.called)
        self.assertFalse(mock_setgid.called)
        self.assertFalse(mock_setgroups.called)
Exemplo n.º 3
0
 def test_plugins_enabled(self, mock_nl_start, mock_dm_start):
     framework = Framework(config_path)
     framework.start()
     expected = {
         8082: make_mock_config(8082, 'HTTPPlugin', 'HTTPPlugin')
     }
     self.assertEqual(expected, framework.global_config.get_plugin_dictionary())
     self.assertEqual(1, mock_nl_start.call_count)
     self.assertTrue(mock_dm_start.called)
Exemplo n.º 4
0
    def test_drop_permissions(self, mock_getenv, mock_setgid, mock_setuid,
                              mock_setgroups, mock_getuid):
        fw = Framework(config_path)

        nobody_uid = pwd.getpwnam('nobody').pw_uid
        nogroup_gid = grp.getgrnam('nogroup').gr_gid

        fw.drop_permissions()

        mock_setuid.assert_called_with(nobody_uid)
        mock_setgid.assert_called_with(nogroup_gid)
        mock_setgroups.assert_called_with([])
Exemplo n.º 5
0
    def test_shutdown(self):
        fw = Framework(config_path)
        for i in range(5):
            fw.listener_list[i] = MagicMock()
            fw.listener_list[i].shutdown = MagicMock()
        for i in range(5):
            fw.running_plugins_list.append(MagicMock())
            fw.running_plugins_list[i].shutdown = MagicMock()
        fw.data_manager = MagicMock()
        fw.data_manager.shutdown = MagicMock()

        fw.shutdown(None)

        for listener in fw.listener_list.values():
            self.assertTrue(listener.shutdown.called)
        for plugin in fw.running_plugins_list:
            self.assertTrue(plugin.shutdown.called)
        self.assertTrue(fw.data_manager.shutdown.called)
Exemplo n.º 6
0
    def test_plugin_stopped(self):
        fw = Framework(config_path)
        for i in range(5):
            fw.running_plugins_list.append(MagicMock())
        stopped_plugin = fw.running_plugins_list[1]
        fw.plugin_stopped(stopped_plugin)
        self.assertFalse(stopped_plugin in fw.running_plugins_list)

        stopped_plugin = fw.running_plugins_list[2]
        fw.shutting_down = True
        fw.plugin_stopped(stopped_plugin)
        self.assertTrue(stopped_plugin in fw.running_plugins_list)
Exemplo n.º 7
0
 def test_spawn(self, mock_gpn, mock_gsn, mock_nl_start, mock_dm_start):
     framework = Framework(config_path)
     framework.start()
     with patch('plugins.http.HTTPPlugin.start') as mock_http_start:
         framework.spawn(socket.socket(), {'port': 8082})
     self.assertTrue(mock_http_start.called)
Exemplo n.º 8
0
 def test_get_config(self, mock_nl_start, mock_dm_start):
     framework = Framework(config_path)
     framework.start()
     expected = make_mock_config(8082, 'HTTPPlugin', 'HTTPPlugin')
     self.assertEqual(expected, framework.get_config(8082))
Exemplo n.º 9
0
 def test_plugins_disabled(self, mock_nl_start, mock_dm_start):
     framework = Framework(config_path)
     framework.start()
     self.assertTrue(8083 not in framework.global_config.get_plugin_dictionary())
     self.assertTrue(8082 in framework.global_config.get_plugin_dictionary())
     self.assertEqual(1, mock_nl_start.call_count)
Exemplo n.º 10
0
 def test_cant_drop_permissions(self, mock_getenv, mock_setgid, mock_setuid,
                                mock_setgroups, mock_getuid):
     fw = Framework(config_path)
     self.assertFalse(fw.drop_permissions())