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
172 changes: 172 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# 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/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.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/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
Pipfile.lock

# PEP 582
__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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# IDE
.idea/
.vscode/
*.swp
*.swo
*~

# Claude Code
.claude/*

# OS
.DS_Store
Thumbs.db

# Testing
.pytest_cache/
.coverage
htmlcov/
coverage.xml
*.cover
.hypothesis/
.tox/
.nox/

# Virtual environments
venv/
.venv/
ENV/
env/
.env

# Build artifacts
build/
dist/
*.egg-info/
.eggs/

# Package manager files
# Note: Do NOT ignore poetry.lock or uv.lock
pip-log.txt
pip-delete-this-directory.txt
451 changes: 451 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[tool.poetry]
name = "weblogicscan"
version = "0.1.0"
description = "WebLogic vulnerability scanner"
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "app"}]

[tool.poetry.dependencies]
python = "^3.8"
requests = "*"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"

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

[tool.pytest.ini_options]
minversion = "7.0"
addopts = [
"-ra",
"--strict-markers",
"--strict-config",
"--cov=app",
"--cov-branch",
"--cov-report=term-missing:skip-covered",
"--cov-report=html",
"--cov-report=xml",
"--cov-fail-under=80",
]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Tests that take a long time to run",
]

[tool.coverage.run]
source = ["app"]
branch = true
omit = [
"*/tests/*",
"*/__pycache__/*",
"*/venv/*",
"*/.venv/*",
]

[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",
]
show_missing = true
precision = 2

[tool.coverage.html]
directory = "htmlcov"

[tool.coverage.xml]
output = "coverage.xml"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.
110 changes: 110 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""Shared pytest fixtures and configuration."""
import os
import shutil
import tempfile
from pathlib import Path
from typing import Generator
from unittest.mock import Mock

import pytest


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for testing."""
temp_path = tempfile.mkdtemp()
yield Path(temp_path)
shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def mock_config() -> dict:
"""Return a mock configuration dictionary."""
return {
"host": "localhost",
"port": 7001,
"timeout": 30,
"verify_ssl": False,
"threads": 10,
"verbose": False,
}


@pytest.fixture
def mock_response():
"""Create a mock HTTP response."""
response = Mock()
response.status_code = 200
response.text = "Mock response"
response.content = b"Mock response"
response.headers = {"Content-Type": "text/html"}
response.json.return_value = {"status": "ok"}
return response


@pytest.fixture
def mock_requests(monkeypatch, mock_response):
"""Mock requests module."""
import sys
mock_req = Mock()
mock_req.get.return_value = mock_response
mock_req.post.return_value = mock_response
mock_req.put.return_value = mock_response
mock_req.delete.return_value = mock_response
mock_req.Session = Mock
mock_req.Session.return_value = mock_req
monkeypatch.setitem(sys.modules, "requests", mock_req)
return mock_req


@pytest.fixture
def test_data_dir() -> Path:
"""Return path to test data directory."""
return Path(__file__).parent / "data"


@pytest.fixture
def sample_url() -> str:
"""Return a sample WebLogic URL for testing."""
return "http://localhost:7001/console"


@pytest.fixture
def sample_payload() -> dict:
"""Return a sample payload for testing."""
return {
"username": "weblogic",
"password": "weblogic123",
"command": "whoami",
}


@pytest.fixture(autouse=True)
def reset_environment():
"""Reset environment variables before each test."""
original_env = os.environ.copy()
yield
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture
def capture_logs(caplog):
"""Fixture to capture log messages during tests."""
with caplog.at_level("DEBUG"):
yield caplog


@pytest.fixture
def mock_file_system(tmp_path):
"""Create a mock file system structure for testing."""
structure = {
"config": tmp_path / "config",
"logs": tmp_path / "logs",
"output": tmp_path / "output",
}

for path in structure.values():
path.mkdir(parents=True, exist_ok=True)

return structure
Empty file added tests/integration/__init__.py
Empty file.
Loading