Skip to content

Commit

Permalink
users: Fix truncated "From" in account logs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinpitt authored and jelly committed Dec 10, 2024
1 parent a906a89 commit 54e5094
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/users/account-logs-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
18 changes: 15 additions & 3 deletions test/verify/check-users
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54e5094

Please sign in to comment.