fix(backend): loginctl JSON parse and filter ephemeral SSH sessions (0.20.34)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
from app.services.host_sessions import (
|
||||
event_supports_session_terminate,
|
||||
filter_logind_session_rows,
|
||||
parse_loginctl_sessions,
|
||||
parse_loginctl_sessions_json,
|
||||
parse_qwinsta_sessions,
|
||||
)
|
||||
|
||||
@@ -16,18 +18,37 @@ def test_parse_loginctl_sessions():
|
||||
assert rows[0].tty == "pts/0"
|
||||
|
||||
|
||||
def test_parse_loginctl_sessions_ignores_motd_noise():
|
||||
stdout = """This server is powered by FASTPANEL
|
||||
Ubuntu Operating LTS
|
||||
configuration By can be not
|
||||
11090 1000 papatramp - - active -
|
||||
11102 1000 papatramp - - active -
|
||||
def test_parse_loginctl_sessions_prefers_pts_over_ephemeral_duplicate():
|
||||
stdout = """21166 1000 papatramp - pts/0 active no -
|
||||
21169 1000 papatramp - - active no -
|
||||
"""
|
||||
rows = parse_loginctl_sessions(stdout)
|
||||
assert len(rows) == 1
|
||||
assert rows[0].session_id == "21166"
|
||||
assert rows[0].tty == "pts/0"
|
||||
|
||||
|
||||
def test_parse_loginctl_sessions_json():
|
||||
stdout = """[
|
||||
{"session":"21166","uid":1000,"user":"papatramp","seat":null,"tty":"pts/0","state":"active","idle":false,"since":null},
|
||||
{"session":"21169","uid":1000,"user":"papatramp","seat":null,"tty":null,"state":"active","idle":false,"since":null}
|
||||
]"""
|
||||
rows = parse_loginctl_sessions_json(stdout)
|
||||
assert len(rows) == 1
|
||||
assert rows[0].session_id == "21166"
|
||||
assert rows[0].tty == "pts/0"
|
||||
|
||||
|
||||
def test_filter_logind_session_rows_keeps_distinct_users():
|
||||
from app.services.host_sessions import HostSessionRow
|
||||
|
||||
rows = filter_logind_session_rows(
|
||||
[
|
||||
HostSessionRow(session_id="1", user="alice", tty="pts/0", state="active"),
|
||||
HostSessionRow(session_id="2", user="bob", tty=None, state="active"),
|
||||
]
|
||||
)
|
||||
assert len(rows) == 2
|
||||
assert rows[0].session_id == "11090"
|
||||
assert rows[1].session_id == "11102"
|
||||
assert all(row.user == "papatramp" for row in rows)
|
||||
|
||||
|
||||
def test_parse_qwinsta_sessions_filters_user():
|
||||
|
||||
Reference in New Issue
Block a user