summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2024-10-16 21:35:12 +0200
committerGitHub <noreply@github.com>2024-10-16 21:35:12 +0200
commit663f7f3b5630068057e0529efb3add8eae279798 (patch)
tree08fbc297a48d70c71769a5ca96af7ebd16434fc5
parentUse dict comprehension instead (#83680) (diff)
downloadansible-663f7f3b5630068057e0529efb3add8eae279798.tar.xz
ansible-663f7f3b5630068057e0529efb3add8eae279798.zip
test for gathering FIPS facts (#83266)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r--lib/ansible/module_utils/facts/system/fips.py25
-rw-r--r--test/units/module_utils/facts/system/test_fips.py15
2 files changed, 21 insertions, 19 deletions
diff --git a/lib/ansible/module_utils/facts/system/fips.py b/lib/ansible/module_utils/facts/system/fips.py
index dbecd8fbaa..131434157d 100644
--- a/lib/ansible/module_utils/facts/system/fips.py
+++ b/lib/ansible/module_utils/facts/system/fips.py
@@ -1,19 +1,6 @@
+# Copyright: Contributors to the Ansible project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Determine if a system is in 'fips' mode
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
@@ -30,9 +17,9 @@ class FipsFactCollector(BaseFactCollector):
def collect(self, module=None, collected_facts=None):
# NOTE: this is populated even if it is not set
- fips_facts = {}
- fips_facts['fips'] = False
- data = get_file_content('/proc/sys/crypto/fips_enabled')
- if data and data == '1':
+ fips_facts = {
+ 'fips': False
+ }
+ if get_file_content('/proc/sys/crypto/fips_enabled') == '1':
fips_facts['fips'] = True
return fips_facts
diff --git a/test/units/module_utils/facts/system/test_fips.py b/test/units/module_utils/facts/system/test_fips.py
new file mode 100644
index 0000000000..90845cac31
--- /dev/null
+++ b/test/units/module_utils/facts/system/test_fips.py
@@ -0,0 +1,15 @@
+# Copyright: Contributors to the Ansible project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import annotations
+
+import pytest
+
+from ansible.module_utils.facts.system.fips import FipsFactCollector
+
+
+@pytest.mark.parametrize(("return_value", "expected"), [('1', True), ('0', False)])
+def test_fips(mocker, return_value, expected):
+ mocker.patch('ansible.module_utils.facts.system.fips.get_file_content', return_value=return_value)
+ fips_mgr = FipsFactCollector().collect()
+ assert fips_mgr['fips'] is expected