diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..6a47abc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,49 @@ +name: Bug report +description: Report a reproducible problem with API Scanner Pro +title: "[Bug]: " +labels: + - bug +body: + - type: markdown + attributes: + value: | + Please search existing issues before opening a new report. + - type: input + id: version + attributes: + label: Version or commit + placeholder: "2.0.0 / commit SHA" + validations: + required: true + - type: input + id: python + attributes: + label: Python version + placeholder: "3.11.x" + validations: + required: true + - type: textarea + id: environment + attributes: + label: Environment + description: OS, browser/runtime, and relevant configuration (never include secrets). + validations: + required: true + - type: textarea + id: steps + attributes: + label: Steps to reproduce + validations: + required: true + - type: textarea + id: expected + attributes: + label: Expected behavior + validations: + required: true + - type: textarea + id: actual + attributes: + label: Actual behavior + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..7ba49d4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,25 @@ +name: Feature request +description: Suggest an improvement to API Scanner Pro +title: "[Feature]: " +labels: + - enhancement +body: + - type: textarea + id: problem + attributes: + label: Problem or use case + description: What problem would this feature solve? + validations: + required: true + - type: textarea + id: proposal + attributes: + label: Proposed solution + validations: + required: true + - type: textarea + id: alternatives + attributes: + label: Alternatives considered + validations: + required: false diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..595c411 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ +## Summary + + + +## Changes + +- + +## Testing + +- [ ] `pytest -q` +- [ ] Relevant manual checks completed +- [ ] Documentation updated if needed + +## Security + +- [ ] No secrets, credentials, session tokens, or private data added +- [ ] Security-sensitive changes include tests/documentation + +## Checklist + +- [ ] Scope is focused +- [ ] Backward compatibility considered +- [ ] README/docs updated where appropriate diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..548ceea --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + push: + branches: ["main", "oss-readiness/**"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.11", "3.12", "3.13"] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: pip + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e ".[dev]" + - name: Run tests + run: pytest -q + - name: Compile package + run: python -m compileall -q api_scanner + - name: Check CLI + run: python -m api_scanner.cli --help diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e7d5795 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# Contributing to API Scanner Pro + +Thank you for considering a contribution. + +## Development setup + +1. Install Python 3.11+. +2. Clone the repository and create a virtual environment. +3. Install dependencies with `pip install -r requirements.txt`. +4. Install the Playwright browser with `playwright install chromium`. +5. Run the test suite with `pytest -q`. + +## Before opening an issue + +Search existing issues first. For security vulnerabilities, do **not** open a public issue; follow [SECURITY.md](SECURITY.md). + +## Pull requests + +1. Fork the repository. +2. Create a focused branch from `main`. +3. Add or update tests for behavioral changes. +4. Keep changes scoped and document user-visible behavior. +5. Run `pytest -q` locally. +6. Run `python -m api_scanner.cli --help` to verify the CLI entry point. +7. Open a pull request using the repository template. + +All pull requests are checked by GitHub Actions. Maintainers may request changes before merging. + +## Contribution principles + +- Prefer small, reviewable changes. +- Do not commit secrets, API keys, session tokens, scan output, or personal data. +- Security-sensitive behavior should include tests and documentation. +- Explain heuristic limitations rather than presenting scanner results as guaranteed verdicts. + +## Code of conduct + +Be respectful, technical, and constructive. Contributions that violate the project's security or collaboration standards may be rejected. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ed6cade --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Skbindas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e3cd9f4..4e65af1 100644 --- a/README.md +++ b/README.md @@ -4,235 +4,154 @@ ![License MIT](https://img.shields.io/badge/License-MIT-green.svg) ![Version 2.0](https://img.shields.io/badge/Version-2.0.0-orange.svg) -## Overview +**API Scanner Pro** is an open-source Python security and developer utility for browser-based API discovery, network inspection, heuristic threat analysis, and report generation. -**API Scanner Pro** is a professional desktop application for scanning websites, detecting API endpoints, analyzing security threats, and exporting comprehensive reports. Built with Python, it combines network interception via Playwright with heuristic-based threat analysis and a modern Tkinter GUI. - ---- - -### Overview (Hindi) - -**API Scanner Pro** एक professional desktop application है जो websites को scan करता है, API endpoints detect करता है, security threats analyze करता है, और comprehensive reports export करता है। Python में built, यह Playwright के माध्यम से network interception को heuristic-based threat analysis और modern Tkinter GUI के साथ combine करता है। - ---- +> **Status:** Active development. The scanner produces evidence and heuristic indicators for investigation; it does not provide definitive vulnerability or malware verdicts. ## Features -### Scanning -- Full browser-based network interception using Playwright -- Automatic API endpoint detection from captured traffic -- Cookie, localStorage, and sessionStorage extraction -- HTML metadata and Open Graph tag parsing -- Configurable scan timeouts and retries - -### Security Analysis -- Heuristic-based URL threat detection (phishing, typosquatting, suspicious TLDs) -- HTML content analysis (hidden iframes, obfuscated JS, suspicious forms) -- Shodan integration for host intelligence (open ports, CVEs, services) -- Risk scoring with severity levels: safe, low, medium, high, critical - -### Export -- JSON export with full metadata and scanner version info -- CSV export with separate files for requests, endpoints, and responses -- HTML report with professional styling, card-based layout, and responsive design -- Batch export via ExportManager for all formats at once - -### User Interface -- Modern Tkinter-based GUI with tabbed interface -- Async scanning with real-time progress feedback -- Dedicated tabs: Scanner, Security, Results, Reports -- Custom widgets: StatusBar, URLInput, LogConsole, RiskBadge - ---- +- Browser network interception with Playwright. +- Likely API endpoint detection from URL and response-content heuristics. +- Cookie, localStorage, and sessionStorage inspection. +- HTML metadata and security-header analysis. +- Deterministic URL/HTML threat heuristics, including IP hosts, suspicious TLDs, typosquatting patterns, suspicious forms, hidden iframes, and obfuscated JavaScript. +- Optional Shodan host intelligence. +- JSON, CSV, and standalone HTML report export. +- Tkinter desktop UI plus a scriptable CLI. +- Automated tests and GitHub Actions CI. ## Architecture -``` +```text Api_Scanner_Bot/ -├── api_scanner/ # Main package -│ ├── __init__.py # Package init, version = "2.0.0" -│ ├── config.py # AppConfig dataclass (env-based settings) -│ ├── exceptions.py # Custom exception hierarchy -│ ├── logger.py # Logging setup (file + console) -│ ├── utils.py # URL validation, rate limiter, retry, serialization -│ ├── main.py # Application entry point -│ ├── scanner/ # Core scanning engine -│ │ ├── models.py # RequestData, ResponseData, ScanResult, etc. -│ │ ├── network_scanner.py # Playwright-based network interception -│ │ ├── storage_analyzer.py # Cookie/storage extraction -│ │ └── meta_analyzer.py # HTML metadata parsing -│ ├── security/ # Security analysis module -│ │ ├── models.py # ThreatReport, SecurityFinding, etc. -│ │ ├── threat_analyzer.py # Heuristic URL/HTML threat detection -│ │ └── shodan_scanner.py # Shodan API integration -│ ├── exporters/ # Report export system -│ │ ├── base.py # BaseExporter abstract class -│ │ ├── json_exporter.py # JSON report generation -│ │ ├── csv_exporter.py # CSV report generation (pandas) -│ │ ├── html_exporter.py # Standalone HTML report generation -│ │ └── export_manager.py # Multi-format export coordinator -│ └── ui/ # Tkinter GUI -│ ├── app.py # Main ScannerApp window -│ ├── async_handler.py # Daemon thread + event loop for async ops -│ ├── widgets.py # Custom reusable widgets -│ ├── scanner_tab.py # URL scan tab -│ ├── security_tab.py # Security analysis tab -│ ├── results_tab.py # Results display tab -│ └── reports_tab.py # Export/reports tab -├── tests/ # Test suite -│ ├── conftest.py # Shared fixtures -│ ├── test_config.py # Config loading tests -│ ├── test_utils.py # Utility function tests -│ ├── test_models.py # Data model tests -│ ├── test_threat_analyzer.py # Threat detection tests -│ └── test_exporters.py # Export system tests -├── logs/ # Application logs -├── .env # Environment configuration (gitignored) -├── .env.example # Example configuration template -├── requirements.txt # Python dependencies -├── pyproject.toml # Project metadata -└── README.md # This file +├── api_scanner/ +│ ├── cli.py # Scriptable command-line interface +│ ├── main.py # Tkinter application entry point +│ ├── config.py # Environment-based configuration +│ ├── exceptions.py +│ ├── logger.py +│ ├── utils.py +│ ├── scanner/ # Network capture, storage, metadata, models +│ ├── security/ # Threat analysis and optional Shodan integration +│ ├── exporters/ # JSON, CSV, HTML reporting +│ └── ui/ # Tkinter interface +├── tests/ +├── docs/ +├── .github/ +│ ├── ISSUE_TEMPLATE/ +│ ├── pull_request_template.md +│ └── workflows/ci.yml +├── CONTRIBUTING.md +├── SECURITY.md +├── LICENSE +├── .env.example +├── requirements.txt +├── pyproject.toml +└── README.md ``` ---- - ## Installation -### Prerequisites - -- Python 3.11 or higher -- pip package manager - -### Step-by-Step Setup +Requirements: Python 3.11+ and Chromium installed by Playwright for browser scans. ```bash -# 1. Clone the repository -git clone https://github.com/your-username/Api_Scanner_Bot.git +git clone https://github.com/Skbindas/Api_Scanner_Bot.git cd Api_Scanner_Bot - -# 2. Create and activate a virtual environment -python3 -m venv venv -source venv/bin/activate # On Windows: venv\Scripts\activate - -# 3. Install dependencies -pip install -r requirements.txt - -# 4. Install Playwright browser (required for scanning) +python -m venv .venv +# macOS/Linux +source .venv/bin/activate +# Windows: .venv\\Scripts\\activate +pip install -e ".[dev]" playwright install chromium - -# 5. Configure environment -cp .env.example .env -# Edit .env with your settings (e.g., add your Shodan API key) - -# 6. Launch the application -python3 -m api_scanner.main ``` ---- - -## Configuration - -All configuration is managed through environment variables. Create a `.env` file (see `.env.example`): - -| Variable | Default | Description | -|----------|---------|-------------| -| `SHODAN_API_KEY` | `""` | Shodan API key for host security scanning | -| `SCAN_TIMEOUT` | `30` | Maximum seconds to wait for a page scan | -| `MAX_RETRIES` | `3` | Number of retries for failed network requests | -| `RATE_LIMIT_DELAY` | `1.0` | Minimum seconds between rate-limited requests | -| `OUTPUT_DIR` | `scan_results` | Directory for storing exported reports | -| `HEADLESS` | `true` | Run browser in headless mode (no visible window) | -| `LOG_LEVEL` | `INFO` | Logging verbosity: DEBUG, INFO, WARNING, ERROR, CRITICAL | - ---- +Optional configuration is documented in `.env.example`. -## Usage +## CLI -### Launch the GUI +The CLI supports reproducible local analysis and automation without launching the Tkinter UI. ```bash -python3 -m api_scanner.main +api-scanner --help +api-scanner analyze-url https://example.com +api-scanner analyze-url https://example.com --json +api-scanner scan https://example.com +api-scanner scan https://example.com --export json csv html ``` -### Scan Workflow +For a visible browser, custom timeout, or output directory: -1. Enter a target URL in the Scanner tab -2. Click "Scan" to start the browser-based analysis -3. View captured API endpoints and network requests in the Results tab -4. Check Security tab for threat analysis results -5. Export reports in JSON, CSV, or HTML format via the Reports tab +```bash +api-scanner scan https://example.com --output-dir ./artifacts --timeout 45 --headed +``` -### Export Formats +The CLI reuses the project's scanning and export components. -- **JSON**: Complete structured data with metadata, ideal for programmatic access -- **CSV**: Tabular data split into requests.csv, api_endpoints.csv, and responses.csv -- **HTML**: Self-contained professional report with embedded CSS, suitable for sharing +## Reproducible usage evidence ---- +This project documents **reproducible local usage instead of making unverifiable claims about external users or production traffic**. -## Development +See [docs/usage-example.md](docs/usage-example.md) for an end-to-end workflow. The test suite covers configuration, models, utilities, threat analysis, exporters, and CLI argument parsing. -### Setup +Run the local checks: ```bash -# Clone and install in development mode -git clone https://github.com/your-username/Api_Scanner_Bot.git -cd Api_Scanner_Bot -python3 -m venv venv -source venv/bin/activate -pip install -r requirements.txt -playwright install chromium +pytest -q +python -m compileall -q api_scanner +python -m api_scanner.cli --help ``` -### Running Tests +GitHub Actions runs the tests and CLI/package smoke checks on Python 3.11, 3.12, and 3.13. -```bash -# Run full test suite -python3 -m pytest tests/ -v +## GUI workflow -# Run specific test module -python3 -m pytest tests/test_threat_analyzer.py -v +1. Enter an authorized target URL. +2. Start the browser-based scan. +3. Review captured requests and likely API endpoints. +4. Review security indicators and metadata. +5. Export JSON, CSV, or HTML reports. -# Run with coverage (if pytest-cov installed) -python3 -m pytest tests/ --cov=api_scanner -v -``` +## Security and privacy -### Code Quality +The scanner can capture request/response metadata and browser storage from a target. Treat scan output as potentially sensitive. -```bash -# Check all files compile without errors -python3 -m py_compile api_scanner/__init__.py -python3 -m py_compile api_scanner/main.py +- Only scan systems you own or have explicit permission to assess. +- Never commit API keys, session tokens, credentials, cookies, or private scan output. +- Review generated reports before sharing them. +- Read [SECURITY.md](SECURITY.md) for vulnerability reporting and safe-use guidance. -# Verify imports work -python3 -c "import api_scanner; print(api_scanner.__version__)" -``` +## Configuration ---- +| Variable | Default | Purpose | +|---|---:|---| +| `SHODAN_API_KEY` | empty | Optional Shodan host intelligence | +| `SCAN_TIMEOUT` | `30` | Page navigation timeout in seconds | +| `MAX_RETRIES` | `3` | Retry count | +| `RATE_LIMIT_DELAY` | `1.0` | Minimum delay between rate-limited requests | +| `OUTPUT_DIR` | `scan_results` | Report output directory | +| `HEADLESS` | `true` | Browser visibility | +| `LOG_LEVEL` | `INFO` | Logging level | -## Testing (Hindi) +## Development ```bash -# पूरा test suite चलाएं -python3 -m pytest tests/ -v - -# Specific module test करें -python3 -m pytest tests/test_threat_analyzer.py -v +pip install -e ".[dev]" +pytest -q +pytest -q tests/test_threat_analyzer.py ``` ---- +The threat-analysis tests are deterministic and do not require a live target. -## License +## Contributing -This project is licensed under the MIT License. +Contributions are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) before opening an issue or pull request. ---- +The repository includes structured bug/feature issue forms, a pull-request checklist, security guidance, and automated CI. -## Contributing +## License + +API Scanner Pro is released under the [MIT License](LICENSE). + +## Maintainer -1. Fork the repository -2. Create a feature branch (`git checkout -b feature/your-feature`) -3. Write tests for your changes -4. Ensure all tests pass (`python3 -m pytest tests/ -v`) -5. Commit your changes with descriptive messages -6. Push and open a Pull Request +Repository: https://github.com/Skbindas/Api_Scanner_Bot diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..4e06c2e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,34 @@ +# Security Policy + +## Supported versions + +Security fixes are currently focused on the latest release on the `main` branch. + +| Version | Supported | +| --- | --- | +| 2.x | Yes | +| < 2.0 | No | + +## Reporting a vulnerability + +Please do **not** disclose suspected vulnerabilities in a public GitHub issue. + +Until a dedicated private security advisory channel is configured, contact the repository maintainer privately through the GitHub profile associated with this repository and include: + +- A clear description of the vulnerability. +- The affected component and version/commit. +- Reproduction steps or a minimal proof of concept. +- Security impact. +- Any suggested mitigation. + +Do not include real credentials, session cookies, API keys, or private user data in reports. + +## Scope and safe testing + +Only scan systems you own or have explicit permission to assess. API Scanner Pro is a security testing utility; users are responsible for authorization and compliance with applicable laws and service terms. + +The scanner uses deterministic heuristics and should not be treated as a definitive malware, phishing, or vulnerability verdict. + +## Response process + +Reports will be reviewed by the maintainer. Valid findings will be triaged, reproduced where practical, fixed or mitigated, and documented in an appropriate release note. diff --git a/api_scanner/cli.py b/api_scanner/cli.py new file mode 100644 index 0000000..c0631cb --- /dev/null +++ b/api_scanner/cli.py @@ -0,0 +1,134 @@ +"""Command-line interface for API Scanner Pro. + +The CLI exposes the deterministic URL analyzer and browser-based scanner +without requiring the Tkinter GUI. +""" + +import argparse +import asyncio +import json +from pathlib import Path +from typing import Sequence + +from api_scanner.config import AppConfig +from api_scanner.scanner.network_scanner import NetworkScanner +from api_scanner.security.threat_analyzer import ThreatAnalyzer + + +def build_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser( + prog="api-scanner", + description="Scan websites for API endpoints and security indicators.", + ) + subparsers = parser.add_subparsers(dest="command", required=True) + + url_parser = subparsers.add_parser( + "analyze-url", help="Run deterministic URL threat heuristics." + ) + url_parser.add_argument("url", help="URL to analyze.") + url_parser.add_argument( + "--json", action="store_true", help="Print machine-readable JSON." + ) + + scan_parser = subparsers.add_parser( + "scan", help="Run a browser-based network/API scan." + ) + scan_parser.add_argument("url", help="Authorized target URL to scan.") + scan_parser.add_argument( + "--export", + nargs="+", + choices=("json", "csv", "html"), + default=(), + help="Export formats to write after scanning.", + ) + scan_parser.add_argument( + "--output-dir", + default="scan_results", + help="Directory for exported reports.", + ) + scan_parser.add_argument( + "--timeout", + type=int, + default=30, + help="Navigation timeout in seconds.", + ) + scan_parser.add_argument( + "--headed", + action="store_true", + help="Run Chromium with a visible window.", + ) + return parser + + +def _threat_report_dict(report) -> dict: + return { + "url": report.url, + "risk_score": report.risk_score, + "risk_level": report.risk_level, + "summary": report.summary, + "indicators": [ + { + "category": i.category, + "description": i.description, + "severity": i.severity, + "evidence": i.evidence, + } + for i in report.indicators + ], + "analyzed_at": report.analyzed_at.isoformat(), + } + + +async def _run_scan(args: argparse.Namespace) -> int: + config = AppConfig( + scan_timeout=args.timeout, + output_dir=args.output_dir, + headless=not args.headed, + ) + scanner = NetworkScanner(config) + result = await scanner.scan(args.url) + + print(f"Target: {result.url}") + print(f"Requests: {len(result.requests)}") + print(f"Responses: {len(result.responses)}") + print(f"API endpoints: {len(result.api_endpoints)}") + print(f"Duration: {result.scan_duration:.2f}s") + + if result.errors: + print(f"Non-fatal errors: {len(result.errors)}") + + if args.export: + from api_scanner.exporters.export_manager import ExportManager + + paths = ExportManager(config).export_all(result, list(args.export)) + for fmt, path in paths.items(): + print(f"{fmt.upper()}: {path}") + return 0 + + +def main(argv: Sequence[str] | None = None) -> int: + parser = build_parser() + args = parser.parse_args(argv) + + if args.command == "analyze-url": + report = ThreatAnalyzer().analyze_url(args.url) + if args.json: + print(json.dumps(_threat_report_dict(report), indent=2)) + else: + print(report.summary) + for indicator in report.indicators: + print( + f"- [{indicator.severity.upper()}] " + f"{indicator.category}: {indicator.description}" + ) + return 0 + + if args.command == "scan": + return asyncio.run(_run_scan(args)) + + parser.error("Unknown command") + return 2 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/docs/usage-example.md b/docs/usage-example.md new file mode 100644 index 0000000..58a9409 --- /dev/null +++ b/docs/usage-example.md @@ -0,0 +1,44 @@ +# Reproducible usage example + +This page documents a reproducible local workflow. The output below is intentionally a procedure rather than a claim about third-party usage. + +## 1. Install + +```bash +python -m venv .venv +# macOS/Linux +source .venv/bin/activate +# Windows +# .venv\\Scripts\\activate + +pip install -e ".[dev]" +playwright install chromium +``` + +## 2. Analyze a URL without browsing + +Use the deterministic threat analyzer when you only need URL heuristics: + +```bash +api-scanner analyze-url https://example.com +``` + +## 3. Run a browser scan + +```bash +api-scanner scan https://example.com --export json html +``` + +The scan captures browser network activity, identifies likely API endpoints, analyzes browser storage and page metadata, and can export reports. + +## 4. Run the test suite + +```bash +pytest -q +``` + +The repository includes tests for configuration, models, utilities, threat analysis, and exporters. CI runs the suite on supported Python versions. + +## Safety + +Only scan targets you own or have explicit permission to assess. Heuristic findings are indicators for investigation, not definitive security verdicts. diff --git a/pyproject.toml b/pyproject.toml index e77986e..3dcd3d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,9 @@ dev = [ "pytest-asyncio>=0.21.0", ] +[project.scripts] +api-scanner = "api_scanner.cli:main" + [tool.pytest.ini_options] testpaths = ["tests"] python_files = ["test_*.py"] @@ -34,4 +37,4 @@ python_functions = ["test_*"] [build-system] requires = ["setuptools>=68.0", "wheel"] -build-backend = "setuptools.backends._legacy:_Backend" +build-backend = "setuptools.build_meta" diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..f697bac --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,27 @@ +from api_scanner.cli import build_parser + + +def test_cli_help_parser() -> None: + parser = build_parser() + args = parser.parse_args(["analyze-url", "https://example.com"]) + assert args.command == "analyze-url" + assert args.url == "https://example.com" + + +def test_scan_cli_options() -> None: + parser = build_parser() + args = parser.parse_args( + [ + "scan", + "https://example.com", + "--export", + "json", + "html", + "--timeout", + "45", + "--headed", + ] + ) + assert args.export == ["json", "html"] + assert args.timeout == 45 + assert args.headed is True