Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

users: Fix truncated "From" in account logs #21418

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

martinpitt
Copy link
Member

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

This silences this unsightly warning during build:

> src/session/session.c:912:10: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]

Just ignore the result -- there is absolutely nothing that we can do at
this point to recover: we are in a signal handler and about to exit.
In TestLogin.testLogging, validate that the "last login from" string
contains a correct and complete IPv6 address and session type.

We can do this because the IP is predictable in our CI, and this test
does not run in tmt.

This ensures that cockpit-project#21383 does not affect the Overview page.
It gets stringified along the way, but this is untidy and a type
violation.
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 cockpit-project#21383
@martinpitt martinpitt requested a review from jelly December 10, 2024 09:48
Comment on lines +1097 to +1098
self.assertIn(year, started)
self.assertIn(year, ended)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This of course assumes that this test doesn't run at precisely mightnight on new year. But if you send a PR around that time, shame on you 😁 I tried to parse the shown date with date, but it's a custom format which date -d doesn't understand, so I gave up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this comment it feels like "challenge accepted". But maybe more for dependabot :)

Copy link
Member

@jelly jelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -31,7 +31,7 @@ const _ = cockpit.gettext;
export function AccountLogs({ name }) {
const [logins, setLogins] = useState([]);
useInit(() => {
cockpit.spawn(["last", "--time-format", "iso", "-n", 25, name], { environ: ["LC_ALL=C"] })
cockpit.spawn(["last", "--time-format", "iso", "-n25", "--fullnames", name], { environ: ["LC_ALL=C"] })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was confused for a bit, why isn't this -w, but that's the same thing :) I guess for historical raisins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer long options in code for better readability. But -w is the same thing indeed.

Comment on lines +1097 to +1098
self.assertIn(year, started)
self.assertIn(year, ended)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this comment it feels like "challenge accepted". But maybe more for dependabot :)

@jelly jelly merged commit 54e5094 into cockpit-project:main Dec 10, 2024
85 checks passed
@martinpitt martinpitt deleted the lastlog branch December 10, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Login history truncates IPv6 addresses
2 participants