Merge lp:~sergei.glushchenko/percona-pam-for-mysql/pam-supp-grp-test into lp:percona-pam-for-mysql

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: 30
Merged at revision: 30
Proposed branch: lp:~sergei.glushchenko/percona-pam-for-mysql/pam-supp-grp-test
Merge into: lp:percona-pam-for-mysql
Prerequisite: lp:~sergei.glushchenko/percona-pam-for-mysql/BT32086-bug1160348
Diff against target: 122 lines (+118/-0)
1 file modified
test/dbqp/percona_tests/percona_pam/pam_mapping_test.py (+118/-0)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-pam-for-mysql/pam-supp-grp-test
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+168637@code.launchpad.net

Description of the change

  Test case for a support of supplementary groups.
  Test case adds system groups grp10, grp11, grp12 and modifies user
  pam_user to be a member of them with grp10 as primary group.
  Test also sets up mysql ''@'' user as identified with
  auth_pam. It sets authentication string to map grp1N to userN mysql
  user. Then it grants proxy to ''@''. After it chackes that
  authentication is successful and system user's group is mapped to
  correct mysql user.

Testcase confirmed to run successfully on CentOS 5 VM with root privileges.

To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'test/dbqp/percona_tests/percona_pam/pam_mapping_test.py'
2--- test/dbqp/percona_tests/percona_pam/pam_mapping_test.py 1970-01-01 00:00:00 +0000
3+++ test/dbqp/percona_tests/percona_pam/pam_mapping_test.py 2013-06-11 10:33:08 +0000
4@@ -0,0 +1,118 @@
5+#! /usr/bin/env python
6+# -*- mode: python; indent-tabs-mode: nil; -*-
7+# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
8+#
9+# Copyright (C) 2013 Percona Ireland Ltd.
10+#
11+#
12+# This program is free software; you can redistribute it and/or modify
13+# it under the terms of the GNU General Public License as published by
14+# the Free Software Foundation; either version 2 of the License, or
15+# (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU General Public License for more details.
21+#
22+# You should have received a copy of the GNU General Public License
23+# along with this program; if not, write to the Free Software
24+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25+
26+import os
27+import time
28+import shutil
29+import signal
30+import subprocess
31+import re
32+import grp
33+
34+from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
35+from lib.util.mysql_methods import execute_cmd
36+
37+
38+server_requirements = [[]]
39+servers = []
40+server_manager = None
41+test_executor = None
42+pamcfg = '/etc/pam.d/mysqld'
43+
44+def group_exists(groupname):
45+ try:
46+ grp.getgrnam(groupname)[0]
47+ except KeyError:
48+ return False
49+ return True
50+
51+class basicTest(mysqlBaseTestCase):
52+
53+ def test_pam_basic(self):
54+ percent_string = '%'
55+ opt_matrix_req = ['pam_plugin_dir']
56+ self.servers = servers
57+ logging = test_executor.logging
58+ master_server = servers[0]
59+ output_path = os.path.join(master_server.vardir, 'pam.out')
60+ test_executor.matrix_manager.matrix_check_req(opt_matrix_req)
61+ # This is a master
62+ if test_executor.matrix_manager.option_matrix['pam_user']:
63+ pam_user = test_executor.matrix_manager.option_matrix['pam_user']
64+ else:
65+ pam_user = 'pamuser'
66+
67+ groups = ['grp%d' % (n) for n in xrange(3)]
68+ users = ['user1%d' % (n) for n in xrange(3)]
69+
70+ for grp in groups:
71+ if not group_exists(grp):
72+ subprocess.call(["groupadd", grp])
73+
74+ # Create UNIX system account
75+ if not test_executor.system_manager.user_exists(pam_user):
76+ subprocess.call(["useradd", pam_user, "-g", groups[0], "-G", ",".join(groups[1:]) ])
77+ else:
78+ subprocess.call(["usermod", "-g", groups[0], "-G", ",".join(groups[1:]), pam_user ])
79+
80+ # Create PAM config
81+ if (os.path.isfile(pamcfg)):
82+ os.remove(pamcfg)
83+
84+ pamcfg_fh = open("/etc/pam.d/mysqld", "wb")
85+ pamcfg_fh.write("auth\trequired\tpam_permit.so\n")
86+ pamcfg_fh.write("account\trequired\tpam_permit.so\n")
87+ pamcfg_fh.close();
88+
89+ master_server.stop()
90+
91+ # setup plugin, users, privileges
92+ groups.reverse()
93+ groups = [ "grp21", "grp22" ] + groups
94+ users = [ "usr21", "usr22" ] + users
95+ queries = [ "INSTALL PLUGIN auth_pam SONAME 'auth_pam.so';" ] + \
96+ [ "CREATE USER '%s'@'localhost';" % (user) for user in users ] + \
97+ [ "CREATE USER ''@'' IDENTIFIED WITH auth_pam AS 'mysqld, %s';" \
98+ % ( ",".join([ user + "=" + group for user, group in zip(groups, users) ] ) ) ] + \
99+ [ "GRANT PROXY ON '%s'@'localhost' TO ''@'';" % (user) for user in users ] + \
100+ [ "SELECT user, host, authentication_string FROM mysql.user;", \
101+ "FLUSH PRIVILEGES;", "SHOW VARIABLES LIKE 'plugin%'" ]
102+
103+ master_server.server_options.append('--plugin-dir=%s' %(test_executor.matrix_manager.option_matrix['pam_plugin_dir']))
104+
105+ master_server.start()
106+ self.assertEqual( master_server.status, 1, msg = 'Server failed to restart')
107+
108+ cmd = "%s --protocol=tcp --port=%d -uroot -e \"%s\"" %(master_server.mysql_client
109+ , master_server.master_port
110+ , "\n".join(queries) )
111+ retcode, output = execute_cmd(cmd, output_path, None, True)
112+
113+ query = "SELECT CONCAT(USER(), CURRENT_USER(), @@PROXY_USER) as res;"
114+ expected_result = "res%s@localhostuser10@localhost''@''" % (pam_user)
115+ cmd = "%s --plugin-dir=/usr/lib/mysql/plugin/ --protocol=tcp --port=%d --user=%s --password=\'\' -e \"%s\" test" %(master_server.mysql_client
116+ , master_server.master_port
117+ , pam_user
118+ , query )
119+ retcode, output = execute_cmd(cmd, output_path, None, True)
120+ output = re.sub(r'\s+', '', output)
121+ self.assertEqual(retcode, 0, msg = output)
122+ self.assertEqual(output, expected_result, msg = "%s || %s" %(output, expected_result))

Subscribers

People subscribed via source and target branches