From 54e509400245ca5adb3e92b4e9b796e3f79cc92b Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 10 Dec 2024 09:50:58 +0100 Subject: [PATCH] users: Fix truncated "From" in account logs Call `last` with `--fullnames` to avoid truncating values (like IPv6 addresses). We don't rely on a "nicely" (argh) formatted ASCII table with fixed column widths, but parse the structure. Flesh out TestAccounts.testAccountLogs to actually test some values on the page. It was almost empty before. Like in the previous commit, we can afford to hardcode the expected IPv6 "from" address. Fixes #21383 --- pkg/users/account-logs-panel.jsx | 2 +- test/verify/check-users | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/users/account-logs-panel.jsx b/pkg/users/account-logs-panel.jsx index 3534046134b8..8c60e13a5aa6 100644 --- a/pkg/users/account-logs-panel.jsx +++ b/pkg/users/account-logs-panel.jsx @@ -31,7 +31,7 @@ const _ = cockpit.gettext; export function AccountLogs({ name }) { const [logins, setLogins] = useState([]); useInit(() => { - cockpit.spawn(["last", "--time-format", "iso", "-n25", name], { environ: ["LC_ALL=C"] }) + cockpit.spawn(["last", "--time-format", "iso", "-n25", "--fullnames", name], { environ: ["LC_ALL=C"] }) .then(data => { let logins = []; data.split('\n').forEach(line => { diff --git a/test/verify/check-users b/test/verify/check-users index ed177402f8d7..bcf12c817ca6 100755 --- a/test/verify/check-users +++ b/test/verify/check-users @@ -1079,14 +1079,26 @@ class TestAccounts(testlib.MachineCase): m.execute("truncate -s0 /var/log/{[bw]tmp,lastlog} /run/utmp") m.execute("rm -f /var/lib/lastlog/lastlog2.db /var/lib/wtmpdb/wtmp.db") - # Login once to create an entry - self.login_and_go("/users") + # First login: no entries yet + self.login_and_go("/users#/admin") + # just the header, nothing else + b.wait_text("#account-logs", "Login history") + self.assertFalse(b.is_present("#account-logs tr")) b.logout() + year = m.execute("date +%Y").strip() + + # second login: one entry from the first one self.login_and_go("/users#/admin") - b.wait_visible("#account-logs") # Header + one line of logins b.wait_js_func("ph_count_check", "#account-logs tr", 2) + started = b.text("#account-logs [data-label='Started']") + ended = b.text("#account-logs [data-label='Ended']") + self.assertIn(year, started) + self.assertIn(year, ended) + self.assertGreaterEqual(ended, started) + # this is the correct IP for our CI, and we don't run this on tmt + b.wait_text("#account-logs [data-label='From']", "::ffff:172.27.0.2") def testGroups(self): b = self.browser