Skip to content

Commit

Permalink
Add unit tests for create_vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
elyousfi5 committed Feb 24, 2025
1 parent 810c4af commit 03df606
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/definitions_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Unit tests for definitions module."""

from ostorlab.agent.kb import kb
from ostorlab.agent.mixins import agent_report_vulnerability_mixin

from agent import definitions


def testCreateVulnerability_whenBasicMetadata_createsCorrectVulnerability() -> None:
"""Test creation of vulnerability with basic metadata."""

class TestExploit(definitions.Exploit):
"""Test exploit class."""

metadata = definitions.VulnerabilityMetadata(
title="Test Vulnerability",
description="Test Description",
Expand Down Expand Up @@ -45,14 +46,16 @@ def check(self, target: definitions.Target) -> list[definitions.Vulnerability]:

def testCreateVulnerability_whenCustomReferences_includesAllReferences() -> None:
"""Test creation of vulnerability with custom references."""

class TestExploit(definitions.Exploit):
"""Test exploit class."""

metadata = definitions.VulnerabilityMetadata(
title="Test Vulnerability",
description="Test Description",
reference="CVE-2024-1234",
risk_rating="HIGH",
references={"extra-ref": "https://example.com/ref"}
references={"extra-ref": "https://example.com/ref"},
)

def accept(self, target: definitions.Target) -> bool:
Expand All @@ -67,13 +70,16 @@ def check(self, target: definitions.Target) -> list[definitions.Vulnerability]:

assert vulnerability.entry.references == {
"nvd.nist.gov": "https://nvd.nist.gov/vuln/detail/CVE-2024-1234",
"extra-ref": "https://example.com/ref"
"extra-ref": "https://example.com/ref",
}


def testCreateVulnerability_whenAllMetadataFields_setsAllFields() -> None:
"""Test creation of vulnerability with all metadata fields."""

class TestExploit(definitions.Exploit):
"""Test exploit class."""

metadata = definitions.VulnerabilityMetadata(
title="Test Vulnerability",
description="Test Description",
Expand Down

0 comments on commit 03df606

Please sign in to comment.