Esempio n. 1
0
 def test_calculate_metric_hex_encoded_length(self):
     result = MetricsAnalyzer.calculate_metric("hex_encoded_length",
                                               "12c322adc020 12322029620")
     expected_observation = {
         'max_hex_encoded_length': 12,
         'max_hex_encoded_word': '12c322adc020'
     }
     self.assertEqual(result, (12, expected_observation))
Esempio n. 2
0
    def test_calculate_metric_url_length(self):
        result = MetricsAnalyzer.calculate_metric(
            "url_length", "why don't we go http://www.nviso.com")
        expected_observation = {
            'extracted_urls_length': 20,
            'extracted_urls': 'http://www.nviso.com'
        }

        self.assertEqual(result, (20, expected_observation))
Esempio n. 3
0
    def test_calculate_metric_base64_encoded_length(self):
        result = MetricsAnalyzer.calculate_metric(
            "base64_encoded_length", "houston we have a cHJvYmxlbQ==")
        expected_observation = {
            'max_base64_decoded_length': 7,
            'max_base64_decoded_word': 'problem'
        }

        self.assertEqual(result, (7, expected_observation))
Esempio n. 4
0
 def test_calculate_metric_unexist_operation(self):
     self.assertEqual(
         MetricsAnalyzer.calculate_metric("dummy operation", ""),
         (None, dict()))
Esempio n. 5
0
 def test_calculate_metric_entropy(self):
     self.assertEqual(MetricsAnalyzer.calculate_metric("entropy", "test"),
                      (helpers.utils.shannon_entropy("test"), dict()))
Esempio n. 6
0
 def test_calculate_metric_length(self):
     self.assertEqual(MetricsAnalyzer.calculate_metric("length", "test"),
                      (len("test"), dict()))
Esempio n. 7
0
 def test_calculate_metric_numerical_value(self):
     self.assertEqual(
         MetricsAnalyzer.calculate_metric("numerical_value", "12"),
         (float(12), dict()))