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,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()