Skip to content

Commit e94d2a0

Browse files
committed
Use full microsecond in VULCOID
Signed-off-by: Shivam Sandbhor <[email protected]>
1 parent d93887e commit e94d2a0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

vulnerabilities/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class Vulnerability(models.Model):
4646
max_length=50,
4747
help_text="Unique vulnerability_id for a vulnerability: this is either a published CVE id"
4848
" (as in CVE-2020-7965) if it exists. Otherwise this is a VulnerableCode-assigned VULCOID"
49-
" (as in VULCOID-2021-01-23-15-12). When a vulnerability CVE is assigned later we replace"
50-
" this with the CVE and keep the 'old' VULCOID in the 'old_vulnerability_id' field to "
51-
"support redirection to the CVE id.",
49+
" (as in VULCOID-20210222-1315-16461541). When a vulnerability CVE is assigned later we"
50+
" replace this with the CVE and keep the 'old' VULCOID in the 'old_vulnerability_id'"
51+
" field to support redirection to the CVE id.",
5252
unique=True,
5353
)
5454
old_vulnerability_id = models.CharField(
@@ -72,7 +72,7 @@ def save(self, *args, **kwargs):
7272
def generate_vulcoid(timestamp=None):
7373
if not timestamp:
7474
timestamp = datetime.now()
75-
timestamp = timestamp.strftime("%Y%m%d-%H%M-%S%f")[:-4]
75+
timestamp = timestamp.strftime("%Y%m%d-%H%M-%S%f")
7676
return f"VULCOID-{timestamp}"
7777

7878
@property

vulnerabilities/tests/test_models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ class TestVulnerabilityModel(TestCase):
3434

3535
def test_generate_vulcoid_given_timestamp_object(self):
3636
timestamp_object = datetime(2021, 1, 1, 11, 12, 13, 2000)
37-
expected_vulcoid = "VULCOID-20210101-1112-1300"
37+
expected_vulcoid = "VULCOID-20210101-1112-13002000"
3838
found_vulcoid = models.Vulnerability.generate_vulcoid(timestamp_object)
39+
print(found_vulcoid)
3940
assert expected_vulcoid == found_vulcoid
4041

4142
def test_generate_vulcoid(self):
42-
expected_vulcoid = "VULCOID-20210101-1112-1300"
43-
with freeze_time("2021-01-01 11:12:13.0000"):
43+
expected_vulcoid = "VULCOID-20210101-1112-13000000"
44+
with freeze_time("2021-01-01 11:12:13.000000"):
4445
found_vulcoid = models.Vulnerability.generate_vulcoid()
4546
assert expected_vulcoid == found_vulcoid
4647

@@ -52,11 +53,11 @@ def test_vulnerability_save_with_vulnerability_id(self):
5253
@pytest.mark.django_db
5354
def test_vulnerability_save_without_vulnerability_id(self):
5455
assert models.Vulnerability.objects.filter(
55-
vulnerability_id="VULCOID-20210101-1112-1300"
56+
vulnerability_id="VULCOID-20210101-1112-13000000"
5657
).count() == 0
5758

58-
with freeze_time("2021-01-01 11:12:13.0000"):
59+
with freeze_time("2021-01-01 11:12:13.000000"):
5960
models.Vulnerability(vulnerability_id="").save()
6061
assert models.Vulnerability.objects.filter(
61-
vulnerability_id="VULCOID-20210101-1112-1300"
62+
vulnerability_id="VULCOID-20210101-1112-13000000"
6263
).count() == 1

0 commit comments

Comments
 (0)