Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Claude Code settings
.claude/*

# Testing artifacts
.pytest_cache/
.coverage
htmlcov/
coverage.xml

# Result files
result.txt
674 changes: 674 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[tool.poetry]
name = "aljcscan"
version = "1.2.0"
description = "A security scanning tool for detecting hidden links and malicious content on websites"
authors = ["tom"]
packages = [{include = "aljcscan.py"}]

[tool.poetry.dependencies]
python = "^3.8"
fake-useragent = "*"
termcolor = "*"
selenium = "*"

[tool.poetry.group.dev.dependencies]
pytest = "*"
pytest-cov = "*"
pytest-mock = "*"

[tool.poetry.scripts]
test = "pytest:main"
tests = "pytest:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--strict-markers",
"--strict-config",
"--cov=.",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-report=term-missing",
"--cov-fail-under=30",
"-v"
]
markers = [
"unit: marks tests as unit tests (fast)",
"integration: marks tests as integration tests (slower)",
"slow: marks tests as slow tests (deselect with '-m \"not slow\"')"
]

[tool.coverage.run]
source = ["."]
omit = [
"tests/*",
"*/tests/*",
"test_*.py",
"*_test.py",
"setup.py",
"*/site-packages/*",
"*/.venv/*",
"*/venv/*",
"htmlcov/*"
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod"
]
Empty file added tests/__init__.py
Empty file.
69 changes: 69 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Shared pytest fixtures for AljcScan testing."""

import os
import tempfile
import pytest
from unittest.mock import Mock, patch


@pytest.fixture
def temp_dir():
"""Create a temporary directory for test files."""
with tempfile.TemporaryDirectory() as tmpdir:
yield tmpdir


@pytest.fixture
def sample_targets_file(temp_dir):
"""Create a sample targets.txt file for testing."""
targets_path = os.path.join(temp_dir, "targets.txt")
with open(targets_path, "w") as f:
f.write("https://example.com\nhttps://test.com\n")
return targets_path


@pytest.fixture
def sample_rules_file(temp_dir):
"""Create a sample rules.txt file for testing."""
rules_path = os.path.join(temp_dir, "rules.txt")
with open(rules_path, "w", encoding="utf-8") as f:
f.write("博彩\n赌博\n色情\n")
return rules_path


@pytest.fixture
def mock_chrome_driver():
"""Mock Chrome WebDriver for testing."""
with patch('aljcscan.Chrome') as mock_chrome:
mock_driver = Mock()
mock_driver.page_source = "<html><body>Test page</body></html>"
mock_chrome.return_value = mock_driver
yield mock_driver


@pytest.fixture
def mock_subprocess():
"""Mock subprocess for testing command execution."""
with patch('aljcscan.subprocess.Popen') as mock_popen:
mock_process = Mock()
mock_process.wait.return_value = None
mock_popen.return_value = mock_process
yield mock_popen


@pytest.fixture
def mock_user_agent():
"""Mock UserAgent for testing."""
with patch('aljcscan.UserAgent') as mock_ua:
mock_ua.return_value.random = "Mozilla/5.0 (Test)"
yield mock_ua


@pytest.fixture
def clean_test_files():
"""Clean up test result files after tests."""
yield
# Clean up any test artifacts
for file in ["result.txt"]:
if os.path.exists(file):
os.remove(file)
Empty file added tests/integration/__init__.py
Empty file.
65 changes: 65 additions & 0 deletions tests/test_setup_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Validation tests to ensure testing infrastructure is properly set up."""

import pytest
import os
import sys

# Add the project root to the path so we can import our module
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

try:
import aljcscan
except ImportError:
aljcscan = None


class TestSetupValidation:
"""Test that the testing infrastructure is properly configured."""

def test_pytest_is_working(self):
"""Basic test to validate pytest is functioning."""
assert True

def test_coverage_is_enabled(self):
"""Test that coverage reporting is enabled."""
# This test validates that coverage is properly configured
# Coverage is enabled if the coverage.xml file gets generated
assert True # Coverage configuration is validated by pytest output

def test_project_module_importable(self):
"""Test that the main project module can be imported."""
assert aljcscan is not None

def test_fixtures_available(self, temp_dir, sample_targets_file):
"""Test that shared fixtures are working."""
assert os.path.exists(temp_dir)
assert os.path.exists(sample_targets_file)

# Verify the content of the targets file
with open(sample_targets_file, 'r') as f:
content = f.read()
assert "https://example.com" in content
assert "https://test.com" in content

@pytest.mark.unit
def test_unit_marker_works(self):
"""Test that the unit test marker is configured."""
assert True

@pytest.mark.integration
def test_integration_marker_works(self):
"""Test that the integration test marker is configured."""
assert True

@pytest.mark.slow
def test_slow_marker_works(self):
"""Test that the slow test marker is configured."""
assert True

def test_main_functions_exist(self):
"""Test that main functions exist in the module."""
if aljcscan:
assert hasattr(aljcscan, 'main')
assert hasattr(aljcscan, 'logo')
assert hasattr(aljcscan, 'radSpider')
assert hasattr(aljcscan, 'All_JC')
Empty file added tests/unit/__init__.py
Empty file.