Skip to content

Commit

Permalink
CheckPamUserDB: implement check to report DB location
Browse files Browse the repository at this point in the history
Check the databases reported by ScanPamUserDB and print a report about
them. It also includes the unit-tests.

Signed-off-by: Iker Pedrosa <[email protected]>
  • Loading branch information
ikerexxe committed Sep 4, 2024
1 parent 9286fa4 commit 3bbc9f0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from leapp.actors import Actor
from leapp.libraries.actor import checkpamuserdb
from leapp.models import PamUserDbLocation, Report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class CheckPamUserDb(Actor):
"""
Create report with the location of pam_userdb databases
"""

name = 'check_pam_user_db'
consumes = (PamUserDbLocation,)
produces = (Report,)
tags = (ChecksPhaseTag, IPUWorkflowTag)

def process(self):
checkpamuserdb.process()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from leapp import reporting
from leapp.libraries.stdlib import api
from leapp.models import PamUserDbLocation
from leapp.exceptions import StopActorExecutionError


FMT_LIST_SEPARATOR = "\n - "


def process():
msg = next(api.consume(PamUserDbLocation), None)
if not msg:
raise StopActorExecutionError('Expected PamUserDbLocation, but got None')

if msg.locations:
reporting.create_report([
reporting.Title('pam_userdb databases will be converted to GDBM'),
reporting.Summary(
'On RHEL 10, GDMB is used by pam_userdb as it\'s backend database,'
' replacing BerkeleyDB. Existing pam_userdb databases will be'
' converted to GDBM. The following databases will be converted:'
'{sep}{locations}'.format(sep=FMT_LIST_SEPARATOR, locations=FMT_LIST_SEPARATOR.join(msg.locations))),
reporting.Severity(reporting.Severity.INFO),
reporting.Groups([reporting.Groups.SECURITY, reporting.Groups.AUTHENTICATION])
])
else:
api.current_logger().debug(
'No pam_userdb databases were located, thus nothing will be converted'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from leapp import reporting
from leapp.exceptions import StopActorExecutionError
from leapp.models import PamUserDbLocation
from leapp.libraries.actor import checkpamuserdb
from leapp.libraries.stdlib import api
from leapp.libraries.common.testutils import create_report_mocked, logger_mocked


def test_process_no_msg(monkeypatch):
def consume_mocked(*args, **kwargs):
yield None

monkeypatch.setattr(api, 'consume', consume_mocked)

with pytest.raises(StopActorExecutionError):
checkpamuserdb.process()


def test_process_no_location(monkeypatch):
def consume_mocked(*args, **kwargs):
yield PamUserDbLocation(locations=[])

monkeypatch.setattr(api, 'current_logger', logger_mocked())
monkeypatch.setattr(api, 'consume', consume_mocked)

checkpamuserdb.process()
assert (
'No pam_userdb databases were located, thus nothing will be converted'
in api.current_logger.dbgmsg
)


def test_process_locations(monkeypatch):
def consume_mocked(*args, **kwargs):
yield PamUserDbLocation(locations=['/tmp/db1', '/tmp/db2'])

monkeypatch.setattr(reporting, "create_report", create_report_mocked())
monkeypatch.setattr(api, 'consume', consume_mocked)

checkpamuserdb.process()
assert reporting.create_report.called == 1

0 comments on commit 3bbc9f0

Please sign in to comment.