Skip to content

Commit

Permalink
API: pam_access and pam_faillock
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Lavu committed Aug 10, 2023
1 parent 97a3994 commit 3713bac
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions sssd_test_framework/utils/pam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
""""PAM Tools."""

from __future__ import annotations

import textwrap

from pytest_mh import MultihostHost, MultihostUtility
from pytest_mh.utils.fs import LinuxFileSystem

__all__ = [
"PAMUtils",
"PAMAccess",
"PAMFaillock",
]


class PAMUtils(MultihostUtility[MultihostHost]):
"""
Management of PAM modules
"""

def __init__(self, host: MultihostHost) -> None:
"""
:param host: Remote host instance.
:type host: MultihostHost
"""
super().__init__(host)

def access(self) -> PAMAccess:
"""
:return: PAM Access object.
:rtype: PAMAccess
"""
return PAMAccess(self)

def faillock(self) -> PAMFaillock:
"""
:return: PAM Faillock object.
:rtype: PAMFaillock
"""
return PAMFaillock(self)


class PAMAccess:
"""
Management of PAM Access on the client host.
.. code-block:: python
:caption: Example usage
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_example(client: Client,
"""
def __init__(self,
util: PAMUtils,
fs: LinuxFileSystem,
file: str | None = "/etc/security/access.conf"
) -> None:
"""
:rtype: object
:param util: PAMUtils object.
:type util: PAMUtils
:param file: File name of access file.
:type file: str, optional
"""
self.util: PAMUtils = util
self.fs: LinuxFileSystem = fs
self.file: str = file

fs.backup(self.file)

def add(self,
*,
permission: str | None = "+",
name: str,
origin: str | None = "ALL"
) -> PAMAccess:
"""
:param name: Name of the user or group
:type name: str | None, required
:param permission: Permission flag, defaults to None
:type permission: str | None, optional
:param origin: Origination of access, defaults to None
:type origin: str | None, optional
:return: Self.
:rtype: PAMAccess
"""
content = f"{permission}:{name}:{origin}"

self.util.logger.info(f"{content} written to {self.file} on {self.util.host.hostname}")
self.fs.write(self.file, content, dedent=True)

return self

def delete(self):
"""
:return:
"""
def get(self):
"""
:return:
"""


class PAMFaillock:
"""
Management of PAM Faillock on the client host.
.. code-block:: python
:caption: Example usage
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_example(client: Client,
"""
def __init__(self, util: PAMUtils) -> None:
"""
:param util: PAMUtils object.
:type util: PAMUtils
"""
self.util: PAMUtils = util

0 comments on commit 3713bac

Please sign in to comment.