File: test_cli_helpers.py

package info (click to toggle)
knockpy 9.0.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 560 kB
  • sloc: python: 6,435; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations

from pathlib import Path

from knockpy.cli import _load_domains_from_file, _normalize_domain_input, _normalize_domain_list, _should_save_scan


def test_load_domains_from_file_strips_empty_lines(tmp_path: Path):
    source = tmp_path / "domains.txt"
    source.write_text("\nexample.com\n\nwww.test.org\n", encoding="utf-8")
    assert _load_domains_from_file(str(source)) == ["example.com", "www.test.org"]


def test_normalize_domain_input_accepts_url_and_plain_domain():
    assert _normalize_domain_input("https://www.Example.com/path?q=1") == "example.com"
    assert _normalize_domain_input("sub.example.com") == "sub.example.com"
    assert _normalize_domain_input("not a domain") is None


def test_normalize_domain_list_deduplicates_and_filters_invalid():
    values = [
        "https://www.example.com",
        "example.com",
        "sub.example.com",
        "bad domain",
        "",
    ]
    assert _normalize_domain_list(values) == ["example.com", "sub.example.com"]


def test_should_save_scan_only_for_recon_or_bruteforce():
    assert _should_save_scan(recon=False, bruteforce=False) is False
    assert _should_save_scan(recon=True, bruteforce=False) is True
    assert _should_save_scan(recon=False, bruteforce=True) is True