python: Add a simple pam_winbind test
authorAndreas Schneider <asn@samba.org>
Wed, 5 Apr 2017 13:59:39 +0000 (15:59 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 7 Apr 2017 12:19:23 +0000 (14:19 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Fri Apr  7 14:19:23 CEST 2017 on sn-devel-144

python/samba/tests/pam_winbind.py [new file with mode: 0644]
python/samba/tests/test_pam_winbind.sh [new file with mode: 0755]
selftest/tests.py

diff --git a/python/samba/tests/pam_winbind.py b/python/samba/tests/pam_winbind.py
new file mode 100644 (file)
index 0000000..21ea2fb
--- /dev/null
@@ -0,0 +1,39 @@
+# Unix SMB/CIFS implementation.
+#
+# Copyright (C) 2017      Andreas Schneider <asn@samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import samba.tests
+import pypamtest
+
+class SimplePamTests(samba.tests.TestCase):
+    def test_authenticate(self):
+        alice_password = "Secret007"
+        expected_rc = 0 # PAM_SUCCESS
+
+        tc = pypamtest.TestCase(pypamtest.PAMTEST_AUTHENTICATE, expected_rc)
+        res = pypamtest.run_pamtest("SAMBADOMAIN/alice", "samba", [tc], [alice_password])
+
+        self.assertTrue(res != None)
+
+    def test_authenticate_error(self):
+        alice_password = "WrongPassword"
+        expected_rc = 7 # PAM_AUTH_ERR
+
+        tc = pypamtest.TestCase(pypamtest.PAMTEST_AUTHENTICATE, expected_rc)
+        res = pypamtest.run_pamtest("SAMBADOMAIN/alice", "samba", [tc], [alice_password])
+
+        self.assertTrue(res != None)
diff --git a/python/samba/tests/test_pam_winbind.sh b/python/samba/tests/test_pam_winbind.sh
new file mode 100755 (executable)
index 0000000..bf59296
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+PYTHON="$1"
+PAM_WRAPPER_SO_PATH="$2"
+shift 2
+
+PAM_WRAPPER_PATH="$BINDIR/default/lib/pam_wrapper"
+
+pam_winbind="$BINDIR/shared/pam_winbind.so"
+service_dir="$SELFTEST_TMPDIR/pam_services"
+service_file="$service_dir/samba"
+
+mkdir $service_dir
+echo "auth        required    $pam_winbind debug debug_state" > $service_file
+echo "account     required    $pam_winbind debug debug_state" >> $service_file
+echo "password    required    $pam_winbind debug debug_state" >> $service_file
+echo "session     required    $pam_winbind debug debug_state" >> $service_file
+
+PAM_WRAPPER="1"
+export PAM_WRAPPER
+PAM_WRAPPER_SERVICE_DIR="$service_dir"
+export PAM_WRAPPER_SERVICE_DIR
+LD_PRELOAD="$LD_PRELOAD:$PAM_WRAPPER_SO_PATH"
+export LD_PRELOAD
+
+PAM_WRAPPER_DEBUGLEVEL=${PAM_WRAPPER_DEBUGLEVEL:="2"}
+export PAM_WRAPPER_DEBUGLEVEL
+
+PYTHONPATH="$PYTHONPATH:$PAM_WRAPPER_PATH:$(dirname $0)" $PYTHON -m samba.subunit.run samba.tests.pam_winbind
+exit_code=$?
+
+rm -rf $service_dir
+
+exit_code=0
+exit $exit_code
index b32b6de9b5ce05cd9139f5bada25665b580503d5..d962a66f4e63cc9052acd7e08f77d3a2abaaea4f 100644 (file)
@@ -39,6 +39,7 @@ finally:
 
 have_man_pages_support = ("XSLTPROC_MANPAGES" in config_hash)
 with_cmocka = ("HAVE_CMOCKA" in config_hash)
 
 have_man_pages_support = ("XSLTPROC_MANPAGES" in config_hash)
 with_cmocka = ("HAVE_CMOCKA" in config_hash)
+pam_wrapper_so_path=config_hash["LIBPAM_WRAPPER_SO_PATH"]
 
 planpythontestsuite("none", "samba.tests.source")
 if have_man_pages_support:
 
 planpythontestsuite("none", "samba.tests.source")
 if have_man_pages_support:
@@ -136,6 +137,9 @@ plantestsuite(
      configuration])
 planpythontestsuite("none", "samba.tests.glue", py3_compatible=True)
 
      configuration])
 planpythontestsuite("none", "samba.tests.glue", py3_compatible=True)
 
+plantestsuite("samba.tests.pam_winbind", "ad_member",
+              [os.path.join(srcdir(), "python/samba/tests/test_pam_winbind.sh"), valgrindify(python), pam_wrapper_so_path])
+
 if with_cmocka:
     plantestsuite("samba.unittests.krb5samba", "none",
                   [os.path.join(bindir(), "default/testsuite/unittests/test_krb5samba")])
 if with_cmocka:
     plantestsuite("samba.unittests.krb5samba", "none",
                   [os.path.join(bindir(), "default/testsuite/unittests/test_krb5samba")])