-
Notifications
You must be signed in to change notification settings - Fork 29
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
Replace fips-mode-setup #349
Open
duzda
wants to merge
4
commits into
freeipa:master
Choose a base branch
from
duzda:replace-fips-mode-setup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,10 @@ | |
from ipahealthcheck.core import config, constants | ||
from ipahealthcheck.meta.plugin import registry | ||
from ipahealthcheck.meta.core import MetaCheck | ||
from ipapython import ipautil | ||
from ipaplatform.paths import paths | ||
|
||
if 'FIPS_MODE_SETUP' not in dir(paths): | ||
paths.FIPS_MODE_SETUP = '/usr/bin/fips-mode-setup' | ||
if 'PROC_FIPS_ENABLED' not in dir(paths): | ||
paths.PROC_FIPS_ENABLED = '/proc/sys/crypto/fips_enabled' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar platforms comment. |
||
|
||
|
||
def gen_result(returncode, output='', error=''): | ||
|
@@ -36,7 +35,7 @@ def gen_result(returncode, output='', error=''): | |
|
||
class TestMetaFIPS(BaseTest): | ||
@patch('os.path.exists') | ||
def test_fips_no_fips_mode_setup(self, mock_exists): | ||
def test_fips_no_fips_available(self, mock_exists): | ||
mock_exists.return_value = False | ||
|
||
framework = object() | ||
|
@@ -48,18 +47,19 @@ def test_fips_no_fips_mode_setup(self, mock_exists): | |
assert len(self.results) == 1 | ||
|
||
result = self.results.results[0] | ||
assert result.result == constants.SUCCESS | ||
assert result.result == constants.WARNING | ||
assert result.source == 'ipahealthcheck.meta.core' | ||
assert result.check == 'MetaCheck' | ||
assert result.kw.get('fips') == 'missing %s' % paths.FIPS_MODE_SETUP | ||
assert result.kw.get('fips') == 'missing %s' % paths.PROC_FIPS_ENABLED | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_fips_disabled(self, mock_run, mock_exists): | ||
def test_fips_disabled(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '0' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(2), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -78,12 +78,13 @@ def test_fips_disabled(self, mock_run, mock_exists): | |
assert result.kw.get('fips') == 'disabled' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_fips_enabled(self, mock_run, mock_exists): | ||
def test_fips_enabled(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '1' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(0), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -102,12 +103,13 @@ def test_fips_enabled(self, mock_run, mock_exists): | |
assert result.kw.get('fips') == 'enabled' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_fips_inconsistent(self, mock_run, mock_exists): | ||
def test_fips_unknown(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '2' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(1), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -123,15 +125,16 @@ def test_fips_inconsistent(self, mock_run, mock_exists): | |
assert result.result == constants.SUCCESS | ||
assert result.source == 'ipahealthcheck.meta.core' | ||
assert result.check == 'MetaCheck' | ||
assert result.kw.get('fips') == 'inconsistent' | ||
assert result.kw.get('fips') == 'unknown' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_fips_unknown(self, mock_run, mock_exists): | ||
def test_fips_non_numeric(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = 'test' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(103), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -144,20 +147,22 @@ def test_fips_unknown(self, mock_run, mock_exists): | |
assert len(self.results) == 1 | ||
|
||
result = self.results.results[0] | ||
assert result.result == constants.SUCCESS | ||
assert result.result == constants.ERROR | ||
assert result.source == 'ipahealthcheck.meta.core' | ||
assert result.check == 'MetaCheck' | ||
assert result.kw.get('fips') == 'unknown' | ||
assert result.kw.get('fips') == 'failed to check' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_fips_failed(self, mock_run, mock_exists): | ||
def test_fips_failed(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
|
||
mock_result.side_effect = [ | ||
gen_result(constants.ERROR, output="failed to check"), | ||
] | ||
|
||
mock_run.side_effect = [ | ||
ipautil.CalledProcessError( | ||
1, 'fips-mode-setup', output='execution failed' | ||
), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -190,19 +195,20 @@ def test_acme_no_ipa_acme_status(self, mock_exists): | |
assert len(self.results) == 1 | ||
|
||
result = self.results.results[0] | ||
assert result.result == constants.SUCCESS | ||
assert result.result == constants.WARNING | ||
assert result.source == 'ipahealthcheck.meta.core' | ||
assert result.check == 'MetaCheck' | ||
assert result.kw.get('acme') == \ | ||
'missing %s' % '/usr/sbin/ipa-acme-manage' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_acme_disabled(self, mock_run, mock_exists): | ||
def test_acme_disabled(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '1' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(0), | ||
gen_result(0, output='ACME is disabled'), | ||
] | ||
|
||
|
@@ -221,12 +227,13 @@ def test_acme_disabled(self, mock_run, mock_exists): | |
assert result.kw.get('acme') == 'disabled' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_acme_enabled(self, mock_run, mock_exists): | ||
def test_acme_enabled(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '1' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(0), | ||
gen_result(0, output='ACME is enabled'), | ||
] | ||
|
||
|
@@ -245,12 +252,13 @@ def test_acme_enabled(self, mock_run, mock_exists): | |
assert result.kw.get('acme') == 'enabled' | ||
|
||
@patch('os.path.exists') | ||
@patch('pathlib.Path.read_text') | ||
@patch('ipapython.ipautil.run') | ||
def test_acme_unknown(self, mock_run, mock_exists): | ||
def test_acme_unknown(self, mock_run, mock_result, mock_exists): | ||
mock_exists.return_value = True | ||
mock_result.return_value = '1' | ||
|
||
mock_run.side_effect = [ | ||
gen_result(0), | ||
gen_result( | ||
0, | ||
error="cannot connect to 'https://somewhere/acme/login" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
PROC_FIPS_ENABLED is in ipaplatform/base.py so should be visible in any derived platform. One can override a path but not remove it so I don't think this part is necessary. It's good defensive coding though.