From 205dedae4f5c431f00c4ff6266c1c7871b039373 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 23 Jan 2020 15:52:10 +0100 Subject: [PATCH] tests: Add dbus-monitor'ing to PAM tests Should prove useful debugging the PAM module if we need it. --- tests/pam/Makefile.am | 2 +- tests/pam/test_pam_fprintd.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/pam/Makefile.am b/tests/pam/Makefile.am index 818192e..77b53de 100644 --- a/tests/pam/Makefile.am +++ b/tests/pam/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = services -TESTS_ENVIRONMENT = export TOPSRCDIR=$(abs_top_srcdir); export LD_PRELOAD=libpam_wrapper.so; export PAM_WRAPPER_SERVICE_DIR=$(abs_top_builddir)/tests/pam/services; export PAM_WRAPPER=1; export PYTHON=@PYTHON@; +TESTS_ENVIRONMENT = export TOPBUILDDIR=$(abs_top_builddir); export TOPSRCDIR=$(abs_top_srcdir); export LD_PRELOAD=libpam_wrapper.so; export PAM_WRAPPER_SERVICE_DIR=$(abs_top_builddir)/tests/pam/services; export PAM_WRAPPER=1; export PYTHON=@PYTHON@; TESTS = test_pam_fprintd.py EXTRA_DIST = $(TESTS) diff --git a/tests/pam/test_pam_fprintd.py b/tests/pam/test_pam_fprintd.py index 784b22c..d9c4125 100755 --- a/tests/pam/test_pam_fprintd.py +++ b/tests/pam/test_pam_fprintd.py @@ -33,9 +33,31 @@ PAM_USER_UNKNOWN = 10 class TestPamFprintd(dbusmock.DBusTestCase): '''Test pam_fprintd''' + @classmethod + def start_monitor(klass): + '''Start dbus-monitor''' + + workdir = os.environ['TOPBUILDDIR'] + '/tests/pam/' + klass.monitor_log = open(os.path.join(workdir, 'dbus-monitor.log'), 'wb', buffering=0) + klass.monitor = subprocess.Popen(['dbus-monitor', '--monitor', '--system'], + stdout=klass.monitor_log, + stderr=subprocess.STDOUT) + + @classmethod + def stop_monitor(klass): + '''Stop dbus-monitor''' + + assert klass.monitor + klass.monitor.terminate() + klass.monitor.wait() + + klass.monitor_log.flush() + klass.monitor_log.close() + @classmethod def setUpClass(klass): klass.start_system_bus() + klass.start_monitor() klass.dbus_con = klass.get_dbus(True) template_path = './' @@ -44,6 +66,10 @@ class TestPamFprintd(dbusmock.DBusTestCase): klass.template_name = template_path + 'dbusmock/fprintd.py' print ('Using template from %s' % klass.template_name) + @classmethod + def tearDownClass(klass): + klass.stop_monitor() + def setUp(self): (self.p_mock, self.obj_fprintd_manager) = self.spawn_server_template( self.template_name, {}, stdout=subprocess.PIPE)