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'])
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)
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'])
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)
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)
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)
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()
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)
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()
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()
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)
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 })
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)
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)
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 })
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 } )
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)
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()
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)
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)
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)
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)
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'])
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'])
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')
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')
def setUp(self): yield helpers.TestGL.setUp(self) pollute_events_for_testing() yield Alarm.compute_activity_level()
def setUp(self): yield helpers.TestGL.setUp(self) self.pollute_events() yield Alarm.compute_activity_level()
def setUp(self): yield helpers.TestGL.setUp(self) TokenList.clear() self.pollute_events() yield Alarm.compute_activity_level()