Imported Upstream version 4.3.1

This commit is contained in:
Mario Fetka
2021-08-10 02:37:58 +02:00
parent a791de49a2
commit 2f177da8f2
2056 changed files with 421730 additions and 1668138 deletions

View File

@@ -23,27 +23,21 @@ Base class for all XML-RPC tests
from __future__ import print_function
import datetime
import inspect
import unittest
import nose
import contextlib
import six
from ipatests.util import assert_deepequal, Fuzzy
from ipalib import api, request, errors
from ipalib.x509 import valid_issuer
from ipapython.version import API_VERSION
# pylint: disable=no-name-in-module, import-error
if six.PY3:
from collections.abc import Sequence
else:
from collections import Sequence
# pylint: enable=no-name-in-module, import-error
# Matches a gidnumber like '1391016742'
# FIXME: Does it make more sense to return gidnumber, uidnumber, etc. as `int`
# or `long`? If not, we still need to return them as `unicode` instead of `str`.
fuzzy_digits = Fuzzy(r'^\d+$', type=six.string_types)
fuzzy_digits = Fuzzy('^\d+$', type=six.string_types)
uuid_re = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
@@ -55,23 +49,9 @@ fuzzy_automember_dn = Fuzzy(
'^cn=%s,cn=automember rebuild membership,cn=tasks,cn=config$' % uuid_re
)
# base64-encoded value
fuzzy_base64 = Fuzzy('^[0-9A-Za-z/+]+={0,2}$')
def fuzzy_sequence_of(fuzzy):
"""Construct a Fuzzy for a Sequence of values matching the given Fuzzy."""
def test(xs):
if not isinstance(xs, Sequence):
return False
else:
return all(fuzzy == x for x in xs)
return Fuzzy(test=test)
# Matches an automember task finish message
fuzzy_automember_message = Fuzzy(
r'^Automember rebuild task finished\. Processed \(\d+\) entries\.$'
'^Automember rebuild task finished\. Processed \(\d+\) entries\.$'
)
# Matches trusted domain GUID, like u'463bf2be-3456-4a57-979e-120304f2a0eb'
@@ -102,30 +82,22 @@ fuzzy_caacldn = Fuzzy(
'(?i)ipauniqueid=%s,cn=caacls,cn=ca,%s' % (uuid_re, api.env.basedn)
)
# Matches internal CA ID
fuzzy_caid = fuzzy_uuid
# Matches fuzzy ipaUniqueID DN group (RDN)
fuzzy_ipauniqueid = Fuzzy('(?i)ipauniqueid=%s' % uuid_re)
# Matches a hash signature, not enforcing length
fuzzy_hash = Fuzzy(
r'^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types
)
fuzzy_hash = Fuzzy('^([a-f0-9][a-f0-9]:)+[a-f0-9][a-f0-9]$', type=six.string_types)
# Matches a date, like Tue Apr 26 17:45:35 2016 UTC
fuzzy_date = Fuzzy(
r'^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$'
)
fuzzy_date = Fuzzy('^[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} \d{4} UTC$')
fuzzy_issuer = Fuzzy(type=six.string_types)
fuzzy_issuer = Fuzzy(type=six.string_types, test=lambda issuer: valid_issuer(issuer))
fuzzy_hex = Fuzzy(r'^0x[0-9a-fA-F]+$', type=six.string_types)
fuzzy_hex = Fuzzy('^0x[0-9a-fA-F]+$', type=six.string_types)
# Matches password - password consists of all printable characters without
# whitespaces. The only exception is space, but space cannot be at the
# beginning or end of the pwd.
fuzzy_password = Fuzzy(r'^\S([\S ]*\S)*$')
# Matches password - password consists of all printable characters without whitespaces
# The only exception is space, but space cannot be at the beggingin or end of the pwd
fuzzy_password = Fuzzy('^\S([\S ]*\S)*$')
# Matches generalized time value. Time format is: %Y%m%d%H%M%SZ
fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
@@ -133,15 +105,13 @@ fuzzy_dergeneralizedtime = Fuzzy(type=datetime.datetime)
# match any string
fuzzy_string = Fuzzy(type=six.string_types)
fuzzy_bytes = Fuzzy(type=bytes)
# case insensitive match of sets
def fuzzy_set_ci(s):
return Fuzzy(test=lambda other: set(x.lower() for x in other) == set(y.lower() for y in s))
try:
if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect()
api.Backend.rpcclient.connect(fallback=False)
res = api.Command['user_show'](u'notfound')
except errors.NetworkError:
server_available = False
@@ -213,10 +183,10 @@ class XMLRPC_test(object):
@classmethod
def setup_class(cls):
if not server_available:
raise unittest.SkipTest('%r: Server not available: %r' %
raise nose.SkipTest('%r: Server not available: %r' %
(cls.__module__, api.env.xmlrpc_uri))
if not api.Backend.rpcclient.isconnected():
api.Backend.rpcclient.connect()
api.Backend.rpcclient.connect(fallback=False)
@classmethod
def teardown_class(cls):
@@ -264,8 +234,7 @@ EXPECTED = """Expected %r to raise %s.
UNEXPECTED = """Expected %r to raise %s, but caught different.
args = %r
options = %r
expected = %s: %s
got = %s: %s"""
%s: %s"""
KWARGS = """Command %r raised %s with wrong kwargs.
@@ -325,13 +294,14 @@ class Declarative(XMLRPC_test):
(cmd, args, options) = command
print('Cleanup:', cmd, args, options)
if cmd not in api.Command:
raise unittest.SkipTest(
raise nose.SkipTest(
'cleanup command %r not in api.Command' % cmd
)
try:
api.Command[cmd](*args, **options)
except (errors.NotFound, errors.EmptyModlist) as e:
print(e)
pass
def test_command(self, index, declarative_test_definition):
"""Run an individual test
@@ -347,7 +317,7 @@ class Declarative(XMLRPC_test):
(cmd, args, options) = command
options.setdefault('version', self.default_version)
if cmd not in api.Command:
raise unittest.SkipTest('%r not in api.Command' % cmd)
raise nose.SkipTest('%r not in api.Command' % cmd)
if isinstance(expected, errors.PublicError):
self.check_exception(nice, cmd, args, options, expected)
elif hasattr(expected, '__call__'):
@@ -357,20 +327,18 @@ class Declarative(XMLRPC_test):
def check_exception(self, nice, cmd, args, options, expected):
klass = expected.__class__
expected_name = klass.__name__
name = klass.__name__
try:
output = api.Command[cmd](*args, **options)
except Exception as e:
got = e
pass
else:
raise AssertionError(
EXPECTED % (cmd, expected_name, args, options, output)
EXPECTED % (cmd, name, args, options, output)
)
if not isinstance(got, klass):
if not isinstance(e, klass):
raise AssertionError(
UNEXPECTED % (cmd, expected_name, args, options,
expected_name, expected,
got.__class__.__name__, got)
UNEXPECTED % (cmd, name, args, options, e.__class__.__name__, e)
)
# FIXME: the XML-RPC transport doesn't allow us to return structured
# information through the exception, so we can't test the kw on the
@@ -378,26 +346,21 @@ class Declarative(XMLRPC_test):
# transport, the exception is a free-form data structure (dict).
# For now just compare the strings
# pylint: disable=no-member
assert_deepequal(expected.strerror, got.strerror)
assert_deepequal(expected.strerror, e.strerror)
# pylint: enable=no-member
def check_callable(self, nice, cmd, args, options, expected):
expected_name = expected.__class__.__name__
try:
expected_text = inspect.getsource(expected).strip()
except TypeError:
expected_text = str(expected)
name = expected.__class__.__name__
output = dict()
got = None
e = None
try:
output = api.Command[cmd](*args, **options)
except Exception as e:
got = e
if not expected(got, output):
pass
if not expected(e, output):
raise AssertionError(
UNEXPECTED % (cmd, expected_name, args, options,
expected_name, expected_text,
got.__class__.__name__, got)
UNEXPECTED % (cmd, name, args, options,
type(e).__name__, e)
)
def check_output(self, nice, cmd, args, options, expected, extra_check):