Debian Codegraph @

test/units/module_utils/facts/system/test_user.py

raw
1 # unit tests for ansible system lsb fact collectors
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # Ansible is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
16 #
17
18 from __future__ import annotations
19
20 from ansible.module_utils.facts.system.user import UserFactCollector
21
22 import os
23
24
25 def test_logname():
26 """ Test if ``UserFactCollector`` still works with LOGNAME set """
27 collector = UserFactCollector()
28
29 unmodified_facts = collector.collect()
30 # Change logname env var and check if the collector still finds
31 # the pw entry.
32 os.environ["LOGNAME"] = "NONEXISTINGUSERDONTEXISTPLEASE"
33 modified_facts = collector.collect()
34
35 # Set logname should be different to the real name.
36 assert unmodified_facts['user_id'] != modified_facts['user_id']
37 # Actual UID is the same.
38 assert unmodified_facts['user_uid'] == modified_facts['user_uid']