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

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

Subscribers

People subscribed via source and target branches