forked from oamg/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScanCryptoPolicies: Adjust the test not to depend on the underlying OS
Signed-off-by: Jakub Jelen <[email protected]>
- Loading branch information
Showing
1 changed file
with
38 additions
and
6 deletions.
There are no files selected for viewing
44 changes: 38 additions & 6 deletions
44
...ystem_upgrade/common/actors/scancryptopolicies/tests/component_test_scancryptopolicies.py
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 |
---|---|---|
@@ -1,14 +1,46 @@ | ||
import distro | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.libraries.actor import scancryptopolicies | ||
from leapp.libraries.common.config import version | ||
from leapp.models import CryptoPolicyInfo | ||
|
||
|
||
def test_actor_execution(monkeypatch, current_actor_context): | ||
source_version = int(distro.major_version()) | ||
monkeypatch.setattr(version, 'get_source_major_version', lambda: "{}".format(source_version)) | ||
@pytest.mark.parametrize(('source_version', 'should_run'), [ | ||
('7', False), | ||
('8', True), | ||
('9', True), | ||
]) | ||
def test_actor_execution(monkeypatch, current_actor_context, source_version, should_run): | ||
def read_current_policy_mock(filename): | ||
return "DEFAULT_XXX" | ||
|
||
def listdir_mock(path): | ||
if path == '/etc/crypto-policies/policies': | ||
return ['modules'] | ||
if path == '/etc/crypto-policies/policies/modules': | ||
return [] | ||
if path == '/usr/share/crypto-policies/policies': | ||
return ['modules', 'DEFAULT', 'FUTURE', 'FIPS', 'LEGACY'] | ||
if path == '/usr/share/crypto-policies/policies/modules': | ||
return ['SHA1', 'TEST-PQ', 'OSPP'] | ||
return _original_listdir(path) | ||
|
||
def isfile_mock(filename): | ||
if filename.endswith('/modules'): | ||
return False | ||
return True | ||
|
||
monkeypatch.setattr(version, 'get_source_major_version', lambda: source_version) | ||
monkeypatch.setattr(scancryptopolicies, 'read_current_policy', read_current_policy_mock) | ||
_original_listdir = os.listdir | ||
monkeypatch.setattr(os, 'listdir', listdir_mock) | ||
monkeypatch.setattr(os.path, 'isfile', isfile_mock) | ||
current_actor_context.run() | ||
if source_version > 8: | ||
assert current_actor_context.consume(CryptoPolicyInfo) | ||
if should_run: | ||
cpi = current_actor_context.consume(CryptoPolicyInfo) | ||
assert cpi | ||
assert cpi[0].current_policy == 'DEFAULT_XXX' | ||
else: | ||
assert not current_actor_context.consume(CryptoPolicyInfo) |