From 70c183862052b63be0ef3fef3f32081998c8b9e4 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 8 Mar 2010 04:39:08 +0000 Subject: [PATCH] Add a "make testrealm" target using the Python test framework. As part of this, expose the environments in K5Realm as attributes so that test scripts can modify them. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23794 dc483132-0cff-0310-8789-dd5450dbe970 --- src/Makefile.in | 4 +++ src/util/k5test.py | 31 +++++++++++-------- src/util/testrealm.py | 69 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 src/util/testrealm.py diff --git a/src/Makefile.in b/src/Makefile.in index 23ea78fc1..ed0e69c14 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -624,6 +624,10 @@ check-unix:: krb5-config $(SHELL) $(srcdir)/t_krbconf check-prerecurse: fake-install +# Create a test realm and spawn a shell in an environment pointing to it. +testrealm: fake-install + PYTHONPATH=$(top_srcdir)/util $(PYTHON) $(srcdir)/util/testrealm.py + COV_BUILD= cov-build COV_ANALYZE= cov-analyze COV_COMMIT= cov-commit-defects --product "$(COV_PRODUCT)" --user "$(COV_USER)" --target "$(COV_TARGET)" --description "$(COV_DESC)" diff --git a/src/util/k5test.py b/src/util/k5test.py index 5205875a7..2404a46a1 100644 --- a/src/util/k5test.py +++ b/src/util/k5test.py @@ -281,6 +281,13 @@ Scripts may use the following realm methods and attributes: credentials for user unless disabled by the realm construction options. +* Attributes for the client, server, master, and slave environments. + These environments are extensions of os.environ. + - realm.env_client + - realm.env_server + - realm.env_master + - realm.env_slave + When the test script is run, its behavior can be modified with command-line flags. These are documented in the --help output. @@ -654,10 +661,10 @@ class K5Realm(object): self._create_acl() self._create_dictfile() - self._env_client = self._make_env('client', False) - self._env_server = self._make_env('server', False) - self._env_master = self._make_env('master', True) - self._env_slave = self._make_env('slave', True) + self.env_client = self._make_env('client', False) + self.env_server = self._make_env('server', False) + self.env_master = self._make_env('master', True) + self.env_slave = self._make_env('slave', True) if create_kdb: self.create_kdb() @@ -771,28 +778,28 @@ class K5Realm(object): return env def run_as_client(self, args, **keywords): - return _run_cmd(args, self._env_client, **keywords) + return _run_cmd(args, self.env_client, **keywords) def run_as_server(self, args, **keywords): - return _run_cmd(args, self._env_server, **keywords) + return _run_cmd(args, self.env_server, **keywords) def run_as_master(self, args, **keywords): - return _run_cmd(args, self._env_master, **keywords) + return _run_cmd(args, self.env_master, **keywords) def run_as_slave(self, args, **keywords): - return _run_cmd(args, self._env_slave, **keywords) + return _run_cmd(args, self.env_slave, **keywords) def server_port(self): return self.portbase + 3 def start_server(self, args, sentinel): - return _start_daemon(args, self._env_server, sentinel) + return _start_daemon(args, self.env_server, sentinel) def start_in_inetd(self, args, port=None): if not port: port = self.server_port() inetd_args = [t_inetd, str(port)] + args - return _start_daemon(inetd_args, self._env_server, 'Ready!') + return _start_daemon(inetd_args, self.env_server, 'Ready!') def create_kdb(self): global kdb5_util @@ -801,7 +808,7 @@ class K5Realm(object): def start_kdc(self): global krb5kdc assert(self._kdc_proc is None) - self._kdc_proc = _start_daemon([krb5kdc, '-n'], self._env_master, + self._kdc_proc = _start_daemon([krb5kdc, '-n'], self.env_master, 'starting...') def stop_kdc(self): @@ -813,7 +820,7 @@ class K5Realm(object): global krb5kdc assert(self._kadmind_proc is None) self._kadmind_proc = _start_daemon([kadmind, '-nofork', '-W'], - self._env_master, 'starting...') + self.env_master, 'starting...') def stop_kadmind(self): assert(self._kadmind_proc is not None) diff --git a/src/util/testrealm.py b/src/util/testrealm.py new file mode 100644 index 000000000..826cb00b0 --- /dev/null +++ b/src/util/testrealm.py @@ -0,0 +1,69 @@ +# Copyright (C) 2010 by the Massachusetts Institute of Technology. +# All rights reserved. + +# Export of this software from the United States of America may +# require a specific license from the United States Government. +# It is the responsibility of any person or organization contemplating +# export to obtain such a license before exporting. +# +# WITHIN THAT CONSTRAINT, permission to use, copy, modify, and +# distribute this software and its documentation for any purpose and +# without fee is hereby granted, provided that the above copyright +# notice appear in all copies and that both that copyright notice and +# this permission notice appear in supporting documentation, and that +# the name of M.I.T. not be used in advertising or publicity pertaining +# to distribution of the software without specific, written prior +# permission. Furthermore if you modify this software you must label +# your software as modified software and not distribute it in such a +# fashion that it might be confused with the original M.I.T. software. +# M.I.T. makes no representations about the suitability of +# this software for any purpose. It is provided "as is" without express +# or implied warranty. + +# Invoked by the testrealm target in the top-level Makefile. Creates +# a test realm and spawns a shell pointing at it, for convenience of +# manual testing. + +from k5test import * + +# A list of directories containing programs in the build tree. +progpaths = [ + 'kdc', + os.path.join('kadmin', 'server'), + os.path.join('kadmin', 'cli'), + os.path.join('kadmin', 'dbutil'), + os.path.join('kadmin', 'ktutil'), + os.path.join('clients', 'kinit'), + os.path.join('clients', 'klist'), + os.path.join('clients', 'kdestroy'), + os.path.join('clients', 'kpasswd'), + 'slave' +] + +# Add program directories to the beginning of PATH. +def supplement_path(env): + # Construct prefixes; these will end in a trailing separator. + path_prefix = manpath_prefix = '' + for dir in progpaths: + path_prefix += os.path.join(buildtop, dir) + os.pathsep + + # Assume PATH exists in env for simplicity. + env['PATH'] = path_prefix + env['PATH'] + +realm = K5Realm() +env = realm.env_master.copy() +supplement_path(env) + +print +print 'Realm files are in %s' % realm.testdir +print 'KRB5_CONFIG is %s' % env['KRB5_CONFIG'] +print 'KRB5_KDC_PROFILE is %s' % env['KRB5_KDC_PROFILE'] +print 'KRB5CCNAME is %s' % env['KRB5CCNAME'] +print 'KRB5_KTNAME is %s' % env['KRB5_KTNAME'] +print 'KRB5RCACHEDIR is %s' % env['KRB5RCACHEDIR'] +print 'Password for user is %s' % password('user') +print 'Password for admin is %s' % password('admin') +print + +subprocess.call([os.getenv('SHELL')], env=env) +success('Create test krb5 realm.') -- 2.26.2