"""Проверка вердиктов по зоне Kaspersky для URL и хешей."""

from ioc_checker.iocs.analysis import IndicatorVerdict
from ioc_checker.iocs.hash import create_hash_indicator
from ioc_checker.iocs.url import URLIndicator


def test_url_blocked_when_kaspersky_zone_not_green():
    indicator = URLIndicator(value="http://example.com", kinds=frozenset())

    verdict = indicator.analysis({"kaspersky": {"kasp_zone": "Red"}})

    assert verdict["verdicts"] == [IndicatorVerdict.BLOCK, IndicatorVerdict.MONITOR]
    assert {reason["text"] for reason in verdict["reasons"]} == {"Зона Kaspersky не Green"}


def test_url_ignored_when_kaspersky_zone_green():
    indicator = URLIndicator(value="http://example.com", kinds=frozenset())

    verdict = indicator.analysis({"kaspersky": {"kasp_zone": "Green"}})

    assert verdict["verdicts"] == [IndicatorVerdict.IGNORE]
    assert verdict["reasons"] == [{"text": "Зона Kaspersky Green"}]


def test_hash_blocked_when_kaspersky_zone_not_green():
    indicator = create_hash_indicator(value="0" * 32, kinds=frozenset(), algorithm="md5")

    verdict = indicator.analysis({"kaspersky": {"kasp_zone": "Red"}})

    assert verdict["verdicts"] == [IndicatorVerdict.BLOCK, IndicatorVerdict.MONITOR]
    assert {reason["text"] for reason in verdict["reasons"]} == {"Зона Kaspersky не Green"}


def test_hash_ignored_when_kaspersky_zone_green():
    indicator = create_hash_indicator(value="0" * 40, kinds=frozenset(), algorithm="sha1")

    verdict = indicator.analysis({"kaspersky": {"kasp_zone": "Green"}})

    assert verdict["verdicts"] == [IndicatorVerdict.IGNORE]
    assert verdict["reasons"] == [{"text": "Зона Kaspersky Green"}]
