fix(jira): report which admin config field is actually missing
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled

POST /system/jira-test bundled 4 independent checks (enabled, url,
admin_email, admin_api_token) behind has_admin_jira_configured() but
always blamed "Admin Email and Admin API Token" regardless of which one
failed. Found via live QA: URL/email/token were all correctly saved, but
the "Enable Jira Integration" toggle was never switched on — the error
message pointed at the wrong fields, making it look like the already-set
credentials were missing.
This commit is contained in:
kitos
2026-07-09 12:02:04 +02:00
parent 4ddd7f9ec3
commit adae7e617e
2 changed files with 68 additions and 5 deletions
+14 -5
View File
@@ -354,7 +354,7 @@ def test_jira_connection(
"""
from app.services.jira_service import (
get_admin_jira_client, get_jira_url, has_admin_jira_configured,
get_admin_jira_email,
get_admin_jira_email, get_admin_jira_api_token, is_jira_enabled,
)
jira_url = get_jira_url(db)
@@ -362,12 +362,21 @@ def test_jira_connection(
return {"status": "error", "message": "Jira URL is not configured.", "jira_url": ""}
if not has_admin_jira_configured(db):
# has_admin_jira_configured() bundles 4 independent checks into one
# bool — report exactly which one(s) are actually missing instead of
# always blaming "Admin Email and Admin API Token" regardless of
# which check failed (e.g. URL/email/token can all be set while the
# "Enable Jira Integration" toggle itself is still off).
missing = []
if not is_jira_enabled(db):
missing.append("Jira integration is not enabled (toggle 'Enable Jira Integration' above)")
if not get_admin_jira_email(db):
missing.append("Admin Email is not set")
if not get_admin_jira_api_token(db):
missing.append("Admin API Token is not set")
return {
"status": "error",
"message": (
"Admin Jira credentials not configured. "
"Set the Admin Email and Admin API Token in the fields above."
),
"message": "Cannot connect: " + "; ".join(missing) + ".",
"jira_url": jira_url,
}
@@ -0,0 +1,54 @@
"""Tests for POST /system/jira-test's diagnostic message.
Regression coverage for a real QA-reported bug: has_admin_jira_configured()
bundles four independent checks (enabled, url, admin_email, admin_api_token)
into one bool, but the error message always blamed "Admin Email and Admin
API Token" regardless of which check actually failed. An admin who had set
url/email/token correctly but never flipped the "Enable Jira Integration"
toggle saw a misleading message pointing at the wrong fields.
"""
from app.models.system_config import SystemConfig
def _set_config(db, key, value):
db.add(SystemConfig(key=key, value=value))
def test_jira_test_reports_disabled_toggle_specifically(client, db, auth_headers):
"""url/email/token all set, but jira.enabled is missing entirely —
the message must call out the toggle, not email/token."""
_set_config(db, "jira.url", "https://example.atlassian.net")
_set_config(db, "jira.admin_email", "admin@example.com")
_set_config(db, "jira.admin_api_token", "some-real-token")
db.commit()
resp = client.post("/api/v1/system/jira-test", headers=auth_headers)
assert resp.status_code == 200
body = resp.json()
assert body["status"] == "error"
assert "not enabled" in body["message"]
assert "Admin Email" not in body["message"]
assert "Admin API Token" not in body["message"]
def test_jira_test_reports_missing_email_and_token_when_actually_missing(client, db, auth_headers):
_set_config(db, "jira.url", "https://example.atlassian.net")
_set_config(db, "jira.enabled", "true")
db.commit()
resp = client.post("/api/v1/system/jira-test", headers=auth_headers)
assert resp.status_code == 200
body = resp.json()
assert body["status"] == "error"
assert "Admin Email is not set" in body["message"]
assert "Admin API Token is not set" in body["message"]
assert "not enabled" not in body["message"]
def test_jira_test_missing_url_reports_url_specifically(client, db, auth_headers):
resp = client.post("/api/v1/system/jira-test", headers=auth_headers)
assert resp.status_code == 200
body = resp.json()
assert body["status"] == "error"
assert "Jira URL is not configured" in body["message"]