Merge lp:~longbow/kewpie/py_pam into lp:kewpie

Proposed by Valentine Gostev on 2012-02-22
Status: Merged
Merged at revision: 122
Proposed branch: lp:~longbow/kewpie/py_pam
Merge into: lp:kewpie
Diff against target: 141 lines (+118/-0)
2 files modified
lib/sys_mgmt/system_management.py (+8/-0)
percona_tests/percona_pam/pam_basic_test.py (+110/-0)
To merge this branch: bzr merge lp:~longbow/kewpie/py_pam
Reviewer Review Type Date Requested Status
kewpie Developers 2012-02-22 Pending
Review via email: mp+94219@code.launchpad.net

Description of the change

Added basic positive pam test

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/sys_mgmt/system_management.py'
2--- lib/sys_mgmt/system_management.py 2012-01-26 01:54:17 +0000
3+++ lib/sys_mgmt/system_management.py 2012-02-22 16:36:09 +0000
4@@ -33,6 +33,7 @@
5 # imports
6 import os
7 import sys
8+import pwd
9 import shutil
10 import getpass
11 import commands
12@@ -526,6 +527,13 @@
13 except OSError:
14 self.logging.verbose("PID: %s was not running despite the existence of a pid file. This may be of note...")
15 return
16+
17+ def user_exists(self, username):
18+ try:
19+ pwd.getpwnam(username)[0]
20+ except KeyError:
21+ return False
22+ return True
23
24 def get_ip_address(self):
25 """ We find the ip address of our host.
26
27=== added directory 'percona_tests/percona_pam'
28=== added file 'percona_tests/percona_pam/pam_basic_test.py'
29--- percona_tests/percona_pam/pam_basic_test.py 1970-01-01 00:00:00 +0000
30+++ percona_tests/percona_pam/pam_basic_test.py 2012-02-22 16:36:09 +0000
31@@ -0,0 +1,110 @@
32+#! /usr/bin/env python
33+# -*- mode: python; indent-tabs-mode: nil; -*-
34+# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
35+#
36+# Copyright (C) 2012 Valentine Gostev
37+#
38+#
39+# This program is free software; you can redistribute it and/or modify
40+# it under the terms of the GNU General Public License as published by
41+# the Free Software Foundation; either version 2 of the License, or
42+# (at your option) any later version.
43+#
44+# This program is distributed in the hope that it will be useful,
45+# but WITHOUT ANY WARRANTY; without even the implied warranty of
46+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47+# GNU General Public License for more details.
48+#
49+# You should have received a copy of the GNU General Public License
50+# along with this program; if not, write to the Free Software
51+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
52+
53+import os
54+import time
55+import shutil
56+import signal
57+import subprocess
58+
59+from lib.util.mysqlBaseTestCase import mysqlBaseTestCase
60+from lib.util.mysql_methods import execute_cmd
61+
62+
63+server_requirements = [[]]
64+servers = []
65+server_manager = None
66+test_executor = None
67+pamcfg = '/etc/pam.d/mysqld'
68+
69+class basicTest(mysqlBaseTestCase):
70+
71+ def test_pam_basic(self):
72+ opt_matrix_req = ['pam_plugin_dir']
73+ self.servers = servers
74+ logging = test_executor.logging
75+ master_server = servers[0]
76+ output_path = os.path.join(master_server.vardir, 'pam.out')
77+ # Checking that required options were given
78+ test_executor.matrix_manager.matrix_check_req(opt_matrix_req)
79+
80+ # Create UNIX system account
81+ if (test_executor.matrix_manager.option_matrix['pam_user']):
82+ pam_user = test_executor.matrix_manager.option_matrix['pam_user']
83+ else:
84+ pam_user = 'pamuser'
85+
86+ if not (test_executor.system_manager.user_exists(pam_user)):
87+ subprocess.call(["useradd", pam_user])
88+
89+ # Create PAM config
90+ if (os.path.isfile(pamcfg)):
91+ os.remove(pamcfg)
92+
93+ pamcfg_fh = open("/etc/pam.d/mysqld", "wb")
94+ pamcfg_fh.write("auth\trequired\tpam_permit.so\n")
95+ pamcfg_fh.close();
96+
97+ # Stop server
98+ master_server.stop()
99+
100+ # Specify mysql plugin dir
101+ master_server.server_options.append('--plugin-dir=%s' %(test_executor.matrix_manager.option_matrix['pam_plugin_dir']))
102+ # Start server with new options
103+ master_server.start()
104+ self.assertEqual( master_server.status, 1, msg = 'Server failed to restart')
105+ # Install plugin
106+ query = "INSTALL PLUGIN auth_pam SONAME \'auth_pam.so\'"
107+ expected_result = ''
108+ cmd = "%s --protocol=tcp --port=%d -uroot -e \"%s\"" %(master_server.mysql_client
109+ , master_server.master_port
110+ , query )
111+ retcode, output = execute_cmd(cmd, output_path, None, True)
112+ self.assertEqual(retcode, 0, msg = cmd)
113+ self.assertEqual(output, expected_result, msg = "%s || %s" %(output, expected_result))
114+ # Create user
115+ query = "CREATE USER \'%s\'@\'%\' IDENTIFIED WITH auth_pam;" %(pam_user)
116+ expected_result = ''
117+ cmd = "%s --protocol=tcp --port=%d -uroot -e \"%s\"" %(master_server.mysql_client
118+ , master_server.master_port
119+ , query )
120+ retcode, output = execute_cmd(cmd, output_path, None, True)
121+ self.assertEqual(retcode, 0, msg = output)
122+ self.assertEqual(output, expected_result, msg = "%s || %s" %(output, expected_result))
123+ # Grant permissions
124+ query = "GRANT ALL ON test.* TO \'%s\'@\'%\';" %(pam_user)
125+ expected_result = ''
126+ cmd = "%s --protocol=tcp --port=%d --user=root -e \"%s\"" %(master_server.mysql_client
127+ , master_server.master_port
128+ , query )
129+ retcode, output = execute_cmd(cmd, output_path, None, True)
130+ self.assertEqual(retcode, 0, msg = output)
131+ self.assertEqual(output, expected_result, msg = "%s || %s" %(output, expected_result))
132+ # Test user login
133+ query = "SHOW TABLES;"
134+ expected_result = ''
135+ cmd = "%s --plugin-dir=/usr/lib/mysql/plugin/ --protocol=tcp --port=%d --user=%s --password=\'\' -e \"%s\" test" %(master_server.mysql_client
136+ , master_server.master_port
137+ , pam_user
138+ , query )
139+ retcode, output = execute_cmd(cmd, output_path, None, True)
140+ self.assertEqual(retcode, 0, msg = output)
141+ self.assertEqual(output, expected_result, msg = "%s || %s" %(output, expected_result))

Subscribers

People subscribed via source and target branches