()
| 2 | |
| 3 | |
| 4 | def test_string_matching(): |
| 5 | signatures = [ |
| 6 | { |
| 7 | 'type': 'regex', |
| 8 | 'pattern': '[a-z]:\\\\{2}.{4,}', |
| 9 | 'message': 'regex_pattern', |
| 10 | 'flags': 'I' |
| 11 | }, |
| 12 | { |
| 13 | 'type': 'glob', |
| 14 | 'pattern': '*password*', |
| 15 | 'message': 'glob_pattern' |
| 16 | }, |
| 17 | { |
| 18 | 'type': 'exact', |
| 19 | 'pattern': 'hello_world', |
| 20 | 'message': 'exact_pattern' |
| 21 | }, |
| 22 | 'test_string' |
| 23 | ] |
| 24 | |
| 25 | compiled = pattern_matching.PatternMatcher.compile_patterns(signatures) |
| 26 | assert len(compiled) == 4 |
| 27 | |
| 28 | hit = list(pattern_matching.PatternMatcher.find_matches('C:\\\\Users\\Something', compiled)) |
| 29 | assert len(hit) == 1 |
| 30 | hit = hit[0] |
| 31 | assert hit._signature['message'] == signatures[0]['message'] |
| 32 | |
| 33 | hit = list(pattern_matching.PatternMatcher.find_matches('secret_passwords.txt', compiled)) |
| 34 | assert len(hit) == 1 |
| 35 | hit = hit[0] |
| 36 | assert hit._signature['message'] == signatures[1]['message'] |
| 37 | |
| 38 | hit = list(pattern_matching.PatternMatcher.find_matches('hello_world', compiled)) |
| 39 | assert len(hit) == 1 |
| 40 | hit = hit[0] |
| 41 | assert hit._signature['message'] == signatures[2]['message'] |
| 42 | |
| 43 | hit = list(pattern_matching.PatternMatcher.find_matches('test_string', compiled)) |
| 44 | assert len(hit) == 1 |
| 45 | hit = hit[0] |
| 46 | assert hit._signature['message'] == 'n/a' |
nothing calls this directly
no test coverage detected