Imported Debian patch 4.0.5-6~numeezy

This commit is contained in:
Alexandre Ellert
2016-02-17 15:07:45 +01:00
committed by Mario Fetka
parent c44de33144
commit 10dfc9587b
1203 changed files with 53869 additions and 241462 deletions

View File

@@ -1,3 +0,0 @@
#
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
#

View File

@@ -22,6 +22,7 @@ Base class for all cmdline tests
"""
import nose
import krbV
import distutils.spawn
import os
@@ -32,14 +33,16 @@ from ipatests.test_xmlrpc.xmlrpc_test import XMLRPC_test
from ipaserver.plugins.ldap2 import ldap2
# See if our LDAP server is up and we can talk to it over GSSAPI
ccache = krbV.default_context().default_ccache()
try:
conn = ldap2(api)
conn.connect()
conn = ldap2(shared_instance=False, ldap_uri=api.env.ldap_uri, base_dn=api.env.basedn)
conn.connect(ccache=ccache)
conn.disconnect()
server_available = True
except errors.DatabaseError:
server_available = False
except Exception as e:
except Exception, e:
server_available = False
class cmdline_test(XMLRPC_test):
@@ -49,22 +52,27 @@ class cmdline_test(XMLRPC_test):
# some reasonable default command
command = paths.LS
@classmethod
def setup_class(cls):
def setUp(self):
# Find the executable in $PATH
# This is neded because ipautil.run resets the PATH to
# a system default.
original_command = cls.command
if not os.path.isabs(cls.command):
cls.command = distutils.spawn.find_executable(cls.command)
original_command = self.command
if not os.path.isabs(self.command):
self.command = distutils.spawn.find_executable(self.command)
# raise an error if the command is missing even if the remote
# server is not available.
if not cls.command:
if not self.command:
raise AssertionError(
'Command %r not available' % original_command
)
super(cmdline_test, cls).setup_class()
super(cmdline_test, self).setUp()
if not server_available:
raise nose.SkipTest(
'Server not available: %r' % api.env.xmlrpc_uri
)
def tearDown(self):
"""
nose tear-down fixture.
"""
super(cmdline_test, self).tearDown()

View File

@@ -1,23 +1,15 @@
import shlex
import sys
import contextlib
import StringIO
import nose
import six
from six import StringIO
from ipatests import util
from ipalib import api, errors
from ipapython.version import API_VERSION
import pytest
if six.PY3:
unicode = str
TEST_ZONE = u'zoneadd.%(domain)s' % api.env
@pytest.mark.tier0
class TestCLIParsing(object):
"""Tests that commandlines are correctly parsed to Command keyword args
"""
@@ -45,12 +37,13 @@ class TestCLIParsing(object):
def fake_stdin(self, string_in):
"""Context manager that temporarily replaces stdin to read a string"""
old_stdin = sys.stdin
sys.stdin = StringIO(string_in)
sys.stdin = StringIO.StringIO(string_in)
yield
sys.stdin = old_stdin
def test_ping(self):
self.check_command('ping', 'ping')
self.check_command('ping', 'ping',
version=API_VERSION)
def test_user_show(self):
self.check_command('user-show admin', 'user_show',
@@ -58,7 +51,8 @@ class TestCLIParsing(object):
rights=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_user_show_underscore(self):
self.check_command('user_show admin', 'user_show',
@@ -66,7 +60,8 @@ class TestCLIParsing(object):
rights=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_group_add(self):
self.check_command('group-add tgroup1 --desc="Test group"',
@@ -77,7 +72,8 @@ class TestCLIParsing(object):
external=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_sudocmdgroup_add_member(self):
# Test CSV splitting is not done
@@ -89,7 +85,8 @@ class TestCLIParsing(object):
sudocmd=[u'ab,c', u'd'],
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_group_add_nonposix(self):
self.check_command('group-add tgroup1 --desc="Test group" --nonposix',
@@ -100,7 +97,8 @@ class TestCLIParsing(object):
external=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_group_add_gid(self):
self.check_command('group-add tgroup1 --desc="Test group" --gid=1234',
@@ -112,58 +110,66 @@ class TestCLIParsing(object):
external=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_group_add_interactive(self):
with self.fake_stdin('Test group\n'):
self.check_command('group-add tgroup1', 'group_add',
cn=u'tgroup1',
description=u'Test group',
nonposix=False,
external=False,
no_members=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_dnsrecord_add(self):
self.check_command('dnsrecord-add %s ns --a-rec=1.2.3.4' % TEST_ZONE,
self.check_command('dnsrecord-add test-example.com ns --a-rec=1.2.3.4',
'dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'ns',
arecord=u'1.2.3.4',
structured=False,
force=False,
raw=False,
all=False)
all=False,
version=API_VERSION)
def test_dnsrecord_del_all(self):
try:
self.run_command('dnszone_add', idnsname=TEST_ZONE)
self.run_command('dnszone_add', idnsname=u'test-example.com',
idnssoamname=u'ns.test-example.com', force=True)
except errors.NotFound:
raise nose.SkipTest('DNS is not configured')
try:
self.run_command('dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
idnsname=u'ns', arecord=u'1.2.3.4', force=True)
dnszoneidnsname=u'test-example.com',
idnsname=u'ns', arecord=u'1.2.3.4')
with self.fake_stdin('yes\n'):
self.check_command('dnsrecord_del %s ns' % TEST_ZONE,
self.check_command('dnsrecord_del test-example.com ns',
'dnsrecord_del',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'ns',
del_all=True,
structured=False)
structured=False,
version=API_VERSION)
with self.fake_stdin('YeS\n'):
self.check_command('dnsrecord_del %s ns' % TEST_ZONE,
self.check_command('dnsrecord_del test-example.com ns',
'dnsrecord_del',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'ns',
del_all=True,
structured=False)
structured=False,
version=API_VERSION)
finally:
self.run_command('dnszone_del', idnsname=TEST_ZONE)
self.run_command('dnszone_del', idnsname=u'test-example.com')
def test_dnsrecord_del_one_by_one(self):
try:
self.run_command('dnszone_add', idnsname=TEST_ZONE)
self.run_command('dnszone_add', idnsname=u'test-example.com',
idnssoamname=u'ns.test-example.com', force=True)
except errors.NotFound:
raise nose.SkipTest('DNS is not configured')
try:
@@ -171,26 +177,27 @@ class TestCLIParsing(object):
u'2 1 FD2693C1EFFC11A8D2BE57229212A04B45663791')
for record in records:
self.run_command('dnsrecord_add',
dnszoneidnsname=TEST_ZONE, idnsname=u'ns',
dnszoneidnsname=u'test-example.com', idnsname=u'ns',
sshfprecord=record)
with self.fake_stdin('no\nyes\nyes\n'):
self.check_command('dnsrecord_del %s ns' % TEST_ZONE,
self.check_command('dnsrecord_del test-example.com ns',
'dnsrecord_del',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'ns',
del_all=False,
sshfprecord=records,
structured=False)
structured=False,
version=API_VERSION)
finally:
self.run_command('dnszone_del', idnsname=TEST_ZONE)
self.run_command('dnszone_del', idnsname=u'test-example.com')
def test_dnsrecord_add_ask_for_missing_fields(self):
sshfp_parts = (1, 1, u'E3B72BA346B90570EED94BE9334E34AA795CED23')
with self.fake_stdin('SSHFP\n%d\n%d\n%s' % sshfp_parts):
self.check_command('dnsrecord-add %s sshfp' % TEST_ZONE,
self.check_command('dnsrecord-add test-example.com sshfp',
'dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'sshfp',
sshfp_part_fp_type=sshfp_parts[0],
sshfp_part_algorithm=sshfp_parts[1],
@@ -198,15 +205,16 @@ class TestCLIParsing(object):
structured=False,
raw=False,
all=False,
force=False)
force=False,
version=API_VERSION)
# NOTE: when a DNS record part is passed via command line, it is not
# converted to its base type when transfered via wire
with self.fake_stdin('%d\n%s' % (sshfp_parts[1], sshfp_parts[2])):
self.check_command('dnsrecord-add %s sshfp '
'--sshfp-algorithm=%d' % (TEST_ZONE, sshfp_parts[0]),
self.check_command('dnsrecord-add test-example.com sshfp ' \
'--sshfp-algorithm=%d' % sshfp_parts[0],
'dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'sshfp',
sshfp_part_fp_type=sshfp_parts[0],
sshfp_part_algorithm=unicode(sshfp_parts[1]), # passed via cmdline
@@ -214,14 +222,14 @@ class TestCLIParsing(object):
structured=False,
raw=False,
all=False,
force=False)
force=False,
version=API_VERSION)
with self.fake_stdin(sshfp_parts[2]):
self.check_command('dnsrecord-add %s sshfp '
'--sshfp-algorithm=%d --sshfp-fp-type=%d' % (
TEST_ZONE, sshfp_parts[0], sshfp_parts[1]),
self.check_command('dnsrecord-add test-example.com sshfp ' \
'--sshfp-algorithm=%d --sshfp-fp-type=%d' % (sshfp_parts[0], sshfp_parts[1]),
'dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'sshfp',
sshfp_part_fp_type=unicode(sshfp_parts[0]), # passed via cmdline
sshfp_part_algorithm=unicode(sshfp_parts[1]), # passed via cmdline
@@ -229,31 +237,101 @@ class TestCLIParsing(object):
structured=False,
raw=False,
all=False,
force=False)
force=False,
version=API_VERSION)
def test_dnsrecord_del_comma(self):
try:
self.run_command(
'dnszone_add', idnsname=TEST_ZONE)
'dnszone_add', idnsname=u'test-example.com',
idnssoamname=u'ns.test-example.com', force=True)
except errors.NotFound:
raise nose.SkipTest('DNS is not configured')
try:
self.run_command(
'dnsrecord_add',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'test',
txtrecord=u'"A pretty little problem," said Holmes.')
with self.fake_stdin('no\nyes\n'):
self.check_command(
'dnsrecord_del %s test' % TEST_ZONE,
'dnsrecord_del test-example.com test',
'dnsrecord_del',
dnszoneidnsname=TEST_ZONE,
dnszoneidnsname=u'test-example.com',
idnsname=u'test',
del_all=False,
txtrecord=[u'"A pretty little problem," said Holmes.'],
structured=False)
structured=False,
version=API_VERSION)
finally:
self.run_command('dnszone_del', idnsname=TEST_ZONE)
self.run_command('dnszone_del', idnsname=u'test-example.com')
def test_dnszone_add(self):
"""
Test dnszone-add with nameserver IP passed interatively
"""
# Pass IP of nameserver interactively for nameserver in zone
# (absolute name)
with self.fake_stdin('1.1.1.1\n'):
self.check_command(
'dnszone_add example.com --name-server=ns.example.com. '
'--admin-email=admin@example.com',
'dnszone_add',
idnsname=u'example.com',
idnssoamname=u'ns.example.com.',
idnssoarname=u'admin@example.com',
ip_address=u'1.1.1.1',
idnssoaexpire=util.Fuzzy(type=int),
idnssoaserial=util.Fuzzy(type=int),
idnssoaretry=util.Fuzzy(type=int),
idnssoaminimum=util.Fuzzy(type=int),
idnssoarefresh=util.Fuzzy(type=int),
all=False,
raw=False,
force=False,
version=API_VERSION
)
# Pass IP of nameserver interactively for nameserver in zone
# (relative name)
with self.fake_stdin('1.1.1.1\n'):
self.check_command(
'dnszone_add example.com --name-server=ns '
'--admin-email=admin@example.com',
'dnszone_add',
idnsname=u'example.com',
idnssoamname=u'ns',
idnssoarname=u'admin@example.com',
ip_address=u'1.1.1.1',
idnssoaexpire=util.Fuzzy(type=int),
idnssoaserial=util.Fuzzy(type=int),
idnssoaretry=util.Fuzzy(type=int),
idnssoaminimum=util.Fuzzy(type=int),
idnssoarefresh=util.Fuzzy(type=int),
all=False,
raw=False,
force=False,
version=API_VERSION
)
# Nameserver is outside the zone - no need to pass the IP
self.check_command(
'dnszone_add example.com --name-server=ns.example.net. '
'--admin-email=admin@example.com',
'dnszone_add',
idnsname=u'example.com',
idnssoamname=u'ns.example.net.',
idnssoarname=u'admin@example.com',
idnssoaexpire=util.Fuzzy(type=int),
idnssoaserial=util.Fuzzy(type=int),
idnssoaretry=util.Fuzzy(type=int),
idnssoaminimum=util.Fuzzy(type=int),
idnssoarefresh=util.Fuzzy(type=int),
all=False,
raw=False,
force=False,
version=API_VERSION
)
def test_idrange_add(self):
"""
@@ -271,6 +349,7 @@ class TestCLIParsing(object):
ipasecondarybaserid=500000,
all=False,
raw=False,
version=API_VERSION
)
def test_with_command_line_options():
@@ -285,6 +364,7 @@ class TestCLIParsing(object):
ipasecondarybaserid=u'500000',
all=False,
raw=False,
version=API_VERSION
)
def test_without_options():
@@ -296,6 +376,7 @@ class TestCLIParsing(object):
ipaidrangesize=u'1',
all=False,
raw=False,
version=API_VERSION
)
adtrust_dn = 'cn=ADTRUST,cn=%s,cn=masters,cn=ipa,cn=etc,%s' % \
@@ -310,8 +391,8 @@ class TestCLIParsing(object):
# Create a mock service object to test against
adtrust_add = dict(
ipaconfigstring=b'enabledService',
objectclass=[b'top', b'nsContainer', b'ipaConfigObject']
ipaconfigstring='enabledService',
objectclass=['top', 'nsContainer', 'ipaConfigObject']
)
mockldap = util.MockLDAP()

View File

@@ -19,20 +19,14 @@
import sys
import contextlib
import StringIO
from nose.tools import assert_raises # pylint: disable=E0611
import six
from six import StringIO
from ipalib import api, errors
from ipalib.plugins.user import user_add
import pytest
if six.PY3:
unicode = str
@pytest.mark.tier0
class CLITestContext(object):
"""Context manager that replaces stdout & stderr, and catches SystemExit
@@ -47,8 +41,8 @@ class CLITestContext(object):
def __enter__(self):
self.old_streams = sys.stdout, sys.stderr
self.stdout_fileobj = sys.stdout = StringIO()
self.stderr_fileobj = sys.stderr = StringIO()
self.stdout_fileobj = sys.stdout = StringIO.StringIO()
self.stderr_fileobj = sys.stderr = StringIO.StringIO()
return self
def __exit__(self, exc_type, exc_value, traceback):

View File

@@ -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):