"""Mobile browser identity — run: python tests/test_mobile_browsers.py

Android browsers ship the same engine, version numbers and security fixes as
their desktop builds, so they resolve to the same CPE. iOS builds do NOT:
Apple mandates WebKit, so the Blink and Gecko CVEs behind these ranges do not
apply there at all.
"""
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.services.app_cve_scanner_service import resolve_product


def _key(name):
    return (resolve_product(name) or {}).get("key")


def demo():
    # Android package ids resolve to the desktop product.
    assert _key("org.mozilla.firefox") == "cpe:mozilla:firefox"
    assert _key("org.mozilla.firefox_beta") == "cpe:mozilla:firefox"
    assert _key("com.android.chrome") == "cpe:google:chrome"

    # iOS builds are WebKit-backed — neither engine's CVEs apply.
    assert _key("org.mozilla.ios.Firefox") is None
    assert _key("Firefox for iOS") is None

    # Desktop unchanged.
    assert _key("Mozilla Firefox") == "cpe:mozilla:firefox"
    # ESR stays excluded on purpose: NVD tracks it as its own firefox_esr CPE,
    # so the plain firefox ranges would flag CVEs that have no ESR fix.
    assert _key("Mozilla Firefox ESR") is None

    print("mobile browsers OK")


if __name__ == "__main__":
    demo()
