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.
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Coverage for the persona-aware path resolver + placement validator."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from decnet.canary.paths import (
|
|
DEFAULT_LINUX_USER,
|
|
DEFAULT_WINDOWS_USER,
|
|
default_path_for,
|
|
default_user,
|
|
normalize_placement,
|
|
)
|
|
|
|
|
|
def test_default_user_dispatch() -> None:
|
|
assert default_user("linux") == DEFAULT_LINUX_USER
|
|
assert default_user("windows") == DEFAULT_WINDOWS_USER
|
|
# Unknown personas fall through to Linux — better to plant than fail.
|
|
assert default_user("aix") == DEFAULT_LINUX_USER
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"generator, persona, expected_substr",
|
|
[
|
|
("aws_creds", "linux", "/home/admin/.aws/credentials"),
|
|
("aws_creds", "windows", "/home/Administrator/.aws/credentials"),
|
|
("env_file", "linux", "/home/admin/.env"),
|
|
("env_file", "windows", "/home/Administrator/Desktop/prod.env"),
|
|
("git_config", "linux", "/home/admin/.git/config"),
|
|
("ssh_key", "linux", "/home/admin/.ssh/id_rsa"),
|
|
("honeydoc", "linux", "/home/admin/Documents/quarterly_report.html"),
|
|
("honeydoc_docx", "linux", "/home/admin/Documents/quarterly_report.docx"),
|
|
("honeydoc_pdf", "linux", "/home/admin/Documents/quarterly_report.pdf"),
|
|
],
|
|
)
|
|
def test_default_path_for_known_generators(
|
|
generator: str, persona: str, expected_substr: str,
|
|
) -> None:
|
|
assert default_path_for(generator, persona) == expected_substr
|
|
|
|
|
|
def test_default_path_for_unknown_generator_falls_through() -> None:
|
|
# Unknown generator — defensive /tmp drop. The API rejects unknowns
|
|
# upstream, but the resolver shouldn't crash if one slips through.
|
|
assert default_path_for("bogus") == "/tmp/bogus.canary"
|
|
|
|
|
|
def test_normalize_placement_accepts_clean_paths() -> None:
|
|
assert normalize_placement("/home/admin/.env") == "/home/admin/.env"
|
|
assert normalize_placement("/var/lib/x") == "/var/lib/x"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"bad",
|
|
[
|
|
"",
|
|
"relative/path",
|
|
"./still-relative",
|
|
"/path/with\x00nul",
|
|
"/path/with\nnewline",
|
|
"/path/with\rcr",
|
|
"/path/../escape",
|
|
"/trailing/..",
|
|
],
|
|
)
|
|
def test_normalize_placement_rejects_bad(bad: str) -> None:
|
|
with pytest.raises(ValueError):
|
|
normalize_placement(bad)
|