Files
DECNET/tests/intel/test_factory.py
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

59 lines
2.0 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Tests for the intel provider factory.
The factory returns a **list** of configured providers (not a singleton
like :mod:`decnet.geoip.factory`). Coverage:
* disabled master switch returns ``[]``
* empty provider list returns ``[]``
* unknown provider name raises ``ValueError`` (typo guard)
* trimming + case-insensitivity of the providers env var
"""
from __future__ import annotations
import pytest
from decnet.intel.factory import get_intel_providers
@pytest.fixture(autouse=True)
def _isolate_env(monkeypatch):
# Disable real providers — concrete impls land in later commits, but
# the factory tests should pass against whatever subset exists today
# via empty/unknown lists.
for key in (
"DECNET_INTEL_ENABLED",
"DECNET_INTEL_PROVIDERS",
"DECNET_GREYNOISE_API_KEY",
"DECNET_ABUSEIPDB_API_KEY",
"DECNET_THREATFOX_API_KEY",
):
monkeypatch.delenv(key, raising=False)
def test_disabled_returns_empty(monkeypatch):
monkeypatch.setenv("DECNET_INTEL_ENABLED", "false")
monkeypatch.setenv("DECNET_INTEL_PROVIDERS", "greynoise")
assert get_intel_providers() == []
def test_empty_provider_list_returns_empty(monkeypatch):
monkeypatch.setenv("DECNET_INTEL_PROVIDERS", "")
assert get_intel_providers() == []
def test_unknown_provider_name_raises(monkeypatch):
monkeypatch.setenv("DECNET_INTEL_PROVIDERS", "definitely-not-real")
with pytest.raises(ValueError, match="Unknown intel provider"):
get_intel_providers()
def test_whitespace_and_case_normalised(monkeypatch):
# The factory imports concrete provider modules lazily; this test only
# asserts that case+whitespace normalization doesn't trip the lookup.
# We use an unknown name (which would also be unknown if not lowercased)
# to exercise the path without requiring provider impls to exist yet.
monkeypatch.setenv("DECNET_INTEL_PROVIDERS", " Mystery , ")
with pytest.raises(ValueError, match="mystery"):
get_intel_providers()