forked from Aabyss-Team/ARL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_finger.py
50 lines (41 loc) · 1.56 KB
/
test_finger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from unittest import TestCase
from app.services import finger_db_cache, finger_db_identify, have_human_rule_from_db
from app import utils
import timeit
import yaml
class TestExpression(TestCase):
def test_finger_db_identify(self):
finger_db_cache.update_cache()
variables = {
'body': "body" * 1024 * 100 + "_test",
'header': "header test2",
'title': "title \" test3",
'icon_hash': "116323821",
}
results = finger_db_identify(variables)
print(results)
print(timeit.timeit(lambda: finger_db_identify(variables), number=1000))
def test_have_human_rule_from_db(self):
test_cases = [
('icon_hash="116323821"', True),
('icon_hash="2062026853"', True),
('body = "test" || icon_hash == "11111111"', False),
('icon_hash="2062026853" ', False),
]
for expression, expected_result in test_cases:
with self.subTest(expression=expression):
self.assertEqual(have_human_rule_from_db(expression), expected_result)
def test_dump_yaml(self):
items = []
results = list(utils.conn_db('fingerprint').find())
cnt = 0
for result in results:
item = dict()
item["name"] = result["name"]
item["rule"] = result["human_rule"]
items.append(item)
cnt += 1
if cnt > 10:
continue
data = yaml.dump(items, default_flow_style=False, sort_keys=False, allow_unicode=True)
print(data)