Exemple #1
0
    def test_config(self):
        """Test the configuration object"""

        config = Configuration({self.key: self.value})

        self.assertEqual(self.value, config.get(self.key))
        self.assertEqual(self.value, config.get(self.key, self.new_value))
        self.assertEqual(self.new_value,
                         config.get("InexistentKey", self.new_value))
    def test_datastoremanager_default(self):
        """Test the DataStoreManager loading the default DataStore
        """
        manager = DataStoreManager(Configuration())
        datastore = manager.get_datastore()

        #self.assertIsInstance(datastore, MemoryDataStore)

        new_datastore = manager.get_datastore()
        self.assertIs(datastore, new_datastore)
Exemple #3
0
    def test_config_update(self):
        """Test the configuration object update methods"""

        config = Configuration()

        # Update from empty using careful
        config.update({self.key: self.value}, mode="careful")
        self.assertIs(None, config.get(self.key))

        # Update using loose mode
        config.update({self.key: self.value}, mode="loose")
        self.assertIs(self.value, config.get(self.key))

        # Update using careful mode
        config.update({self.new_key: self.new_value}, mode="careful")
        self.assertIs(self.value, config.get(self.key))
        self.assertIs(None, config.get(self.new_key))

        # Updating from another Configuration object
        config.update(Configuration({self.new_new_key: self.new_new_value}))
        self.assertIs(self.new_new_value, config.get(self.new_new_key))
Exemple #4
0
    def test_hpfeeds(self):
        """Tests the HPFeed by connecting to honeynet's HPFriends service.
        """

        # Register an event using the HPFeed
        configuration = Configuration({
            "feed": "HPFeed",
            "feed_host": self.test_host,
            "feed_port": self.test_port,
            "feed_ident": self.test_ident,
            "feed_secret": self.test_secret,
            "channels": [self.test_channel]
        })
Exemple #5
0
    def test_hpfeeds(self):
        """Tests the HPFeed by connecting to honeynet's HPFriends service.
        """

        # Register an event using the HPFeed
        configuration = Configuration({"feed": "HPFeed",
                                       "feed_host": self.test_host,
                                       "feed_port": self.test_port,
                                       "feed_ident": self.test_ident,
                                       "feed_secret": self.test_secret,
                                       "channels": [self.test_channel]})
        feed = HPFeed(configuration)
        event = Event("Test event")
        event.session = Session(Queue(), "test", "127.0.0.1", 3200,
                                "127.0.0.1", 3201)

        feed.log(event)
        feed.stop()
Exemple #6
0
    def test_logfeeds(self):

        self.test_filename = mkstemp(".log", "logfeedstest")[1]

        # Register an event using the LogFeed
        configuration = Configuration({
            "feed": "LogFeed",
            "log_filename": self.test_filename
        })
        feed = LogFeed(configuration)
        event = Event("Test event")
        event.session = Session(Queue(), "test", "127.0.0.1", 3200,
                                "127.0.0.1", 3201)

        feed.log(event)
        feed.stop()

        self.assertIs(path.exists(self.test_filename), True)
Exemple #7
0
    def test_feed_manager(self):
        """Test attack feed manager"""

        # Create a session manager and the feed manager attached to it
        config = Configuration()
        session_manager = SessionManager(config)
        feed_manager = FeedManager(config, session_manager)
        feed_manager.add_feed(DummyFeed(config))
        feed_manager.run()

        # Create an event
        event = Event("Test event")

        # Obtain a session and add the event
        session = session_manager.get_session("test", "127.0.0.1", 3200, "127.0.0.1", 3201)
        session.add_event(event)

        # Give the feed manager time for processing the event
        sleep(1)

        # Stop the feed manager and check if the event was processed
        feed_manager.stop()
        new_event = DummyFeed.events.get()
        self.assertIs(event, new_event)
 def test_datastoremanager_invalid(self):
     """Test the DataStoreManager loading an invalid  DataStore
     """
     with self.assertRaises(DataStoreNotFound):
         DataStoreManager(
             Configuration({"datastore_class": "InexistentClass"}))