#!/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')
* 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).
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
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
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