Skip to content

Conversation

3v1n0
Copy link
Collaborator

@3v1n0 3v1n0 commented Jun 16, 2025

See commits for details.

Base of #971

@3v1n0 3v1n0 requested a review from a team as a code owner June 16, 2025 20:34
@3v1n0 3v1n0 force-pushed the ssh-tests-cleanups branch 2 times, most recently from 229946b to 2a9c077 Compare June 16, 2025 21:39
3v1n0 added 5 commits June 17, 2025 03:53
Do not show the sshd messages unless we have a failure, this avoids
spamming CI, but also it seems that in such context they get scrambled.

At the same time they're useful during debugging, so don't change the
behavior when we're in an interactive terminal
…orks

It's kind implicit in the previous tests, but still let's test the non
interactive behavior too
Otherwise mkhomedir may fail in trying to create it, and so SSH:
  Could not chdir to home directory /home/user-integration-cached:
  No such file or directory
In case the user is considered already existent:
 - Create the directory when parsing the DB
 - Ensure the directory already exists at test time

Otherwise:
 - Ensure no user home directory exists before user has been created
 - Ensure the user home exists after user logged in
@3v1n0 3v1n0 force-pushed the ssh-tests-cleanups branch from 2a9c077 to 7f5af63 Compare June 17, 2025 01:53
Let's give some time to ssh to print all the environment first
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.61%. Comparing base (bbbb672) to head (6c6887b).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #979   +/-   ##
=======================================
  Coverage   85.61%   85.61%           
=======================================
  Files          82       82           
  Lines        5792     5792           
  Branches      111      111           
=======================================
  Hits         4959     4959           
  Misses        777      777           
  Partials       56       56           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@3v1n0 3v1n0 requested a review from adombeck June 18, 2025 15:02
Comment on lines -87 to +80
user-pre-check: '{"Name":"user-pre-check","UID":1974679960,"GID":1974679960,"Gecos":"gecos for user-pre-check","Dir":"/home/user-pre-check","Shell":"/bin/sh","LastPwdChange":-1,"MaxPwdAge":-1,"PwdWarnPeriod":-1,"PwdInactivity":-1,"MinPwdAge":-1,"ExpirationDate":-1,"LastLogin":"2025-05-30T18:24:42.349318925+02:00"}'
user-integration-UPPER-CASE: '{"Name":"user-integration-UPPER-CASE","UID":1911746559,"GID":1911746559,"Gecos":"gecos for user-integration-UPPER-CASE","Dir":"@HOME_BASE@/user-integration-UPPER-CASE","Shell":"/bin/sh","LastPwdChange":-1,"MaxPwdAge":-1,"PwdWarnPeriod":-1,"PwdInactivity":-1,"MinPwdAge":-1,"ExpirationDate":-1,"LastLogin":"2025-05-30T18:20:04.201035581+02:00"}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a valid home for already-existing users

Otherwise mkhomedir may fail in trying to create it, and so SSH:
Could not chdir to home directory /home/user-integration-cached:
No such file or directory

Why does mkhomedir fail when trying to create a directory /home/user-pre-check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, it does in this test environment of course... It's just running as user, so it won't be able to make a such directory.

Indeed if we would make the daemon run inside bwrap, things would change, but that's for another day.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I see. could we change the home directories in the testdata to /tmp/user-pre-check etc. instead? could we avoid the extra redaction + insertion logic that way?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Eh, I don't like to have fixed and hardcoded paths, since otherwise we may end up having false positive/negatives when repeating the tests locally, and if a test expects something from the environment (like being able to write to /tmp) is already a problem IMHO.

I did initially some simple redaction, but then I though the one I ended up was more prone to potential future issues.

// Z_ForTests_CreateDBFromYAMLWithBaseHome creates the database inside destDir and loads the src file content into it.
//
// nolint:revive,nolintlint // We want to use underscores in the function name here.
func Z_ForTests_CreateDBFromYAMLWithBaseHome(src, destDir, baseHomeDir string) (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this in the old bbolt package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because that's a function to generate a bolt db, no?
I just added another function similar to where the one we had was...

I initially was just doing this as part of the integration tests helpers, but it felt something to do in its own spot (also to be able to access to private stuff).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the integration tests should not use a bbolt database anymore, except for test cases which test migration from bbolt to sqlite. I see useOldDatabaseEnv is used in many other test cases as well

Copy link
Contributor

Choose a reason for hiding this comment

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

ah but it just returns if oldDB is empty, which it is for all test cases except for the ones which test migration

Copy link
Contributor

Choose a reason for hiding this comment

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

but that means that Z_ForTests_CreateDBFromYAMLWithBaseHome is also only used for those test cases which test migration. is that expected?

Copy link
Contributor

Choose a reason for hiding this comment

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

do we not need to create the home directory in the other cases, where we use a SQLite db?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do we not need to create the home directory in the other cases, where we use a SQLite db?

Oh, we should, but IIRC we don't have such tests yet... I need to double check it.

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.

3 participants