Self-hosted, Docker-based agentic troubleshooting platform: FastAPI backend + LangGraph agent, Next.js UI, tiered LLM routing (local Ollama -> Gemini -> DeepSeek -> OpenRouter), MCP server manager, encrypted device credentials, RBAC, audit log, project-memory + Obsidian integrations, and editable troubleshooting decision rules tuned for the GeneseasX vessel stack. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
"""Tests for device default credentials from env."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-unit-tests-only")
|
|
os.environ["DEVICE_SSH_USERNAME"] = "shipadmin"
|
|
os.environ["DEVICE_SSH_PASSWORD"] = "ssh-secret"
|
|
os.environ["DEVICE_PFSENSE_PORT"] = "40443"
|
|
os.environ["DEVICE_PFSENSE_API_KEY"] = "pf-key-123"
|
|
os.environ["DEVICE_PROXMOX_PASSWORD"] = "pve-pass"
|
|
os.environ["DEVICE_PROXMOX_TOKEN_ID"] = "root@pam!agentic"
|
|
os.environ["DEVICE_PROXMOX_TOKEN_SECRET"] = "token-uuid"
|
|
|
|
from app.inventory_catalog import catalog_by_key # noqa: E402
|
|
from app.services.device_defaults import ( # noqa: E402
|
|
merge_selection_with_defaults,
|
|
proxmox_api_configured,
|
|
resolve_proxmox_api_defaults,
|
|
resolve_slot_defaults,
|
|
)
|
|
|
|
|
|
def test_ssh_slot_uses_global_fallback():
|
|
entry = catalog_by_key()["docker_vm"]
|
|
d = resolve_slot_defaults("docker_vm", entry)
|
|
assert d.username == "shipadmin"
|
|
assert d.secret == "ssh-secret"
|
|
assert d.secret_kind == "password"
|
|
|
|
|
|
def test_per_slot_overrides_global():
|
|
entry = catalog_by_key()["proxmox"]
|
|
d = resolve_slot_defaults("proxmox", entry)
|
|
assert d.secret == "pve-pass"
|
|
assert d.username == "shipadmin"
|
|
|
|
|
|
def test_api_key_slot():
|
|
entry = catalog_by_key()["pfsense"]
|
|
d = resolve_slot_defaults("pfsense", entry)
|
|
assert d.port == 40443
|
|
assert d.secret == "pf-key-123"
|
|
assert d.secret_kind == "api_key"
|
|
|
|
|
|
def test_merge_applies_env_when_blank():
|
|
entry = catalog_by_key()["pfsense"]
|
|
port, user, secret = merge_selection_with_defaults(
|
|
"pfsense", entry, port=None, username=None, secret=None
|
|
)
|
|
assert port == 40443
|
|
assert secret == "pf-key-123"
|
|
|
|
|
|
def test_proxmox_api_env():
|
|
api = resolve_proxmox_api_defaults("10.1.2.3")
|
|
assert api["proxmox_token_id"] == "root@pam!agentic"
|
|
assert api["proxmox_token_secret"] == "token-uuid"
|
|
assert proxmox_api_configured(api)
|
|
|
|
|
|
def test_merge_ui_override_wins():
|
|
entry = catalog_by_key()["pfsense"]
|
|
_, _, secret = merge_selection_with_defaults(
|
|
"pfsense", entry, port=8443, username="admin", secret="custom-key"
|
|
)
|
|
assert secret == "custom-key"
|