コード例 #1
0
    def test_save_anomalies(self):
        """
        How create anomalies: a lots of event + compute stress
        """

        # start test
        ANOMALIES_COUNT = 50
        pollute_events_for_testing(ANOMALIES_COUNT)

        Alarm.compute_activity_level()

        anomdet = GLSettings.RecentAnomaliesQ.values()[0]
        self.assertEqual(len(GLSettings.RecentAnomaliesQ.keys()), 1)
        original_date = datetime_to_ISO8601(GLSettings.RecentAnomaliesQ.keys()[0])

        self.assertTrue(isinstance(anomdet, list))
        self.assertTrue(len(anomdet), 2)

        # alarm level was 2, right ?
        self.assertEqual(anomdet[1], 2, "Alarm raised is not 2 anymore ?")

        # every stuff need to be ANOMALIES_AMOUNT * 2, because
        # pollute function put two event each
        for event, count in anomdet[0].iteritems():
            self.assertEqual(count, ANOMALIES_COUNT * 2)

        # scheduler happen to save these anomalies, along with stats
        yield StatisticsSchedule().operation()

        # now if we get our anomalies, we expect the same 10, right ?
        AH = yield get_anomaly_history(limit=10)
        self.assertEqual(original_date, AH[0]['date'])
コード例 #2
0
ファイル: statistics_sched.py プロジェクト: Taipo/GlobaLeaks
    def operation(self):
        Alarm.compute_activity_level()

        free_disk_bytes, total_disk_bytes = get_workingdir_space()
        free_ramdisk_bytes, total_ramdisk_bytes = get_ramdisk_space()

        Alarm.check_disk_anomalies(free_disk_bytes, total_disk_bytes, free_ramdisk_bytes, total_ramdisk_bytes)
コード例 #3
0
ファイル: test_alerting.py プロジェクト: evilaliv3/GlobaLeaks
    def test_save_anomalies(self):
        """
        How create anomalies: a lots of event + compute stress
        """

        # start test
        ANOMALIES_AMOUNT = 50
        pollute_events_for_testing(ANOMALIES_AMOUNT)

        Alarm.compute_activity_level()

        anomdet = GLSettings.RecentAnomaliesQ.values()[0]
        self.assertEqual(len(GLSettings.RecentAnomaliesQ.keys()), 1)
        original_date = datetime_to_ISO8601(
            GLSettings.RecentAnomaliesQ.keys()[0])

        self.assertTrue(isinstance(anomdet, list))
        self.assertTrue(len(anomdet), 2)

        # alarm level was 2, right ?
        self.assertEqual(anomdet[1], 2, "Alarm raised is not 2 anymore ?")

        # every stuff need to be ANOMALIES_AMOUNT * 2, because
        # pollute function put two event each
        for event, amount in anomdet[0].iteritems():
            self.assertEqual(amount, ANOMALIES_AMOUNT * 2)

        # scheduler happen to save these anomalies, along with stats
        yield StatisticsSchedule().operation()

        # now if we get our anomalies, we expect the same 10, right ?
        AH = yield get_anomaly_history(limit=10)
        self.assertEqual(original_date, AH[0]['date'])
コード例 #4
0
    def operation(self):
        Alarm.compute_activity_level()

        free_disk_bytes, total_disk_bytes = get_workingdir_space()
        free_ramdisk_bytes, total_ramdisk_bytes = get_ramdisk_space()

        Alarm.check_disk_anomalies(free_disk_bytes, total_disk_bytes,
                                   free_ramdisk_bytes, total_ramdisk_bytes)
コード例 #5
0
    def test_event_accouting(self):
        Alarm.compute_activity_level()

        # create one event per type.
        for event_obj in event.outcoming_event_monitored:
            event.EventTrack(event_obj, 1.0)

        x = event.EventTrackQueue.take_current_snapshot()
        self.assertTrue(len(x) > 1)
コード例 #6
0
ファイル: test_anomaly.py プロジェクト: Taipo/GlobaLeaks
    def test_event_accouting(self):
        Alarm.compute_activity_level()

        # create one event per type.
        for event_obj in event.events_monitored:
            event.EventTrack(event_obj, 1.0)

        x = event.EventTrackQueue.take_current_snapshot()
        self.assertTrue(len(x) > 1)
コード例 #7
0
ファイル: test_token.py プロジェクト: vondrakk/GlobaLeaks
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        orig_question = u'77+33'
        token.human_captcha = {
            'question': orig_question,
            'answer': 1,
            'solved': False
        }

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

        handler = self.request(request_payload)
        new_token = yield handler.put(token.id)

        self.assertFalse(token.human_captcha['solved'])

        self.assertEqual(new_token['human_captcha'],
                         token.human_captcha['question'])
        self.assertNotEqual(new_token['human_captcha'], orig_question)

        self.assertIsNot(new_token['human_captcha'], False)
        self.assertNotIn('human_captcha_anwser', new_token)
コード例 #8
0
ファイル: statistics_sched.py プロジェクト: mmaker/GlobaLeaks
 def operation(self, alarm_enable=True):
     """
     Every X seconds is checked if anomalies are happening
     from anonymous interaction (submission/file/comments/whatever flood)
     If the alarm has been raise, logs in the DB the event.
     """
     yield Alarm.compute_activity_level()
コード例 #9
0
    def test_compute_activity_level(self):
        """
        remind: activity level is called every 30 seconds by
        """
        pollute_events_for_testing()
        previous_len = len(event.EventTrackQueue.take_current_snapshot())

        pollute_events_for_testing()
        self.assertEqual(len(event.EventTrackQueue.take_current_snapshot()),
                         previous_len * 2)

        activity_level = yield Alarm.compute_activity_level()
        self.assertEqual(activity_level, 2)

        # Has not slow comeback to 0
        activity_level = yield Alarm.compute_activity_level()
        self.assertEqual(activity_level, 0)
コード例 #10
0
    def operation(self):
        """
        Every X seconds is checked if anomalies are happening
        from anonymous interaction (submission/file/comments/whatever flood)
        If the alarm has been raise, logs in the DB the event.

        This copy data inside StatisticsSchedule.RecentAnomaliesQ
        """
        yield Alarm.compute_activity_level()
コード例 #11
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
コード例 #12
0
    def operation(self):
        """
        Every X seconds is checked if anomalies are happening
        from anonymous interaction (submission/file/comments/whatever flood)
        If the alarm has been raise, logs in the DB the event.

        This copy data inside StatisticsSchedule.RecentAnomaliesQ
        """
        yield Alarm.compute_activity_level()
コード例 #13
0
ファイル: test_token.py プロジェクト: comradekingu/GlobaLeaks
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
コード例 #14
0
ファイル: test_anomaly.py プロジェクト: Taipo/GlobaLeaks
    def test_compute_activity_level(self):
        """
        remind: activity level is called every 30 seconds by
        """
        pollute_events_for_testing()
        previous_len = len(event.EventTrackQueue.take_current_snapshot())

        pollute_events_for_testing()
        self.assertEqual(len(
            event.EventTrackQueue.take_current_snapshot()
        ), previous_len * 2)

        activity_level = yield Alarm.compute_activity_level()
        self.assertEqual(activity_level, 2)

        # Has not slow comeback to 0
        activity_level = yield Alarm.compute_activity_level()
        self.assertEqual(activity_level, 0)
コード例 #15
0
    def test_generate_admin_alert_mail(self):
        # Remind, these two has to be done to get an event matrix meaningful
        pollute_events_for_testing()
        activity_level = yield Alarm.compute_activity_level()

        x = yield Alarm.generate_admin_alert_mail(event_matrix={
            'wb_comments': 100,
            'noise': 12345
        })
コード例 #16
0
ファイル: test_token.py プロジェクト: comradekingu/GlobaLeaks
    def test_post(self):
        yield Alarm.compute_activity_level()

        handler = self.request({'type': 'submission'})

        yield handler.post()

        token = self.responses[0]

        self.assert_default_token_values(token)
コード例 #17
0
    def test_post(self):
        yield Alarm.compute_activity_level()

        handler = self.request({'type': 'submission'})

        handler.request.client_using_tor = True

        response = yield handler.post()

        self.assert_default_token_values(response)
コード例 #18
0
    def test_post(self):
        yield Alarm.compute_activity_level()

        handler = self.request({'type': 'submission'})

        yield handler.post()

        token = self.responses[0]

        self.assert_default_token_values(token)
コード例 #19
0
ファイル: test_anomaly.py プロジェクト: zhou0/GlobaLeaks
    def test_generate_admin_alert_mail(self):
        # Remind, these two has to be done to get an event matrix meaningful
        self.pollute_events()
        activity_level = yield Alarm.compute_activity_level()
        self.assertEqual(activity_level, 2)

        yield Alarm.generate_admin_alert_mail(event_matrix={
            'wb_comments': 100,
            'noise': 12345
        })
コード例 #20
0
ファイル: test_anomaly.py プロジェクト: Taipo/GlobaLeaks
    def test_generate_admin_alert_mail(self):
        # Remind, these two has to be done to get an event matrix meaningful
        pollute_events_for_testing()
        activity_level = yield Alarm.compute_activity_level()

        x = yield Alarm.generate_admin_alert_mail(
            event_matrix = {
                'wb_comments': 100,
                'noise': 12345
            }
        )
コード例 #21
0
    def operation(self):
        """
        The routine periodically checks is checked if the system is having some anomalies
        If the alarm has been raises, it is logged in the db.
        """
        yield Alarm.compute_activity_level()

        free_disk_bytes, total_disk_bytes = get_workingdir_space()
        free_ramdisk_bytes, total_ramdisk_bytes = get_ramdisk_space()

        Alarm.check_disk_anomalies(free_disk_bytes, total_disk_bytes, free_ramdisk_bytes, total_ramdisk_bytes)
コード例 #22
0
    def operation(self):
        """
        The routine periodically checks is checked if the system is having some anomalies
        If the alarm has been raises, it is logged in the db.
        """
        yield Alarm.compute_activity_level()

        free_disk_bytes, total_disk_bytes = get_workingdir_space()
        free_ramdisk_bytes, total_ramdisk_bytes = get_ramdisk_space()

        Alarm.check_disk_anomalies(free_disk_bytes, total_disk_bytes,
                                   free_ramdisk_bytes, total_ramdisk_bytes)
コード例 #23
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        # This is at the beginning
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
コード例 #24
0
ファイル: test_token.py プロジェクト: jpobley/GlobaLeaks
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        # This is at the beginning
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        # Token submission
        st = Token('submission')
        st.generate_token_challenge()
コード例 #25
0
    def test_put_wrong_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX', 'answer': 1, 'solved': False}

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

        handler = self.request(request_payload)
        self.assertRaises(errors.TokenFailure, handler.put, token.id)
コード例 #26
0
    def test_put_wrong_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX','answer': 1, 'solved': False}

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 883

        handler = self.request(request_payload)
        self.assertRaises(errors.TokenFailure, handler.put, token.id)
コード例 #27
0
ファイル: test_token.py プロジェクト: comradekingu/GlobaLeaks
    def test_put_right_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX','answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertEqual(self.responses[0]['human_captcha'], False)
コード例 #28
0
ファイル: test_token.py プロジェクト: evilaliv3/GlobaLeaks
    def test_put_right_answer(self):
        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX', 'answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertEqual(self.responses[0]['human_captcha'], False)
コード例 #29
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')
        token.human_captcha = {'question': 'XXX', 'answer': 1, 'solved': False}
        token.proof_of_work['solved'] = True

        request_payload = token.serialize()
        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)

        response = yield handler.put(token.id)

        token.use()

        self.assertFalse(response['human_captcha'])
        self.assertTrue(token.human_captcha['solved'])
コード例 #30
0
    def test_put_right_answer(self):
        self.pollute_events()
        yield Alarm.compute_activity_level()

        token = Token('submission')
        token.human_captcha = {'question': 'XXX','answer': 1, 'solved': False}
        token.proof_of_work['solved'] = True

        request_payload = token.serialize()
        request_payload['human_captcha_answer'] = 1

        handler = self.request(request_payload)

        yield handler.put(token.id)

        token.use()

        self.assertFalse(self.responses[0]['human_captcha'])
        self.assertTrue(token.human_captcha['solved'])
コード例 #31
0
ファイル: test_token.py プロジェクト: jpobley/GlobaLeaks
    def test_put_wrong_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX', 'answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 2

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertNotEqual(self.responses[0]['human_captcha'], False)

        # verify that the question is changed
        self.assertNotEqual(self.responses[0]['human_captcha'], 'XXX')
コード例 #32
0
ファイル: test_token.py プロジェクト: jpobley/GlobaLeaks
    def test_put_wrong_answer(self):
        event.EventTrackQueue.reset()

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()

        token = Token('submission')

        token.human_captcha = {'question': 'XXX','answer': 1}
        token.proof_of_work = False

        request_payload = token.serialize()

        request_payload['human_captcha_answer'] = 2

        handler = self.request(request_payload)
        yield handler.put(token.id)

        self.assertNotEqual(self.responses[0]['human_captcha'], False)

        # verify that the question is changed
        self.assertNotEqual(self.responses[0]['human_captcha'], 'XXX')
コード例 #33
0
ファイル: test_token.py プロジェクト: pawmsf/GlobaLeaks
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()
コード例 #34
0
ファイル: test_token.py プロジェクト: Taipo/GlobaLeaks
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        pollute_events_for_testing()
        yield Alarm.compute_activity_level()
コード例 #35
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        self.pollute_events()
        yield Alarm.compute_activity_level()
コード例 #36
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)
        TokenList.clear()

        self.pollute_events()
        yield Alarm.compute_activity_level()