-
Notifications
You must be signed in to change notification settings - Fork 356
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
core: Look up live user from PKEXEC_UID #5074
Conversation
note this is untested. it's just fixing a problem I saw when looking at recent commit history. |
cc @jkonecny12 |
cddcde6
to
645dbb3
Compare
Thanks, I'll take a look on this. |
d5c2f69
to
68a03f8
Compare
Tested and seems to be fix for https://bugzilla.redhat.com/show_bug.cgi?id=2235728 . |
@halfline thanks for the PR! Do you agree that I'll take over this PR and finish it? |
yes please |
Verified even in the Live environment and it seems to be working correctly everywhere, great work! We just need to fix the tests and link the bug. |
68a03f8
to
ca4cf00
Compare
@VladimirSlavik, @M4rtinK, @rvykydal could you please tell me if you agree with the second commit (should be squashed if you agree). I tried to do this in way of pytest because they have great monkeypatching for environment vars, however, it was a bit bigger overhaul. What I wonder is if we want to go this way or rather stick with the current UnitTests approach. I definitely can change the tests to the old solution if we prefer that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test also really possible values for the environment variable:
- negative number
- zero
- huge number out of range
- non-numeric string such as "hello world"
- empty string
- etc...
The actual code as written now does not try to do anything beyond surviving missing variable.
ca4cf00
to
a49761b
Compare
UPDATED:
|
I definitely can add that but I wonder what we want to cover here? If the PKEXEC_UID will be wrong then policy kit doesn't work as expected and we have much more problems then broken installation. Do we want to be that paranoid? |
a49761b
to
54fd7cb
Compare
I guess you can't be paranoid enough 😆 Anyway, updated to add more tests for the input environment variable. |
54fd7cb
to
5aec17d
Compare
/kickstart-test --testtype smoke |
5aec17d
to
8ada751
Compare
Ah, sorry. The point was that there are values that will clearly make the code crash, and that the code is always executed, so you want to make it not-crashy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks good to me in terms of ensuring it works.
Please consider merging the "fail" tests and adding doc texts.
@patch("pyanaconda.core.live_user.conf") | ||
@patch("pyanaconda.core.live_user.getpwuid") | ||
@patch.dict("pyanaconda.core.live_user.os.environ", {"PKEXEC_UID": "1024"}) | ||
def test_get_live_user_with_failed_getpwuid(self, getpwuid_mock, conf_mock): | ||
# supposedly live but missing user | ||
conf_mock.system.provides_liveuser = True | ||
getpwuid_mock.side_effect = KeyError | ||
assert get_live_user() is None | ||
getpwuid_mock.assert_called_once_with(1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now I understand why you thought this is verbose compared to pytest! You can actually collapse all of the "fail" tests into one by using patch.dict
within a loop:
@patch("pyanaconda.core.live_user.conf")
@patch("pyanaconda.core.live_user.getpwuid")
def test_get_live_user_with_wrong_pkexec_env(self, getpwuid_mock, conf_mock):
"""Test getting live user with wrong environment values"""
# supposedly live but missing user
conf_mock.system.provides_liveuser = True
# no value
with patch.dict("pyanaconda.core.live_user.os.environ", dict()):
assert get_live_user() is None
getpwuid_mock.assert_not_called()
# all the rest
for value in ("", "0", "-1", "999999999999999999999999", "hello world"):
with patch.dict("pyanaconda.core.live_user.os.environ", {"PKEXEC_ENV": value}):
assert get_live_user() == None
getpwuid_mock.assert_not_called()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, your suggested solution is probably better one. I was balancing between cleanliness and correctness.
Having each of these tests as separate test seems to me like more correct approach - one test / one test-case. However, yeah it's pretty verbose.
anaconda can be run as gnome-initial-setup or liveuser on live images, depending on how its started by the use. It currently assumes it will be started as liveuser always. This commit makes it look up the username and home directory by querying PKEXEC_UID environment variable. Resolves: rhbz#2235728
8ada751
to
28ee0b0
Compare
UPDATED
|
/kickstart-test --testtype smoke |
anaconda can be run as gnome-initial-setup or liveuser on live images, depending on how its started by the use.
It currently assumes it will be started as liveuser always.
This commit makes it look up the username and home directory by querying PKEXEC_UID environment variable.