svn rev #25826: trunk/src/ tests/ util/

ghudson@MIT.EDU ghudson at MIT.EDU
Thu Apr 26 00:34:15 EDT 2012


http://src.mit.edu/fisheye/changelog/krb5/?cs=25826
Commit By: ghudson
Log Message:
Add k5test.py helpers for running kadmin

Add K5Realm.prep_kadmin() to create a ccache and K5Realm.run_kadmin()
to run a kadmin query using it.  Modify t_stringattr.py to use these
helpers instead of its own.


Changed Files:
U   trunk/src/tests/t_stringattr.py
U   trunk/src/util/k5test.py
Modified: trunk/src/tests/t_stringattr.py
===================================================================
--- trunk/src/tests/t_stringattr.py	2012-04-26 04:33:48 UTC (rev 25825)
+++ trunk/src/tests/t_stringattr.py	2012-04-26 04:34:15 UTC (rev 25826)
@@ -23,32 +23,28 @@
 #!/usr/bin/python
 from k5test import *
 
-def run_kadmin(query):
-    global realm
-    return realm.run_as_master([kadmin, '-c', realm.ccache, '-q', query])
-
 realm = K5Realm(start_kadmind=True, create_host=False, get_creds=False)
 
-realm.kinit(realm.admin_princ, password('admin'), flags=['-S', 'kadmin/admin'])
+realm.prep_kadmin()
 
-output = run_kadmin('getstrs user')
+output = realm.run_kadmin('getstrs user')
 if '(No string attributes.)' not in output:
     fail('Empty attribute query')
 
-output = run_kadmin('setstr user attr1 value1')
+output = realm.run_kadmin('setstr user attr1 value1')
 if 'Attribute set for principal' not in output:
     fail('Setting attr1')
-output = run_kadmin('setstr user attr2 value2')
+output = realm.run_kadmin('setstr user attr2 value2')
 if 'Attribute set for principal' not in output:
     fail('Setting attr2')
-output = run_kadmin('delstr user attr1')
+output = realm.run_kadmin('delstr user attr1')
 if 'Attribute removed from principal' not in output:
     fail('Deleting attr1')
-output = run_kadmin('setstr user attr3 value3')
+output = realm.run_kadmin('setstr user attr3 value3')
 if 'Attribute set for principal' not in output:
     fail('Setting attr3')
 
-output = run_kadmin('getstrs user')
+output = realm.run_kadmin('getstrs user')
 if 'attr2: value2' not in output or 'attr3: value3' not in output or \
         'attr1:' in output:
     fail('Final attribute query')

Modified: trunk/src/util/k5test.py
===================================================================
--- trunk/src/util/k5test.py	2012-04-26 04:33:48 UTC (rev 25825)
+++ trunk/src/util/k5test.py	2012-04-26 04:34:15 UTC (rev 25826)
@@ -279,6 +279,15 @@
 
 * realm.run_kadminl(query): Run the specified query in kadmin.local.
 
+* realm.prep_kadmin(princname=None, password=None, flags=[]): Populate
+  realm.kadmin_ccache with a ticket which can be used to run kadmin.
+  If princname is not specified, realm.admin_princ and its default
+  password will be used.
+
+* realm.run_kadmin(query, **keywords): Run the specified query in
+  kadmin, using realm.kadmin_ccache to authenticate.  Accepts the same
+  keyword arguments as run_as_client.
+
 * realm.realm: The realm's name.
 
 * realm.testdir: The realm's storage directory (absolute path).
@@ -301,6 +310,9 @@
   credentials for user unless disabled by the realm construction
   options.
 
+* realm.kadmin_ccache: The ccache file initialized by prep_kadmin and
+  used by run_kadmin.
+
 * Attributes for the client, server, master, and slave environments.
   These environments are extensions of os.environ.
   - realm.env_client
@@ -689,6 +701,7 @@
         self.krbtgt_princ = 'krbtgt/%s@%s' % (self.realm, self.realm)
         self.keytab = os.path.join(self.testdir, 'keytab')
         self.ccache = os.path.join(self.testdir, 'ccache')
+        self.kadmin_ccache = os.path.join(self.testdir, 'kadmin_ccache')
         self._krb5_conf = _cfg_merge(_default_krb5_conf, krb5_conf)
         self._kdc_conf = _cfg_merge(_default_kdc_conf, kdc_conf)
         self._kdc_proc = None
@@ -917,7 +930,19 @@
         global kadmin_local
         return self.run_as_master([kadmin_local, '-q', query])
 
+    def prep_kadmin(self, princname=None, pw=None, flags=[]):
+        if princname is None:
+            princname = self.admin_princ
+            pw = password('admin')
+        return self.kinit(princname, pw,
+                          flags=['-S', 'kadmin/admin',
+                                 '-c', self.kadmin_ccache] + flags)
 
+    def run_kadmin(self, query, **keywords):
+        return self.run_as_client([kadmin, '-c', self.kadmin_ccache,
+                                   '-q', query], **keywords)
+
+
 def multipass_realms(**keywords):
     global _current_pass, _passes, testpass
     caller_krb5_conf = keywords.get('krb5_conf')



More information about the cvs-krb5 mailing list