kin: KIN-095 При добавлении в среды серверов вылетает ошибка 500 Internal Server Error в модалке
This commit is contained in:
parent
8ebc6f1111
commit
1bf0125991
3 changed files with 66 additions and 1 deletions
|
|
@ -51,6 +51,18 @@ def scan_client(tmp_path):
|
|||
return c, env_id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def env_client(tmp_path):
|
||||
"""TestClient with just a project pre-created. Returns client."""
|
||||
import web.api as api_module
|
||||
api_module.DB_PATH = tmp_path / "env_biz007.db"
|
||||
from web.api import app
|
||||
from fastapi.testclient import TestClient
|
||||
c = TestClient(app)
|
||||
c.post("/api/projects", json={"id": "envproj", "name": "Env Project", "path": "/env"})
|
||||
return c
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# AC1: Roundtrip — _encrypt_auth → _decrypt_auth returns original string
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -325,3 +337,52 @@ def test_deobfuscate_auth_not_imported_in_web_api():
|
|||
assert not hasattr(api_mod, "_deobfuscate_auth"), (
|
||||
"_deobfuscate_auth must not appear in web.api"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# AC6 (KIN-095): ModuleNotFoundError for cryptography → 503, not 500
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_create_environment_returns_503_when_cryptography_not_installed(env_client):
|
||||
"""AC6: POST /environments returns 503 when cryptography package missing (not 500)."""
|
||||
client = env_client
|
||||
with patch("core.models._encrypt_auth", side_effect=ModuleNotFoundError("No module named 'cryptography'")):
|
||||
r = client.post("/api/projects/envproj/environments", json={
|
||||
"name": "creds-env", "host": "10.0.0.20", "username": "root",
|
||||
"auth_type": "password", "auth_value": "secret",
|
||||
})
|
||||
assert r.status_code == 503, (
|
||||
f"create_environment must return 503 when cryptography is missing, got {r.status_code}: {r.text}"
|
||||
)
|
||||
assert "cryptography" in r.json()["detail"].lower()
|
||||
|
||||
|
||||
def test_create_environment_returns_503_not_500_for_missing_cryptography(env_client):
|
||||
"""AC6: 500 must NOT be returned when cryptography package is absent."""
|
||||
client = env_client
|
||||
with patch("core.models._encrypt_auth", side_effect=ModuleNotFoundError("No module named 'cryptography'")):
|
||||
r = client.post("/api/projects/envproj/environments", json={
|
||||
"name": "creds-env2", "host": "10.0.0.21", "username": "root",
|
||||
"auth_value": "secret2",
|
||||
})
|
||||
assert r.status_code != 500, "Missing cryptography must produce 503, not 500"
|
||||
|
||||
|
||||
def test_patch_environment_returns_503_when_cryptography_not_installed(env_client):
|
||||
"""AC6: PATCH /environments/{id} returns 503 when cryptography package missing."""
|
||||
client = env_client
|
||||
# Create env without auth_value so no encryption at create time
|
||||
r = client.post("/api/projects/envproj/environments", json={
|
||||
"name": "patch-env", "host": "10.0.0.22", "username": "root",
|
||||
})
|
||||
assert r.status_code == 201, f"Setup failed: {r.text}"
|
||||
env_id = r.json()["id"]
|
||||
|
||||
with patch("core.models._encrypt_auth", side_effect=ModuleNotFoundError("No module named 'cryptography'")):
|
||||
r = client.patch(f"/api/projects/envproj/environments/{env_id}", json={
|
||||
"auth_value": "new_secret",
|
||||
})
|
||||
assert r.status_code == 503, (
|
||||
f"patch_environment must return 503 when cryptography is missing, got {r.status_code}: {r.text}"
|
||||
)
|
||||
assert "cryptography" in r.json()["detail"].lower()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue