Ranjan Parekh

13 papers Journal 3Unranked 9
YearRankTypeTitle / Venue / Authors
2020 J jnl
J. King Saud Univ. Comput. Inf. Sci.
Jyotismita Chaki, Ranjan Parekh, Samar Bhattacharya
2018 conf
CICBA (2)
Susovan Jana, Ranjan Parekh, Bijan Sarkar
2018 conf
CICBA (1)
Chandrima Ganguly, Susovan Jana, Ranjan Parekh
2017 conf
CICBA (2)
Jyotismita Chaki, Ranjan Parekh, Samar Bhattacharya
2017 conf
CICBA (2)
Susovan Jana, Ranjan Parekh
2015 J jnl
Pattern Recognit. Lett.
Jyotismita Chaki, Ranjan Parekh, Samar Bhattacharya
2015 conf
ReTIS
Jyotismita Chaki, Ranjan Parekh, Samar Bhattacharya
2013 ch.
Handbook of Medical and Healthcare Technologies
Jyotismita Chaki, Ranjan Parekh
2012 J jnl
IEEE Multim.
Ranjan Parekh
2011 conf
ICCCS
Sankar Roy, Ranjan Parekh
2011 conf
ICCCS
Nabanita Bhattacharjee, Ranjan Parekh
2006 conf
ICIT
Ranjan Parekh
2005 conf
ITRE
Ranjan Parekh
tests/unit/test_extractor_registry.py
← Index tests/unit/test_extractor_registry.py python
"""
Unit tests for the extractor registry (redb/extractor_registry.py).

Verifies that all file-type groups load correctly, return the expected
extractors, and that lookup/filtering logic works as intended.
"""
import pytest

from redb.extractor_registry import (
    get_filetype_modules,
    get_extractor_class,
    FILETYPE_TO_GROUP,
    _REGISTRY,
)

pytestmark = [pytest.mark.unit]


# ============================================================================
# get_filetype_modules — group loading
# ============================================================================

class TestGetFiletypeModules:

    @pytest.mark.parametrize("filetype,expected_names", [
        ("pebin", [
            "PEFeaturesExtractor", "PEImportExtractor", "PEResourceExtractor",
            "PEOverlayExtractor", "PESectionExtractor", "PESignatureExtractor",
            "PEExtraFindings", "PEInconstistencyTestsExtractor", "PEDotNetExtractor",
        ]),
        ("elf", [
            "ELFFeaturesExtractor", "ELFSegmentExtractor", "ELFSectionExtractor",
            "ELFDependencyExtractor", "ELFSymbolExtractor", "ELFImportExtractor",
            "ELFExportExtractor", "ELFRelocationExtractor", "ELFNotesExtractor",
        ]),
        ("macho", [
            "MachOFeaturesExtractor", "MachOSegmentExtractor",
            "MachOImportExtractor", "MachOExportExtractor",
            "MachODylibExtractor", "MachOSignatureExtractor",
        ]),
        ("apk", [
            "APKFeaturesExtractor", "APKManifestExtractor",
            "APKPermissionsExtractor", "APKSignatureExtractor",
            "APKDexExtractor", "APKResourceExtractor",
            "APKNativeLibExtractor", "APKInconsistencyTestsExtractor",
        ]),
    ])
    def test_loads_all_extractors_for_filetype(self, filetype, expected_names):
        """Each filetype group should return all its registered extractors."""
        modules = get_filetype_modules(filetype)
        names = [m.__name__ for m in modules]
        for expected in expected_names:
            assert expected in names, f"{expected} missing from {filetype} modules"

    def test_apk_excludes_decompilers(self):
        """get_filetype_modules should not include DecompileAPK."""
        modules = get_filetype_modules("apk")
        names = [m.__name__ for m in modules]
        assert "DecompileAPK" not in names

    def test_unknown_filetype_returns_empty(self):
        """An unrecognized filetype should return an empty list."""
        assert get_filetype_modules("unknown_format") == []

    def test_returned_classes_are_callable(self):
        """All returned extractor classes should be callable (i.e., actual classes)."""
        for filetype in FILETYPE_TO_GROUP:
            for cls in get_filetype_modules(filetype):
                assert callable(cls), f"{cls} is not callable"


# ============================================================================
# get_extractor_class — single lookup
# ============================================================================

class TestGetExtractorClass:

    def test_finds_pe_extractor(self):
        cls = get_extractor_class("PEFeaturesExtractor")
        assert cls is not None
        assert cls.__name__ == "PEFeaturesExtractor"

    def test_finds_elf_extractor(self):
        cls = get_extractor_class("ELFSectionExtractor")
        assert cls is not None
        assert cls.__name__ == "ELFSectionExtractor"

    def test_finds_macho_extractor(self):
        cls = get_extractor_class("MachOSignatureExtractor")
        assert cls is not None
        assert cls.__name__ == "MachOSignatureExtractor"

    def test_finds_apk_extractor(self):
        cls = get_extractor_class("APKDexExtractor")
        assert cls is not None
        assert cls.__name__ == "APKDexExtractor"

    def test_finds_decompile_apk(self):
        cls = get_extractor_class("DecompileAPK")
        assert cls is not None
        assert cls.__name__ == "DecompileAPK"

    def test_returns_none_for_unknown(self):
        assert get_extractor_class("NonExistentExtractor") is None


# ============================================================================
# Registry completeness
# ============================================================================

class TestRegistryCompleteness:

    def test_all_filetypes_have_registry_group(self):
        """Every filetype in FILETYPE_TO_GROUP should map to a valid registry group."""
        for filetype, group in FILETYPE_TO_GROUP.items():
            assert group in _REGISTRY, f"filetype {filetype} maps to unknown group {group}"

    def test_all_registry_groups_are_reachable(self):
        """Every registry group should be reachable via at least one filetype."""
        reachable = set(FILETYPE_TO_GROUP.values())
        for group in _REGISTRY:
            assert group in reachable, f"registry group {group} has no filetype mapping"


# ============================================================================
# Integration with workers.get_module_by_name
# ============================================================================

class TestWorkersGetModuleByName:

    def test_resolves_common_extractor(self):
        from redb.workers import get_module_by_name
        cls = get_module_by_name("BasicPropertiesExtractor")
        assert cls is not None
        assert cls.__name__ == "BasicPropertiesExtractor"

    def test_resolves_type_specific_extractor(self):
        from redb.workers import get_module_by_name
        cls = get_module_by_name("PEFeaturesExtractor")
        assert cls is not None
        assert cls.__name__ == "PEFeaturesExtractor"

    def test_resolves_decompile_apk(self):
        from redb.workers import get_module_by_name
        cls = get_module_by_name("DecompileAPK")
        assert cls is not None

    def test_returns_none_for_unknown(self):
        from redb.workers import get_module_by_name
        assert get_module_by_name("BogusExtractor") is None