Пример #1
0
 def test_value_no_match(self):
     """
     Tests the parse method for a 'value' method when a string has no
     match.
     """
     parser = MailParser(source_field='Content',
                         method='SUBSTRING',
                         regex='Threats:\s*(\w+)\n')
     result = parser.process(self.msg)
     self.assertEqual(result, None)
Пример #2
0
 def test_count_multi_matches(self):
     """
     Tests the parse method for a 'count' method when a string has
     multiple matches.
     """
     parser = MailParser(source_field='Content',
                         method='COUNT',
                         regex='Bad Bots')
     result = parser.process(self.msg)
     self.assertEqual(result, 2)
Пример #3
0
 def test_presence_false(self):
     """
     Tests the parse method for a 'presence' method when a string has no
     match.
     """
     parser = MailParser(source_field='Content',
                         method='P/A',
                         regex='Bad Robots')
     result = parser.process(self.msg)
     self.assertFalse(result)
Пример #4
0
 def test_sanitize(self):
     """
     Makes sure the _get_values method strips malicious code.
     """
     parser = MailParser(source_field='Content',
                         method='COPY',
                         regex='Bad Robots')
     assert 'SCRIPT' in str(get_content(self.msg))
     result = parser.process(self.msg)
     self.assertFalse(re.search('SCRIPT', str(result), re.IGNORECASE))