Beispiel #1
0
    def test_handle_event(self, mock_decrypt):
        @patch("Bcfg2.Server.Plugins.Cfg.CfgGenerator.handle_event")
        @patch("Bcfg2.Options.setup.lax_decryption", False)
        def inner(mock_handle_event):
            def reset():
                mock_decrypt.reset_mock()
                mock_handle_event.reset_mock()

            def get_event_data(obj, event):
                obj.data = "encrypted"

            mock_handle_event.side_effect = get_event_data
            mock_decrypt.side_effect = lambda d, **kw: "plaintext"
            event = Mock()
            ceg = self.get_obj()
            ceg.handle_event(event)
            mock_handle_event.assert_called_with(ceg, event)
            mock_decrypt.assert_called_with("encrypted")
            self.assertEqual(ceg.data, "plaintext")

            reset()
            mock_decrypt.side_effect = EVPError
            self.assertRaises(PluginExecutionError, ceg.handle_event, event)

        inner()

        # to perform the tests from the parent test object, we
        # make bruteforce_decrypt just return whatever data was
        # given to it
        mock_decrypt.side_effect = lambda d, **kw: d
        TestCfgGenerator.test_handle_event(self)
    def test_handle_event(self, mock_decrypt):
        @patch("Bcfg2.Server.Plugins.Cfg.CfgGenerator.handle_event")
        @patch("Bcfg2.Options.setup.lax_decryption", False)
        def inner(mock_handle_event):
            def reset():
                mock_decrypt.reset_mock()
                mock_handle_event.reset_mock()

            def get_event_data(obj, event):
                obj.data = "encrypted"

            mock_handle_event.side_effect = get_event_data
            mock_decrypt.side_effect = lambda d, **kw: "plaintext"
            event = Mock()
            ceg = self.get_obj()
            ceg.handle_event(event)
            mock_handle_event.assert_called_with(ceg, event)
            mock_decrypt.assert_called_with("encrypted")
            self.assertEqual(ceg.data, "plaintext")

            reset()
            mock_decrypt.side_effect = EVPError
            self.assertRaises(PluginExecutionError,
                              ceg.handle_event, event)
        inner()

        # to perform the tests from the parent test object, we
        # make bruteforce_decrypt just return whatever data was
        # given to it
        mock_decrypt.side_effect = lambda d, **kw: d
        TestCfgGenerator.test_handle_event(self)
        def test_handle_event(self):
            @patch("Bcfg2.Server.Plugins.Cfg.CfgGenerator.handle_event")
            def inner(mock_handle_event):
                cgg = self.get_obj()
                cgg.loader = Mock()
                cgg.data = "template data"
                event = Mock()
                cgg.handle_event(event)
                cgg.loader.load.assert_called_with(cgg.name,
                                                   cls=NewTextTemplate,
                                                   encoding=cgg.encoding)

                cgg.loader.reset_mock()
                cgg.loader.load.side_effect = OSError
                self.assertRaises(PluginExecutionError,
                                  cgg.handle_event, event)
                cgg.loader.load.assert_called_with(cgg.name,
                                                   cls=NewTextTemplate,
                                                   encoding=cgg.encoding)

            inner()
            loader_cls = self.test_obj.__loader_cls__
            self.test_obj.__loader_cls__ = Mock
            TestCfgGenerator.test_handle_event(self)
            self.test_obj.__loader_cls__ = loader_cls
        def test_handle_event(self):
            @patch("Bcfg2.Server.Plugins.Cfg.CfgGenerator.handle_event")
            def inner(mock_handle_event):
                cgg = self.get_obj()
                cgg.loader = Mock()
                cgg.data = "template data"
                event = Mock()
                cgg.handle_event(event)
                cgg.loader.load.assert_called_with(cgg.name,
                                                   cls=NewTextTemplate,
                                                   encoding=cgg.encoding)

                cgg.loader.reset_mock()
                cgg.loader.load.side_effect = OSError
                self.assertRaises(PluginExecutionError, cgg.handle_event,
                                  event)
                cgg.loader.load.assert_called_with(cgg.name,
                                                   cls=NewTextTemplate,
                                                   encoding=cgg.encoding)

            inner()
            loader_cls = self.test_obj.__loader_cls__
            self.test_obj.__loader_cls__ = Mock
            TestCfgGenerator.test_handle_event(self)
            self.test_obj.__loader_cls__ = loader_cls
Beispiel #5
0
    def test_get_data(self):
        ceg = self.get_obj()
        ceg.data = None
        entry = lxml.etree.Element("Path", name="/test.txt")
        metadata = Mock()

        self.assertRaises(PluginExecutionError, ceg.get_data, entry, metadata)

        TestCfgGenerator.test_get_data(self)
    def test_get_data(self):
        ceg = self.get_obj()
        ceg.data = None
        entry = lxml.etree.Element("Path", name="/test.txt")
        metadata = Mock()

        self.assertRaises(PluginExecutionError,
                          ceg.get_data, entry, metadata)

        TestCfgGenerator.test_get_data(self)
Beispiel #7
0
 def test__init(self):
     TestCfgGenerator.test__init(self)
     cgg = self.get_obj()
     self.assertIsInstance(cgg.loader, cgg.__loader_cls__)
Beispiel #8
0
 def setUp(self):
     TestCfgGenerator.setUp(self)
     set_setup_default("repository", datastore)
Beispiel #9
0
 def test__init(self):
     TestCfgGenerator.test__init(self)
     cgg = self.get_obj()
     self.assertIsInstance(cgg.loader, cgg.__loader_cls__)
Beispiel #10
0
 def setUp(self):
     TestCfgGenerator.setUp(self)
     set_setup_default("repository", datastore)
 def setUp(self):
     TestCfgGenerator.setUp(self)
Beispiel #12
0
 def setUp(self):
     TestCfgGenerator.setUp(self)
 def setUp(self):
     TestCfgGenerator.setUp(self)
     TestStructFile.setUp(self)
 def setUp(self):
     TestCfgGenerator.setUp(self)
     TestStructFile.setUp(self)