Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -22,40 +22,39 @@ Test `ipa-getkeytab`
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import gssapi
|
||||
import nose
|
||||
import pytest
|
||||
|
||||
from cmdline import cmdline_test
|
||||
from ipalib import api
|
||||
from ipalib import errors
|
||||
from ipapython import ipautil, ipaldap
|
||||
import tempfile
|
||||
from ipapython import ipautil
|
||||
import nose
|
||||
import tempfile
|
||||
import krbV
|
||||
from ipaserver.plugins.ldap2 import ldap2
|
||||
from ipapython.dn import DN
|
||||
from ipatests.test_cmdline.cmdline import cmdline_test
|
||||
|
||||
def use_keytab(principal, keytab):
|
||||
try:
|
||||
tmpdir = tempfile.mkdtemp(prefix = "tmp-")
|
||||
ccache_file = 'FILE:%s/ccache' % tmpdir
|
||||
name = gssapi.Name(principal, gssapi.NameType.kerberos_principal)
|
||||
store = {'ccache': ccache_file,
|
||||
'client_keytab': keytab}
|
||||
krbcontext = krbV.default_context()
|
||||
principal = str(principal)
|
||||
keytab = krbV.Keytab(name=keytab, context=krbcontext)
|
||||
principal = krbV.Principal(name=principal, context=krbcontext)
|
||||
os.environ['KRB5CCNAME'] = ccache_file
|
||||
gssapi.Credentials(name=name, usage='initiate', store=store)
|
||||
conn = ldap2(api)
|
||||
conn.connect(autobind=ipaldap.AUTOBIND_DISABLED)
|
||||
ccache = krbV.CCache(name=ccache_file, context=krbcontext, primary_principal=principal)
|
||||
ccache.init(principal)
|
||||
ccache.init_creds_keytab(keytab=keytab, principal=principal)
|
||||
conn = ldap2(shared_instance=False, ldap_uri=api.env.ldap_uri, base_dn=api.env.basedn)
|
||||
conn.connect(ccache=ccache)
|
||||
conn.disconnect()
|
||||
except gssapi.exceptions.GSSError as e:
|
||||
raise Exception('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal, keytab, str(e)))
|
||||
except krbV.Krb5Error, e:
|
||||
raise StandardError('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal.name, keytab, str(e)))
|
||||
finally:
|
||||
os.environ.pop('KRB5CCNAME', None)
|
||||
del os.environ['KRB5CCNAME']
|
||||
if tmpdir:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
class test_ipagetkeytab(cmdline_test):
|
||||
"""
|
||||
Test `ipa-getkeytab`.
|
||||
@@ -86,11 +85,8 @@ class test_ipagetkeytab(cmdline_test):
|
||||
"-p", "test/notfound.example.com",
|
||||
"-k", self.keytabname,
|
||||
]
|
||||
result = ipautil.run(new_args, stdin=None, raiseonerr=False,
|
||||
capture_error=True)
|
||||
err = result.error_output
|
||||
(out, err, rc) = ipautil.run(new_args, stdin=None, raiseonerr=False)
|
||||
assert 'Failed to parse result: PrincipalName not found.\n' in err, err
|
||||
rc = result.returncode
|
||||
assert rc > 0, rc
|
||||
|
||||
def test_2_run(self):
|
||||
@@ -111,12 +107,11 @@ class test_ipagetkeytab(cmdline_test):
|
||||
"-k", self.keytabname,
|
||||
]
|
||||
try:
|
||||
result = ipautil.run(new_args, None, capture_error=True)
|
||||
(out, err, rc) = ipautil.run(new_args, None)
|
||||
expected = 'Keytab successfully retrieved and stored in: %s\n' % (
|
||||
self.keytabname)
|
||||
assert expected in result.error_output, (
|
||||
'Success message not in output:\n%s' % result.error_output)
|
||||
except ipautil.CalledProcessError as e:
|
||||
assert expected in err, 'Success message not in output:\n%s' % err
|
||||
except ipautil.CalledProcessError, e:
|
||||
assert (False)
|
||||
|
||||
def test_3_use(self):
|
||||
@@ -146,7 +141,7 @@ class test_ipagetkeytab(cmdline_test):
|
||||
"""
|
||||
try:
|
||||
use_keytab(self.service_princ, self.keytabname)
|
||||
except Exception as errmsg:
|
||||
except StandardError, errmsg:
|
||||
assert('Unable to bind to LDAP. Error initializing principal' in str(errmsg))
|
||||
|
||||
def test_9_cleanup(self):
|
||||
|
||||
Reference in New Issue
Block a user