88
99from macaron .errors import HeuristicAnalyzerValueError
1010from macaron .malware_analyzer .pypi_heuristics .heuristics import HeuristicResult
11- from macaron .malware_analyzer .pypi_heuristics .metadata .anomalistic_version import AnomalisticVersionAnalyzer
11+ from macaron .malware_analyzer .pypi_heuristics .metadata .anomalistic_version import AnomalisticVersionAnalyzer , Versioning
1212
1313
1414def test_analyze_no_information (pypi_package_json : MagicMock ) -> None :
@@ -24,34 +24,99 @@ def test_analyze_no_information(pypi_package_json: MagicMock) -> None:
2424@pytest .mark .parametrize (
2525 ("version" , "upload_date" , "result" , "versioning" ),
2626 [
27- pytest .param ("2016-10-13" , "2016-10-13" , HeuristicResult .SKIP , "invalid" , id = "test_invalid_version" ),
28- pytest .param ("2016.10.12.7.3.5" , "2016-10-13" , HeuristicResult .PASS , "calendar" , id = "test_calendar_pass" ),
29- pytest .param ("2!16.10.14.2.5.3" , "2016-10-13" , HeuristicResult .PASS , "calendar" , id = "test_calendar_epoch_pass" ),
30- pytest .param ("100!2016.10.14" , "2016-10-13" , HeuristicResult .FAIL , "calendar" , id = "test_calendar_epoch_fail" ),
3127 pytest .param (
32- "2016.7.2 " , "2016-10-13" , HeuristicResult .PASS , "calendar_semantic" , id = "test_calendar_semantic_pass "
28+ "2016-10-13 " , "2016-10-13" , HeuristicResult .SKIP , Versioning . INVALID . value , id = "test_invalid_version "
3329 ),
3430 pytest .param (
35- "2016.100.0" , "2016-10-13" , HeuristicResult .FAIL , "calendar_semantic" , id = "test_calendar_semantic_fail"
31+ "2016.10.11" ,
32+ "2016-10-13" ,
33+ HeuristicResult .PASS ,
34+ Versioning .CALENDAR .value ,
35+ id = "test_calendar_YYYY.MM.DD_pass" ,
36+ ),
37+ pytest .param (
38+ "2016.12.10" ,
39+ "2016-10-13" ,
40+ HeuristicResult .PASS ,
41+ Versioning .CALENDAR .value ,
42+ id = "test_calendar_YYYY.DD.MM_pass" ,
43+ ),
44+ pytest .param (
45+ "16.10.13" , "2016-10-13" , HeuristicResult .PASS , Versioning .CALENDAR .value , id = "test_calendar_YY.DD.MM_pass"
46+ ),
47+ pytest .param (
48+ "16.14.10" , "2016-10-13" , HeuristicResult .PASS , Versioning .CALENDAR .value , id = "test_calendar_YY.MM.DD_pass"
49+ ),
50+ pytest .param (
51+ "10.10.2016" ,
52+ "2016-10-13" ,
53+ HeuristicResult .PASS ,
54+ Versioning .CALENDAR .value ,
55+ id = "test_calendar_MM.DD.YYYY_pass" ,
56+ ),
57+ pytest .param (
58+ "9.10.2016" ,
59+ "2016-10-13" ,
60+ HeuristicResult .PASS ,
61+ Versioning .CALENDAR .value ,
62+ id = "test_calendar_DD.MM.YYYY_pass" ,
63+ ),
64+ pytest .param (
65+ "10.15.16" , "2016-10-13" , HeuristicResult .PASS , Versioning .CALENDAR .value , id = "test_calendar_DD.MM.YY_pass"
66+ ),
67+ pytest .param (
68+ "16.10.16" , "2016-10-13" , HeuristicResult .PASS , Versioning .CALENDAR .value , id = "test_calendar_MM.DD.YY_pass"
69+ ),
70+ pytest .param (
71+ "2!16.10.17.2.5.3" ,
72+ "2016-10-13" ,
73+ HeuristicResult .PASS ,
74+ Versioning .CALENDAR .value ,
75+ id = "test_calendar_epoch_pass" ,
76+ ),
77+ pytest .param (
78+ "100!2016.10.14" ,
79+ "2016-10-13" ,
80+ HeuristicResult .FAIL ,
81+ Versioning .CALENDAR .value ,
82+ id = "test_calendar_epoch_fail" ,
83+ ),
84+ pytest .param (
85+ "2016.7.2" ,
86+ "2016-10-13" ,
87+ HeuristicResult .PASS ,
88+ Versioning .CALENDAR_SEMANTIC .value ,
89+ id = "test_calendar_semantic_pass" ,
90+ ),
91+ pytest .param (
92+ "2016.100.0" ,
93+ "2016-10-13" ,
94+ HeuristicResult .FAIL ,
95+ Versioning .CALENDAR_SEMANTIC .value ,
96+ id = "test_calendar_semantic_fail" ,
3697 ),
3798 pytest .param (
3899 "2!2016.1.5.6" ,
39100 "2016-10-13" ,
40101 HeuristicResult .PASS ,
41- "calendar_semantic" ,
102+ Versioning . CALENDAR_SEMANTIC . value ,
42103 id = "test_calendar_semantic_epoch_pass" ,
43104 ),
44105 pytest .param (
45106 "100!2016.1" ,
46107 "2016-10-13" ,
47108 HeuristicResult .FAIL ,
48- "calendar_semantic" ,
109+ Versioning . CALENDAR_SEMANTIC . value ,
49110 id = "test_calendar_semantic_epoch_fail" ,
50111 ),
51- pytest .param ("3.1" , "2016-10-13" , HeuristicResult .PASS , "semantic" , id = "test_semantic_pass" ),
52- pytest .param ("999" , "2016-10-13" , HeuristicResult .FAIL , "semantic" , id = "test_semantic_fail" ),
53- pytest .param ("3!0.1.9999" , "2016-10-13" , HeuristicResult .PASS , "semantic" , id = "test_semantic_epoch_pass" ),
54- pytest .param ("999!0.0.0" , "2016-10-13" , HeuristicResult .FAIL , "semantic" , id = "test_semantic_epoch_fail" ),
112+ pytest .param ("3.1" , "2016-10-13" , HeuristicResult .PASS , Versioning .SEMANTIC .value , id = "test_semantic_pass" ),
113+ pytest .param ("999" , "2016-10-13" , HeuristicResult .FAIL , Versioning .SEMANTIC .value , id = "test_semantic_fail" ),
114+ pytest .param (
115+ "3!0.1.9999" , "2016-10-13" , HeuristicResult .PASS , Versioning .SEMANTIC .value , id = "test_semantic_epoch_pass"
116+ ),
117+ pytest .param (
118+ "999!0.0.0" , "2016-10-13" , HeuristicResult .FAIL , Versioning .SEMANTIC .value , id = "test_semantic_epoch_fail"
119+ ),
55120 ],
56121)
57122def test_analyze (
@@ -101,7 +166,7 @@ def test_analyze(
101166
102167 pypi_package_json .get_releases .return_value = release
103168 pypi_package_json .get_latest_version .return_value = version
104- expected_result : tuple [HeuristicResult , dict ] = (result , {"versioning" : versioning })
169+ expected_result : tuple [HeuristicResult , dict ] = (result , {AnomalisticVersionAnalyzer . DETAIL_INFO_KEY : versioning })
105170
106171 actual_result = analyzer .analyze (pypi_package_json )
107172
0 commit comments