Skip to content

Commit dd2dd17

Browse files
committed
fix: missing tests, comments on class reflect actual functionality
1 parent cad4a52 commit dd2dd17

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

src/macaron/malware_analyzer/pypi_heuristics/metadata/anomalistic_version.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2024 - 2025, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""The heuristic analyzer to check for an anomalistic package version."""
@@ -27,11 +27,32 @@ class AnomalisticVersionAnalyzer(BaseHeuristicAnalyzer):
2727
If the version does not adhere to PyPI standards (PEP 440, as per the 'packaging' module), this heuristic
2828
cannot analyze it.
2929
30-
Calendar versioning is detected as version numbers with the major value as the year (either yyyy or yy),
31-
the minor as the month, and the micro as the day (+/- 2 days), with no further values.
30+
Calendar versioning is detected as version numbers with the year, month and day present in the following combinations:
31+
(using the example 11th October 2016)
32+
- YYYY.MM.DD, e.g. 2016.10.11
33+
- YYYY.DD.MM, e.g. 2016.11.10
34+
- YY.DD.MM, e.g. 16.11.10
35+
- YY.MM.DD, e.g. 16.10.11
36+
- MM.DD.YYYY, e.g. 10.11.2016
37+
- DD.MM.YYYY, e.g. 11.10.2016
38+
- DD.MM.YY, e.g. 11.10.16
39+
- MM.DD.YY, e.g. 10.11.16
40+
- YYYYMMDD, e.g. 20161011
41+
- YYYYDDMM, e.g. 20161110
42+
- YYDDMM, e.g. 161110
43+
- YYMMDD, e.g. 161011
44+
- MMDDYYYY, e.g. 10112016
45+
- DDMMYYYY, e.g. 11102016
46+
- DDMMYY, e.g. 111016
47+
- MMDDYY, e.g. 101116
48+
This may be followed by further versioning (e.g. 2016.10.11.5.6.2). This type of versioning is detected based on the
49+
date of the upload time for the release within a threshold of a number of days (in the defaults file).
3250
3351
Calendar-semantic versioning is detected as version numbers with the major value as the year (either yyyy or yy),
34-
and any other series of numbers following it.
52+
and any other series of numbers following it:
53+
- 2016.7.1 woud be version 7.1 of 2016
54+
- 16.1.4 would be version 1.4 of 2016
55+
This type of versioning is detected based on the exact year of the upload time for the release.
3556
3657
All other versionings are detected as semantic versioning.
3758
"""

tests/malware_analyzer/pypi/test_anomalistic_version.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,58 @@ def test_analyze_no_time(pypi_package_json: MagicMock) -> None:
141141
pytest.param(
142142
"16.10.16", "2016-10-13", HeuristicResult.PASS, Versioning.CALENDAR.value, id="test_calendar_MM.DD.YY_pass"
143143
),
144+
pytest.param(
145+
"20161011.0",
146+
"2016-10-13",
147+
HeuristicResult.PASS,
148+
Versioning.CALENDAR.value,
149+
id="test_calendar_YYYYMMDD_pass",
150+
),
151+
pytest.param(
152+
"20161210.6.1",
153+
"2016-10-13",
154+
HeuristicResult.PASS,
155+
Versioning.CALENDAR.value,
156+
id="test_calendar_YYYYDDMM_pass",
157+
),
158+
pytest.param(
159+
"161013.9.0.5",
160+
"2016-10-13",
161+
HeuristicResult.PASS,
162+
Versioning.CALENDAR.value,
163+
id="test_calendar_YYDDMM_pass",
164+
),
165+
pytest.param(
166+
"161410.2.5.7",
167+
"2016-10-13",
168+
HeuristicResult.PASS,
169+
Versioning.CALENDAR.value,
170+
id="test_calendar_YYMMDD_pass",
171+
),
172+
pytest.param(
173+
"10102016.0",
174+
"2016-10-13",
175+
HeuristicResult.PASS,
176+
Versioning.CALENDAR.value,
177+
id="test_calendar_MMDDYYYY_pass",
178+
),
179+
pytest.param(
180+
"09102016",
181+
"2016-10-13",
182+
HeuristicResult.PASS,
183+
Versioning.CALENDAR.value,
184+
id="test_calendar_DDMMYYYY_pass",
185+
),
186+
pytest.param(
187+
"101516.5.7", "2016-10-13", HeuristicResult.PASS, Versioning.CALENDAR.value, id="test_calendar_DDMMYY_pass"
188+
),
189+
pytest.param(
190+
"161016.0.0.0.0",
191+
"2016-10-13",
192+
HeuristicResult.PASS,
193+
Versioning.CALENDAR.value,
194+
id="test_calendar_MMDDYY_pass",
195+
),
144196
pytest.param(
145197
"2!16.10.17.2.5.3",
146198
"2016-10-13",

0 commit comments

Comments
 (0)