refactor(web): elimina ruta moarta /cont/rar-creds
Ruta web POST /cont/rar-creds era cod mort: niciun template nu mai posta catre ea (formularul live e /cont/rar-medii, US-008/PRD 5.20 cu sectiuni explicite Testare+Productie si validare login per-env). Scria mereu in slotul env-ului instantei — exact bug-ul semnalat la Issue A. Elimina functia cont_rar_creds si cele doua teste care o exercitau (test_set_creds_rar_din_sesiune, test_creds_alt_cont_neafectat). Actualizeaza comentariul stale US-008 sa refere ruta reala /cont/rar-medii. Ruta API /v1/conturi/rar-creds e separata si ramane neatinsa. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4201,11 +4201,10 @@ async def web_confirma_import(
|
||||
#
|
||||
# Puncte de validare existente:
|
||||
# - /cont/test-rar-creds (testeaza integrarea RAR, fara efecte secundare)
|
||||
# - /cont/rar-medii (US-008): salvare creds per-mediu, valideaza login pe env-ul propriu
|
||||
# Puncte non-aplicabile (nu colecteaza/valideaza creds RAR):
|
||||
# - signup (/signup): nu colecteaza credentiale RAR — creare cont platforma, nu RAR
|
||||
# - preview import: nu valideaza credentiale RAR
|
||||
# Puncte viitoare (US-008):
|
||||
# - /cont/rar-creds la salvare creds per-mediu (va apela _valideaza_login_rar)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -4590,60 +4589,6 @@ def integrare_test_cheie(
|
||||
)
|
||||
|
||||
|
||||
@router.post("/cont/rar-creds", response_class=HTMLResponse)
|
||||
def cont_rar_creds(
|
||||
request: Request,
|
||||
rar_email: str = Form(""),
|
||||
rar_parola: str = Form(""),
|
||||
csrf_token: str | None = Form(None),
|
||||
) -> HTMLResponse:
|
||||
"""Seteaza creds RAR per cont din sesiune (ruta web proprie).
|
||||
|
||||
Camp parola NICIODATA re-pus in value= la re-randare.
|
||||
Validare minima: email si parola negoale.
|
||||
"""
|
||||
account_id = require_login(request)
|
||||
verify_csrf(request, csrf_token)
|
||||
acct = account_or_default(account_id)
|
||||
|
||||
email = rar_email.strip()
|
||||
parola = rar_parola.strip()
|
||||
|
||||
if not email or not parola:
|
||||
conn = get_connection()
|
||||
try:
|
||||
account_meta = _fetch_account_meta(conn, acct)
|
||||
env_ctx = _fetch_cont_env_state(conn, acct)
|
||||
finally:
|
||||
conn.close()
|
||||
return _render_cont(
|
||||
request,
|
||||
creds_eroare="Email si parola sunt obligatorii.",
|
||||
account_meta=account_meta,
|
||||
**env_ctx,
|
||||
)
|
||||
|
||||
enc = encrypt_creds({"email": email, "password": parola})
|
||||
# US-013: scrie in slotul per-env al ancorei globale (nu mai exista coloana legacy).
|
||||
_env_w = get_settings().rar_env if get_settings().rar_env in ("test", "prod") else "test"
|
||||
conn = get_connection()
|
||||
try:
|
||||
conn.execute(
|
||||
f"UPDATE accounts SET rar_creds_{_env_w}_enc=?, rar_{_env_w}_enabled=1 WHERE id=?",
|
||||
(enc, acct),
|
||||
)
|
||||
account_meta = _fetch_account_meta(conn, acct)
|
||||
env_ctx = _fetch_cont_env_state(conn, acct)
|
||||
return _render_cont(
|
||||
request,
|
||||
creds_mesaj="Credentialele RAR au fost salvate cu succes.",
|
||||
account_meta=account_meta,
|
||||
**env_ctx,
|
||||
)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
@router.post("/cont/test-rar-creds", response_class=HTMLResponse)
|
||||
def cont_test_rar_creds(
|
||||
request: Request,
|
||||
|
||||
@@ -6,7 +6,6 @@ dupa implementare trec (GREEN).
|
||||
Rute testate:
|
||||
- GET /_fragments/cont -> card "Contul meu"
|
||||
- POST /cont/roteste-cheie -> cheie noua afisata o singura data
|
||||
- POST /cont/rar-creds -> seteaza rar_creds_enc per cont din sesiune
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -126,83 +125,6 @@ def test_roteste_cheie_afisata_o_data(client):
|
||||
conn.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_set_creds_rar_din_sesiune
|
||||
# ============================================================
|
||||
|
||||
def test_set_creds_rar_din_sesiune(client):
|
||||
"""User logat seteaza creds RAR: slotul per-env (US-013) != NULL, decriptabil."""
|
||||
acct_id, user_id, _ = _create_account_user("creds@test.com")
|
||||
_login(client, "creds@test.com", "parolasecreta10")
|
||||
|
||||
csrf = _get_csrf_from_fragment(client)
|
||||
resp = client.post("/cont/rar-creds", data={
|
||||
"csrf_token": csrf,
|
||||
"rar_email": "user@rar.ro",
|
||||
"rar_parola": "parolaRAR123",
|
||||
})
|
||||
|
||||
assert resp.status_code == 200
|
||||
# Mesaj de succes in raspuns
|
||||
assert "succes" in resp.text.lower() or "salvat" in resp.text.lower() or "configurat" in resp.text.lower(), \
|
||||
f"Mesaj de succes lipsa: {resp.text[:500]}"
|
||||
|
||||
# Verifica in DB: slotul per-env setat si decriptabil (US-013: rar_creds_enc legacy dropata)
|
||||
from app.db import get_connection
|
||||
from app.crypto import decrypt_creds
|
||||
conn = get_connection()
|
||||
try:
|
||||
row = conn.execute(
|
||||
"SELECT rar_creds_test_enc, rar_creds_prod_enc FROM accounts WHERE id=?", (acct_id,)
|
||||
).fetchone()
|
||||
assert row is not None
|
||||
enc = row["rar_creds_test_enc"] or row["rar_creds_prod_enc"]
|
||||
assert enc is not None, "Cel putin un slot per-env trebuia setat (US-013)"
|
||||
creds = decrypt_creds(enc)
|
||||
assert creds is not None
|
||||
assert creds.get("email") == "user@rar.ro"
|
||||
assert creds.get("password") == "parolaRAR123"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_creds_alt_cont_neafectat
|
||||
# ============================================================
|
||||
|
||||
def test_creds_alt_cont_neafectat(client):
|
||||
"""User A seteaza creds -> contul B ramane fara creds (sloturi per-env NULL, US-013)."""
|
||||
acct_a, user_a, _ = _create_account_user("userA@test.com")
|
||||
acct_b, user_b, _ = _create_account_user("userB@test.com")
|
||||
|
||||
# Logam user A si setam creds
|
||||
_login(client, "userA@test.com", "parolasecreta10")
|
||||
csrf = _get_csrf_from_fragment(client)
|
||||
resp = client.post("/cont/rar-creds", data={
|
||||
"csrf_token": csrf,
|
||||
"rar_email": "a@rar.ro",
|
||||
"rar_parola": "parolaA123",
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
|
||||
# Verifica: contul A are creds in slotul per-env, contul B ramane NULL (US-013)
|
||||
from app.db import get_connection
|
||||
conn = get_connection()
|
||||
try:
|
||||
row_a = conn.execute(
|
||||
"SELECT rar_creds_test_enc, rar_creds_prod_enc FROM accounts WHERE id=?", (acct_a,)
|
||||
).fetchone()
|
||||
row_b = conn.execute(
|
||||
"SELECT rar_creds_test_enc, rar_creds_prod_enc FROM accounts WHERE id=?", (acct_b,)
|
||||
).fetchone()
|
||||
enc_a = row_a["rar_creds_test_enc"] or row_a["rar_creds_prod_enc"]
|
||||
enc_b = row_b["rar_creds_test_enc"] or row_b["rar_creds_prod_enc"]
|
||||
assert enc_a is not None, "Contul A trebuia sa aiba creds in slotul per-env"
|
||||
assert enc_b is None, "Contul B nu trebuia atins"
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# test_roteste_fara_csrf_403_in_prod
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user