from pathlib import Path from scripts.scrape_fsbp import parse_fsbp_index _FIXTURES = Path(__file__).parent / "fixtures" def test_parses_fsbp_index_rows(): html = (_FIXTURES / "fsbp_index_sample.html").read_text() rows = parse_fsbp_index(html, base_url="https://docs.aws.amazon.com") by_id = {r.control_id: r for r in rows} assert "S3.5" in by_id assert by_id["S3.5"].title == "S3 general purpose buckets should require requests to use SSL" assert by_id["S3.5"].severity == "medium" assert by_id["S3.5"].detail_url.endswith("s3-controls.html#s3-5") assert "IAM.5" in by_id assert "Account.1" in by_id def test_resource_types_attached_via_prefix_map(): html = (_FIXTURES / "fsbp_index_sample.html").read_text() rows = parse_fsbp_index(html, base_url="https://docs.aws.amazon.com") by_id = {r.control_id: r for r in rows} assert "aws_s3_bucket" in by_id["S3.5"].resource_types assert "aws_iam_user" in by_id["IAM.5"].resource_types assert "aws_account_alternate_contact" in by_id["Account.1"].resource_types def test_dedups_repeat_control_ids(): """A control linked multiple times on the page should appear once.""" html = """\
""" rows = parse_fsbp_index(html, base_url="https://docs.aws.amazon.com") assert len([r for r in rows if r.control_id == "S3.1"]) == 1