fix(jira,tests): send real datetime to RT/BT date fields, resolve assignee usernames for operators
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
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
- RT/BT Start/End Date are genuine Jira "datetime" custom fields (confirmed via issue_editmeta), not plain dates. Pushing a bare "YYYY-MM-DD" string made Jira default the time-of-day to midnight, so RT Start Date and RT End Date ended up showing the same meaningless midnight timestamp instead of the actual execution window. Now sends a full ISO datetime. - The test detail page showed "RT: Unassigned" for the operator who WAS correctly assigned, because GET /users/operators (the only source AssigneeControl used to resolve an assignee ID into a username) is restricted to leads/managers — a plain operator has no other way to resolve their own ID. TestOut now resolves and includes the assignee's username directly (red/blue tech + reviewer), so the badge no longer depends on a permission-gated list the viewer might not have access to.
This commit is contained in:
@@ -1202,6 +1202,20 @@ def _select_field(value: str) -> dict:
|
||||
return {"value": value}
|
||||
|
||||
|
||||
def _jira_datetime(dt: datetime) -> str:
|
||||
"""Format a naive-UTC datetime for a Jira ``datetime``-type custom field.
|
||||
|
||||
RT/BT Start/End Date are genuine Jira datetime fields (confirmed via
|
||||
issue_editmeta — schema type "datetime"), not plain dates. Sending a
|
||||
bare "YYYY-MM-DD" string makes Jira default the time-of-day to
|
||||
midnight, so RT Start Date and RT End Date ended up showing the same
|
||||
meaningless midnight timestamp regardless of when the operator
|
||||
actually started/finished. Jira's REST API expects
|
||||
``yyyy-MM-dd'T'HH:mm:ss.SSSZ`` for this field type.
|
||||
"""
|
||||
return dt.strftime("%Y-%m-%dT%H:%M:%S.000+0000")
|
||||
|
||||
|
||||
def _compute_hours(start: Optional[datetime], end: Optional[datetime]) -> Optional[float]:
|
||||
"""Return the elapsed time between two timestamps in hours, or None if unavailable."""
|
||||
if not start or not end:
|
||||
@@ -1272,10 +1286,10 @@ def push_rt_submitted(db: Session, test: Test) -> None:
|
||||
else test.execution_start_time
|
||||
)
|
||||
if first_start:
|
||||
fields[JIRA_FIELD_RT_START_DATE] = first_start.strftime("%Y-%m-%d")
|
||||
fields[JIRA_FIELD_RT_START_DATE] = _jira_datetime(first_start)
|
||||
|
||||
if test.execution_end_time:
|
||||
fields[JIRA_FIELD_RT_END_DATE] = test.execution_end_time.strftime("%Y-%m-%d")
|
||||
fields[JIRA_FIELD_RT_END_DATE] = _jira_datetime(test.execution_end_time)
|
||||
|
||||
attack_success = _enum_value(test.attack_success)
|
||||
if attack_success in _ATTACK_SUCCESS_TO_JIRA:
|
||||
@@ -1287,13 +1301,13 @@ def push_rt_submitted(db: Session, test: Test) -> None:
|
||||
def push_bt_started(db: Session, test: Test) -> None:
|
||||
"""Set the BT Start Date field — called when Blue picks up the test to evaluate."""
|
||||
_update_test_fields(db, test, {
|
||||
JIRA_FIELD_BT_START_DATE: datetime.utcnow().strftime("%Y-%m-%d"),
|
||||
JIRA_FIELD_BT_START_DATE: _jira_datetime(datetime.utcnow()),
|
||||
})
|
||||
|
||||
|
||||
def push_bt_submitted(db: Session, test: Test) -> None:
|
||||
"""Set BT End Date, Attack Detected/Contained, and time-to-detect/contain — Blue submits for review."""
|
||||
fields: dict = {JIRA_FIELD_BT_END_DATE: datetime.utcnow().strftime("%Y-%m-%d")}
|
||||
fields: dict = {JIRA_FIELD_BT_END_DATE: _jira_datetime(datetime.utcnow())}
|
||||
|
||||
detection_result = _enum_value(test.detection_result)
|
||||
if detection_result in _DETECTION_TO_JIRA:
|
||||
|
||||
Reference in New Issue
Block a user