<filename>components/collector/tests/source_collectors/owasp_dependency_check/test_dependencies.py
"""Unit tests for the OWASP Dependency Check dependencies collector."""

from collector_utilities.functions import sha1_hash

from .base import OWASPDependencyCheckTestCase


class OWASPDependencyCheckDependenciesTest(OWASPDependencyCheckTestCase):
    """Unit tests for the OWASP Dependency Check metrics."""

    METRIC_TYPE = "dependencies"

    async def test_dependencies(self):
        """Test that the dependencies are returned."""
        response = await self.collect(get_request_text=self.xml)
        expected_entities = [
            dict(
                key="12345",
                url="https://owasp_dependency_check#l1_12345",
                file_name=self.file_name,
                file_path=self.file_path,
            )
        ]
        self.assert_measurement(response, value="1", entities=expected_entities)

    async def test_ignore_part_of_file_path(self):
        """Test that parts of the file path can be ignored, if the secrity warning has no sha1."""
        self.set_source_parameter("variable_file_path_regexp", ["/home/[a-z]+/"])
        response = await self.collect(get_request_text=self.xml.replace("<sha1>12345</sha1>", ""))
        expected_entities = [
            dict(
                key=sha1_hash(self.file_path[len("/home/jenkins/") :] + self.file_name),
                url="",
                file_name=self.file_name,
                file_path=self.file_path,
            )
        ]
        self.assert_measurement(response, value="1", entities=expected_entities)

<filename>components/collector/tests/source_collectors/owasp_dependency_check/test_dependencies.py
"""Unit tests for the OWASP Dependency Check dependencies collector."""

from collector_utilities.functions import sha1_hash

from .base import OWASPDependencyCheckTestCase


class OWASPDependencyCheckDependenciesTest(OWASPDependencyCheckTestCase):
    """Unit tests for the OWASP Dependency Check metrics."""

    METRIC_TYPE = "dependencies"

    async def test_dependencies(self):
        """Test that the dependencies are returned."""
        response = await self.collect(get_request_text=self.xml)
        expected_entities = [
            dict(
                key="12345",
                url="https://owasp_dependency_check#l1_12345",
                file_name=self.file_name,
                file_path=self.file_path,
            )
        ]
        self.assert_measurement(response, value="1", entities=expected_entities)

    async def test_ignore_part_of_file_path(self):
        """Test that parts of the file path can be ignored, if the secrity warning has no sha1."""
        self.set_source_parameter("variable_file_path_regexp", ["/home/[a-z]+/"])
        response = await self.collect(get_request_text=self.xml.replace("<sha1>12345</sha1>", ""))
        expected_entities = [
            dict(
                key=sha1_hash(self.file_path[len("/home/jenkins/") :] + self.file_name),
                url="",
                file_name=self.file_name,
                file_path=self.file_path,
            )
        ]
        self.assert_measurement(response, value="1", entities=expected_entities)

Unit tests for the OWASP Dependency Check dependencies collector. Unit tests for the OWASP Dependency Check metrics. Test that the dependencies are returned. #l1_12345", Test that parts of the file path can be ignored, if the secrity warning has no sha1.