Imported Debian patch 4.8.10-2
This commit is contained in:
committed by
Mario Fetka
parent
8bc559c5a1
commit
358acdd85f
@@ -22,10 +22,6 @@ Test the `ipalib.backend` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
# pylint: disable=maybe-no-member
|
||||
|
||||
import threading
|
||||
from ipatests.util import ClassChecker, raises, create_test_api
|
||||
from ipatests.data import unicode_str
|
||||
@@ -49,7 +45,7 @@ class test_Backend(ClassChecker):
|
||||
assert self.cls.__bases__ == (plugable.Plugin,)
|
||||
|
||||
|
||||
class Disconnect(object):
|
||||
class Disconnect:
|
||||
called = False
|
||||
|
||||
def __init__(self, id=None):
|
||||
|
||||
@@ -108,7 +108,7 @@ def test_lock():
|
||||
assert str(e) == 'already locked: %r' % o
|
||||
|
||||
# Test with another class implemented locking protocol:
|
||||
class Lockable(object):
|
||||
class Lockable:
|
||||
__locked = False
|
||||
def __lock__(self):
|
||||
self.__locked = True
|
||||
@@ -122,7 +122,7 @@ def test_lock():
|
||||
assert str(e) == 'already locked: %r' % o
|
||||
|
||||
# Test with a class incorrectly implementing the locking protocol:
|
||||
class Broken(object):
|
||||
class Broken:
|
||||
def __lock__(self):
|
||||
pass
|
||||
def __islocked__(self):
|
||||
@@ -145,7 +145,7 @@ def test_islocked():
|
||||
assert f(o) is True
|
||||
|
||||
# Test with another class implemented locking protocol:
|
||||
class Lockable(object):
|
||||
class Lockable:
|
||||
__locked = False
|
||||
def __lock__(self):
|
||||
self.__locked = True
|
||||
@@ -157,7 +157,7 @@ def test_islocked():
|
||||
assert f(o) is True
|
||||
|
||||
# Test with a class incorrectly implementing the locking protocol:
|
||||
class Broken(object):
|
||||
class Broken:
|
||||
__lock__ = False
|
||||
def __islocked__(self):
|
||||
return False
|
||||
@@ -207,7 +207,7 @@ def membername(i):
|
||||
return 'member%03d' % i
|
||||
|
||||
|
||||
class DummyMember(object):
|
||||
class DummyMember:
|
||||
def __init__(self, i):
|
||||
self.i = i
|
||||
self.name = self.__name__ = membername(i)
|
||||
|
||||
@@ -76,7 +76,7 @@ def get_cmd_name(i):
|
||||
return 'cmd_%d' % i
|
||||
|
||||
|
||||
class DummyCommand(object):
|
||||
class DummyCommand:
|
||||
def __init__(self, name):
|
||||
self.__name = name
|
||||
|
||||
@@ -85,7 +85,7 @@ class DummyCommand(object):
|
||||
name = property(__get_name)
|
||||
|
||||
|
||||
class DummyAPI(object):
|
||||
class DummyAPI:
|
||||
def __init__(self, cnt):
|
||||
self.__cmd = plugable.APINameSpace(self.__cmd_iter(cnt), DummyCommand)
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ Test the `ipalib.config` module.
|
||||
"""
|
||||
|
||||
from os import path
|
||||
import site
|
||||
import sys
|
||||
|
||||
from ipatests.util import raises, delitem, ClassChecker
|
||||
from ipatests.util import getitem
|
||||
from ipatests.util import TempDir, TempHome
|
||||
@@ -447,23 +449,39 @@ class test_Env(ClassChecker):
|
||||
assert o.bin == path.dirname(path.abspath(sys.argv[0]))
|
||||
assert o.home == home.path
|
||||
assert o.dot_ipa == home.join('.ipa')
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
assert o.confdir == '/etc/ipa'
|
||||
assert o.conf == '/etc/ipa/default.conf'
|
||||
assert o.conf_default == o.conf
|
||||
if (
|
||||
# venv site module doesn't have getsitepackages()
|
||||
not hasattr(site, "getsitepackages")
|
||||
or o.site_packages in site.getsitepackages()
|
||||
):
|
||||
assert o.in_tree is False
|
||||
assert o.confdir == '/etc/ipa'
|
||||
assert o.conf == '/etc/ipa/default.conf'
|
||||
assert o.conf_default == o.conf
|
||||
else:
|
||||
assert o.in_tree is True
|
||||
assert o.confdir == o.dot_ipa
|
||||
assert o.conf == home.join('.ipa/default.conf')
|
||||
assert o.conf_default == o.conf
|
||||
|
||||
# Test overriding values created by _bootstrap()
|
||||
(o, home) = self.bootstrap(in_tree='True', context='server')
|
||||
assert o.in_tree is True
|
||||
assert o.context == 'server'
|
||||
assert o.conf == home.join('.ipa', 'server.conf')
|
||||
(o, home) = self.bootstrap(conf='/my/wacky/whatever.conf')
|
||||
|
||||
o, home = self.bootstrap(
|
||||
conf='/my/wacky/whatever.conf', in_tree=False
|
||||
)
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
assert o.conf == '/my/wacky/whatever.conf'
|
||||
assert o.conf_default == '/etc/ipa/default.conf'
|
||||
(o, home) = self.bootstrap(conf_default='/my/wacky/default.conf')
|
||||
|
||||
o, home = self.bootstrap(
|
||||
conf_default='/my/wacky/default.conf', in_tree=False
|
||||
)
|
||||
assert o.in_tree is False
|
||||
assert o.context == 'default'
|
||||
assert o.conf == '/etc/ipa/default.conf'
|
||||
|
||||
@@ -41,7 +41,7 @@ if six.PY3:
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class PrivateExceptionTester(object):
|
||||
class PrivateExceptionTester:
|
||||
_klass = None
|
||||
__klass = None
|
||||
|
||||
@@ -193,7 +193,7 @@ class test_PluginMissingOverrideError(PrivateExceptionTester):
|
||||
##############################################################################
|
||||
# Unit tests for public errors:
|
||||
|
||||
class PublicExceptionTester(object):
|
||||
class PublicExceptionTester:
|
||||
_klass = None
|
||||
__klass = None
|
||||
|
||||
@@ -338,7 +338,7 @@ class test_PublicError(PublicExceptionTester):
|
||||
assert_equal(list(inst_match),list(instructions))
|
||||
|
||||
|
||||
class BaseMessagesTest(object):
|
||||
class BaseMessagesTest:
|
||||
"""Generic test for all of a module's errors or messages
|
||||
"""
|
||||
def test_public_messages(self):
|
||||
@@ -367,7 +367,7 @@ class BaseMessagesTest(object):
|
||||
pass
|
||||
|
||||
|
||||
class test_PublicErrors(object):
|
||||
class test_PublicErrors:
|
||||
message_list = errors.public_errors
|
||||
errno_range = list(range(900, 5999))
|
||||
required_classes = (Exception, errors.PublicError)
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
Test the `ipalib.frontend` module.
|
||||
"""
|
||||
|
||||
# FIXME: Pylint errors
|
||||
# pylint: disable=no-member
|
||||
import pytest
|
||||
import six
|
||||
|
||||
@@ -71,7 +69,7 @@ def test_is_rule():
|
||||
is_rule = frontend.is_rule
|
||||
flag = frontend.RULE_FLAG
|
||||
|
||||
class no_call(object):
|
||||
class no_call:
|
||||
def __init__(self, value):
|
||||
if value is not None:
|
||||
assert value in (True, False)
|
||||
@@ -199,7 +197,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Return a standard subclass of `ipalib.frontend.Command`.
|
||||
"""
|
||||
class Rule(object):
|
||||
class Rule:
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
@@ -232,7 +230,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Helper method used to test args and options.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -278,7 +276,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.args`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -335,7 +333,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.options`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -359,7 +357,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the ``ipalib.frontend.Command.output`` instance attribute.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -407,7 +405,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.convert` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -424,7 +422,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.normalize` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -472,7 +470,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.validate` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
env = config.Env(context='cli')
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
@@ -691,7 +689,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.validate_output` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -733,7 +731,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` per-type validation.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -762,7 +760,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test `ipalib.frontend.Command.validate_output` nested validation.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -797,7 +795,7 @@ class test_Command(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.Command.get_output_params` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -833,7 +831,7 @@ class test_LocalOrRemote(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.frontend.LocalOrRemote.__init__` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -916,7 +914,7 @@ class test_Object(ClassChecker):
|
||||
Test the `ipalib.frontend.Object.__init__` method.
|
||||
"""
|
||||
# Setup for test:
|
||||
class DummyAttribute(object):
|
||||
class DummyAttribute:
|
||||
def __init__(self, obj_name, attr_name, name=None):
|
||||
self.obj_name = obj_name
|
||||
self.attr_name = attr_name
|
||||
@@ -944,7 +942,7 @@ class test_Object(ClassChecker):
|
||||
cnt = 10
|
||||
methods_format = 'method_%d'
|
||||
|
||||
class FakeAPI(object):
|
||||
class FakeAPI:
|
||||
def __init__(self):
|
||||
self._API__plugins = get_attributes(cnt, methods_format)
|
||||
self._API__default_map = {}
|
||||
@@ -1113,13 +1111,16 @@ class test_Attribute(ClassChecker):
|
||||
Test the `ipalib.frontend.Attribute.__init__` method.
|
||||
"""
|
||||
user_obj = 'The user frontend.Object instance'
|
||||
class api(object):
|
||||
|
||||
class api:
|
||||
Object = {("user", "1"): user_obj}
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
|
||||
class user_add(self.cls):
|
||||
pass
|
||||
|
||||
o = user_add(api)
|
||||
assert read_only(o, 'api') is api
|
||||
assert read_only(o, 'obj') is user_obj
|
||||
|
||||
@@ -31,12 +31,11 @@ import re
|
||||
import sys
|
||||
from decimal import Decimal
|
||||
from inspect import isclass
|
||||
from xmlrpc.client import MAXINT, MININT
|
||||
|
||||
import pytest
|
||||
|
||||
import six
|
||||
# pylint: disable=import-error
|
||||
from six.moves.xmlrpc_client import MAXINT, MININT
|
||||
# pylint: enable=import-error
|
||||
from cryptography import x509 as crypto_x509
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
@@ -173,7 +172,7 @@ def test_parse_param_spec():
|
||||
assert str(e) == TYPE_ERROR % ('spec', str, bad_value, type(bad_value))
|
||||
|
||||
|
||||
class DummyRule(object):
|
||||
class DummyRule:
|
||||
def __init__(self, error=None):
|
||||
assert error is None or type(error) is unicode
|
||||
self.error = error
|
||||
@@ -581,7 +580,7 @@ class test_Param(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.parameters.Param.get_default` method.
|
||||
"""
|
||||
class PassThrough(object):
|
||||
class PassThrough:
|
||||
value = None
|
||||
|
||||
def __call__(self, value):
|
||||
@@ -681,7 +680,7 @@ class test_Data(ClassChecker):
|
||||
Test the `ipalib.parameters.Data.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_data')
|
||||
assert o.type is type(None)
|
||||
assert o.type is type(None) # noqa
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -1222,7 +1221,7 @@ class test_Number(ClassChecker):
|
||||
Test the `ipalib.parameters.Number.__init__` method.
|
||||
"""
|
||||
o = self.cls('my_number')
|
||||
assert o.type is type(None)
|
||||
assert o.type is type(None) # noqa
|
||||
assert o.password is False
|
||||
assert o.rules == tuple()
|
||||
assert o.class_rules == tuple()
|
||||
@@ -1243,7 +1242,7 @@ class test_Int(ClassChecker):
|
||||
# Test with no kwargs:
|
||||
o = self.cls('my_number')
|
||||
assert o.type == int
|
||||
assert o.allowed_types == six.integer_types
|
||||
assert o.allowed_types == (int,)
|
||||
assert isinstance(o, parameters.Int)
|
||||
assert o.minvalue == int(MININT)
|
||||
assert o.maxvalue == int(MAXINT)
|
||||
|
||||
@@ -25,6 +25,7 @@ Test the `ipalib.plugable` module.
|
||||
# pylint: disable=no-member
|
||||
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
from ipalib import plugable, errors, create_api
|
||||
@@ -35,6 +36,7 @@ import pytest
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class test_Plugin(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin` class.
|
||||
@@ -76,19 +78,11 @@ class test_Plugin(ClassChecker):
|
||||
assert o.summary == u'<%s.%s>' % (another_subclass.__module__,
|
||||
another_subclass.__name__)
|
||||
|
||||
# Test that Plugin makes sure the subclass hasn't defined attributes
|
||||
# whose names conflict with the logger methods set in Plugin.__init__():
|
||||
class check(self.cls):
|
||||
info = 'whatever'
|
||||
e = raises(Exception, check, api)
|
||||
assert str(e) == \
|
||||
"info is already bound to ipatests.test_ipalib.test_plugable.check()"
|
||||
|
||||
def test_finalize(self):
|
||||
"""
|
||||
Test the `ipalib.plugable.Plugin.finalize` method.
|
||||
"""
|
||||
class api(object):
|
||||
class api:
|
||||
@staticmethod
|
||||
def is_production_mode():
|
||||
return False
|
||||
@@ -102,14 +96,15 @@ def test_Registry():
|
||||
"""
|
||||
Test the `ipalib.plugable.Registry` class
|
||||
"""
|
||||
class Base1(object):
|
||||
pass
|
||||
class Base2(object):
|
||||
class Base1:
|
||||
pass
|
||||
|
||||
class Base2:
|
||||
pass
|
||||
|
||||
class plugin1(Base1):
|
||||
pass
|
||||
|
||||
class plugin2(Base2):
|
||||
pass
|
||||
|
||||
@@ -307,3 +302,44 @@ class test_API(ClassChecker):
|
||||
os.environ['IPA_CONFDIR'] = ipa_confdir
|
||||
else:
|
||||
os.environ.pop('IPA_CONFDIR')
|
||||
|
||||
|
||||
class test_cli(ClassChecker):
|
||||
"""
|
||||
Test the `ipalib.plugable` global bootstrap.
|
||||
"""
|
||||
def test_no_args(self):
|
||||
sys.argv = ['/usr/bin/ipa']
|
||||
api = create_api(mode='unit_test')
|
||||
(_options, argv) = api.bootstrap_with_global_options(
|
||||
context='unit_test')
|
||||
assert len(argv) == 0
|
||||
assert _options.env is None
|
||||
assert _options.conf is None
|
||||
assert _options.debug is None
|
||||
assert _options.delegate is None
|
||||
assert _options.verbose is None
|
||||
|
||||
def test_one_arg(self):
|
||||
sys.argv = ['/usr/bin/ipa', 'user-show']
|
||||
api = create_api(mode='unit_test')
|
||||
(_options, argv) = api.bootstrap_with_global_options(
|
||||
context='unit_test')
|
||||
assert argv == ['user-show']
|
||||
assert _options.verbose is None
|
||||
|
||||
def test_args_valid_option(self):
|
||||
sys.argv = ['/usr/bin/ipa', '-v', 'user-show']
|
||||
api = create_api(mode='unit_test')
|
||||
(_options, argv) = api.bootstrap_with_global_options(
|
||||
context='unit_test')
|
||||
assert argv == ['user-show']
|
||||
assert _options.verbose == 1
|
||||
|
||||
def test_args_invalid_option(self):
|
||||
sys.argv = ['/usr/bin/ipa', '-verbose', 'user-show']
|
||||
api = create_api(mode='unit_test')
|
||||
try:
|
||||
api.bootstrap_with_global_options(context='unit_test')
|
||||
except errors.OptionError as e:
|
||||
assert e.msg == 'Unable to parse option rbose'
|
||||
|
||||
@@ -22,21 +22,18 @@ Test the `ipalib.rpc` module.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import unittest
|
||||
from xmlrpc.client import Binary, Fault, dumps, loads
|
||||
import urllib
|
||||
|
||||
import pytest
|
||||
import six
|
||||
# pylint: disable=import-error
|
||||
from six.moves.xmlrpc_client import Binary, Fault, dumps, loads
|
||||
# pylint: enable=import-error
|
||||
from six.moves import urllib
|
||||
|
||||
from ipatests.util import raises, assert_equal, PluginTester, DummyClass
|
||||
from ipatests.util import Fuzzy
|
||||
from ipatests.data import binary_bytes, utf8_bytes, unicode_str
|
||||
from ipalib.frontend import Command
|
||||
from ipalib.request import context, Connection
|
||||
from ipalib import rpc, errors, api, request
|
||||
from ipalib import rpc, errors, api, request as ipa_request
|
||||
from ipapython.version import API_VERSION
|
||||
|
||||
if six.PY3:
|
||||
@@ -76,7 +73,6 @@ def test_round_trip():
|
||||
if six.PY2:
|
||||
assert_equal(dump_n_load(utf8_bytes), unicode_str)
|
||||
assert_equal(dump_n_load(unicode_str), unicode_str)
|
||||
# "Binary" is not "str". pylint: disable=no-member
|
||||
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
||||
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
||||
assert type(dump_n_load(b'hello')) is output_binary_type
|
||||
@@ -113,7 +109,6 @@ def test_xml_wrap():
|
||||
assert f({}, API_VERSION) == dict()
|
||||
b = f(b'hello', API_VERSION)
|
||||
assert isinstance(b, Binary)
|
||||
# "Binary" is not "dict" or "tuple". pylint: disable=no-member
|
||||
assert b.data == b'hello'
|
||||
u = f(u'hello', API_VERSION)
|
||||
assert type(u) is unicode
|
||||
@@ -262,18 +257,18 @@ class test_xmlclient(PluginTester):
|
||||
|
||||
@pytest.mark.skip_ipaclient_unittest
|
||||
@pytest.mark.needs_ipaapi
|
||||
class test_xml_introspection(object):
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
class test_xml_introspection:
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def xml_introsp_setup(self, request):
|
||||
try:
|
||||
api.Backend.xmlclient.connect()
|
||||
except (errors.NetworkError, IOError):
|
||||
raise unittest.SkipTest('%r: Server not available: %r' %
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
pytest.skip('%r: Server not available: %r' %
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
request.destroy_context()
|
||||
def fin():
|
||||
ipa_request.destroy_context()
|
||||
request.addfinalizer(fin)
|
||||
|
||||
def test_list_methods(self):
|
||||
result = api.Backend.xmlclient.conn.system.listMethods()
|
||||
@@ -353,16 +348,18 @@ class test_rpcclient_context(PluginTester):
|
||||
"""
|
||||
Test the context in `ipalib.rpc.rpcclient` plugin.
|
||||
"""
|
||||
def setup(self):
|
||||
@pytest.fixture(autouse=True)
|
||||
def rpcclient_context_fsetup(self, request):
|
||||
try:
|
||||
api.Backend.rpcclient.connect(ca_certfile='foo')
|
||||
except (errors.NetworkError, IOError):
|
||||
raise unittest.SkipTest('%r: Server not available: %r' %
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
pytest.skip('%r: Server not available: %r' %
|
||||
(__name__, api.env.xmlrpc_uri))
|
||||
|
||||
def teardown(self):
|
||||
if api.Backend.rpcclient.isconnected():
|
||||
api.Backend.rpcclient.disconnect()
|
||||
def fin():
|
||||
if api.Backend.rpcclient.isconnected():
|
||||
api.Backend.rpcclient.disconnect()
|
||||
request.addfinalizer(fin)
|
||||
|
||||
def test_context_cafile(self):
|
||||
"""
|
||||
|
||||
@@ -25,7 +25,6 @@ from __future__ import print_function
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import six
|
||||
import pytest
|
||||
@@ -50,7 +49,7 @@ def test_create_translation():
|
||||
assert context.__dict__[key] is t
|
||||
|
||||
|
||||
class test_TestLang(object):
|
||||
class test_TestLang:
|
||||
lang_env_vars = {'LC_ALL', 'LC_MESSAGES', 'LANGUAGE', 'LANG'}
|
||||
|
||||
def setup_lang(self):
|
||||
@@ -77,7 +76,8 @@ class test_TestLang(object):
|
||||
|
||||
os.environ.update(self.saved_locale)
|
||||
|
||||
def setup(self):
|
||||
@pytest.fixture(autouse=True)
|
||||
def testlang_setup(self, request):
|
||||
self.tmp_dir = None
|
||||
self.setup_lang()
|
||||
|
||||
@@ -102,26 +102,27 @@ class test_TestLang(object):
|
||||
|
||||
result = create_po(self.pot_file, self.po_file, self.mo_file)
|
||||
if result:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Unable to create po file "%s" & mo file "%s" from pot '
|
||||
'file "%s"' % (self.po_file, self.mo_file, self.pot_file)
|
||||
)
|
||||
|
||||
if not os.path.isfile(self.po_file):
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Test po file unavailable: {}'.format(self.po_file))
|
||||
|
||||
if not os.path.isfile(self.mo_file):
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Test mo file unavailable: {}'.format(self.mo_file))
|
||||
|
||||
self.po_file_iterate = po_file_iterate
|
||||
|
||||
def teardown(self):
|
||||
self.teardown_lang()
|
||||
def fin():
|
||||
self.teardown_lang()
|
||||
|
||||
if self.tmp_dir is not None:
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
if self.tmp_dir is not None:
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
request.addfinalizer(fin)
|
||||
|
||||
def test_test_lang(self):
|
||||
print("test_test_lang")
|
||||
@@ -148,7 +149,8 @@ class test_TestLang(object):
|
||||
result = self.po_file_iterate(self.po_file, get_msgstr, get_msgstr_plural)
|
||||
assert result == 0
|
||||
|
||||
class test_LazyText(object):
|
||||
|
||||
class test_LazyText:
|
||||
|
||||
klass = text.LazyText
|
||||
|
||||
@@ -159,7 +161,7 @@ class test_LazyText(object):
|
||||
assert inst.key == ('foo', 'bar')
|
||||
|
||||
|
||||
class test_FixMe(object):
|
||||
class test_FixMe:
|
||||
klass = text.FixMe
|
||||
|
||||
def test_init(self):
|
||||
@@ -178,7 +180,7 @@ class test_FixMe(object):
|
||||
assert type(unicode(inst)) is unicode
|
||||
|
||||
|
||||
class test_Gettext(object):
|
||||
class test_Gettext:
|
||||
|
||||
klass = text.Gettext
|
||||
|
||||
@@ -186,7 +188,7 @@ class test_Gettext(object):
|
||||
inst = self.klass('what up?', 'foo', 'bar')
|
||||
assert inst.domain == 'foo'
|
||||
assert inst.localedir == 'bar'
|
||||
assert inst.msg is 'what up?'
|
||||
assert inst.msg == 'what up?'
|
||||
assert inst.args == ('what up?', 'foo', 'bar')
|
||||
|
||||
def test_repr(self):
|
||||
@@ -241,7 +243,7 @@ class test_Gettext(object):
|
||||
assert (inst4 != inst1) is True
|
||||
|
||||
|
||||
class test_NGettext(object):
|
||||
class test_NGettext:
|
||||
|
||||
klass = text.NGettext
|
||||
|
||||
@@ -320,7 +322,7 @@ class test_NGettext(object):
|
||||
assert (inst4 != inst1) is True
|
||||
|
||||
|
||||
class test_GettextFactory(object):
|
||||
class test_GettextFactory:
|
||||
|
||||
klass = text.GettextFactory
|
||||
|
||||
@@ -348,12 +350,12 @@ class test_GettextFactory(object):
|
||||
inst = self.klass('foo', 'bar')
|
||||
g = inst('what up?')
|
||||
assert type(g) is text.Gettext
|
||||
assert g.msg is 'what up?'
|
||||
assert g.msg == 'what up?'
|
||||
assert g.domain == 'foo'
|
||||
assert g.localedir == 'bar'
|
||||
|
||||
|
||||
class test_NGettextFactory(object):
|
||||
class test_NGettextFactory:
|
||||
|
||||
klass = text.NGettextFactory
|
||||
|
||||
@@ -387,7 +389,7 @@ class test_NGettextFactory(object):
|
||||
assert ng.localedir == 'bar'
|
||||
|
||||
|
||||
class test_ConcatenatedText(object):
|
||||
class test_ConcatenatedText:
|
||||
|
||||
klass = text.ConcatenatedLazyText
|
||||
|
||||
|
||||
77
ipatests/test_ipalib/test_util.py
Normal file
77
ipatests/test_ipalib/test_util.py
Normal file
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# Copyright (C) 2018 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
"""Tests for ipalib.util module
|
||||
"""
|
||||
|
||||
import os
|
||||
import ssl
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from ipalib.util import (
|
||||
get_pager, create_https_connection, get_proper_tls_version_span
|
||||
)
|
||||
from ipaplatform.constants import constants
|
||||
|
||||
|
||||
@pytest.mark.parametrize('pager,expected_result', [
|
||||
# Valid values
|
||||
('cat', '/bin/cat'),
|
||||
('/bin/cat', '/bin/cat'),
|
||||
# Invalid values (wrong command, package is not installed, etc)
|
||||
('cat_', None),
|
||||
('', None)
|
||||
])
|
||||
def test_get_pager(pager, expected_result):
|
||||
with mock.patch.dict(os.environ, {'PAGER': pager}):
|
||||
pager = get_pager()
|
||||
assert(pager == expected_result or pager.endswith(expected_result))
|
||||
|
||||
|
||||
BASE_CTX = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||
if constants.TLS_HIGH_CIPHERS is not None:
|
||||
BASE_CTX.set_ciphers(constants.TLS_HIGH_CIPHERS)
|
||||
else:
|
||||
BASE_CTX.set_ciphers("PROFILE=SYSTEM")
|
||||
|
||||
# options: IPA still supports Python 3.6 without min/max version setters
|
||||
BASE_OPT = BASE_CTX.options
|
||||
BASE_OPT |= (
|
||||
ssl.OP_ALL | ssl.OP_NO_COMPRESSION | ssl.OP_SINGLE_DH_USE |
|
||||
ssl.OP_SINGLE_ECDH_USE
|
||||
)
|
||||
TLS_OPT = (
|
||||
ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_NO_TLSv1 |
|
||||
ssl.OP_NO_TLSv1_1
|
||||
)
|
||||
OP_NO_TLSv1_3 = getattr(ssl, "OP_NO_TLSv1_3", 0) # make pylint happy
|
||||
|
||||
|
||||
@pytest.mark.skip_if_platform(
|
||||
"debian", reason="Crypto policy is not supported on Debian"
|
||||
)
|
||||
@pytest.mark.parametrize('minver,maxver,opt,expected', [
|
||||
(None, None, BASE_OPT, None),
|
||||
(None, "tls1.3", BASE_OPT | TLS_OPT, ["tls1.2", "tls1.3"]),
|
||||
("tls1.2", "tls1.3", BASE_OPT | TLS_OPT, ["tls1.2", "tls1.3"]),
|
||||
("tls1.2", None, BASE_OPT | TLS_OPT, ["tls1.2", "tls1.3"]),
|
||||
("tls1.2", "tls1.2", BASE_OPT | TLS_OPT | OP_NO_TLSv1_3, ["tls1.2"]),
|
||||
(None, "tls1.2", BASE_OPT | TLS_OPT | OP_NO_TLSv1_3, ["tls1.2"]),
|
||||
("tls1.3", "tls1.3", BASE_OPT | TLS_OPT | ssl.OP_NO_TLSv1_2, ["tls1.3"]),
|
||||
("tls1.3", None, BASE_OPT | TLS_OPT | ssl.OP_NO_TLSv1_2, ["tls1.3"]),
|
||||
])
|
||||
def test_tls_version_span(minver, maxver, opt, expected):
|
||||
assert get_proper_tls_version_span(minver, maxver) == expected
|
||||
# file must exist and contain certs
|
||||
cafile = ssl.get_default_verify_paths().cafile
|
||||
conn = create_https_connection(
|
||||
"invalid.test",
|
||||
cafile=cafile,
|
||||
tls_version_min=minver,
|
||||
tls_version_max=maxver
|
||||
)
|
||||
ctx = getattr(conn, "_context")
|
||||
assert ctx.options == BASE_OPT | opt
|
||||
assert ctx.get_ciphers() == BASE_CTX.get_ciphers()
|
||||
@@ -22,7 +22,11 @@ Test the `ipalib.x509` module.
|
||||
"""
|
||||
|
||||
import base64
|
||||
from binascii import hexlify
|
||||
from configparser import RawConfigParser
|
||||
import datetime
|
||||
from io import StringIO
|
||||
import pickle
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -160,7 +164,8 @@ QUs1Hx1wL7mL4U8fKCFDKA+ds2B2xWgoZg==
|
||||
-----END CERTIFICATE-----
|
||||
'''
|
||||
|
||||
class test_x509(object):
|
||||
|
||||
class test_x509:
|
||||
"""
|
||||
Test `ipalib.x509`
|
||||
|
||||
@@ -258,7 +263,7 @@ class test_x509(object):
|
||||
not_after = datetime.datetime(2018, 10, 23, 5, 36, 59)
|
||||
assert cert.not_valid_before == not_before
|
||||
assert cert.not_valid_after == not_after
|
||||
assert cert.san_general_names == [DNSName(u'ipa.demo1.freeipa.org')]
|
||||
assert cert.san_general_names == [DNSName('ipa.demo1.freeipa.org')]
|
||||
assert cert.san_a_label_dns_names == ['ipa.demo1.freeipa.org']
|
||||
assert cert.extended_key_usage == {
|
||||
'1.3.6.1.5.5.7.3.1', '1.3.6.1.5.5.7.3.2'
|
||||
@@ -267,3 +272,114 @@ class test_x509(object):
|
||||
b'0 \x06\x03U\x1d%\x01\x01\xff\x04\x160\x14\x06\x08+\x06\x01'
|
||||
b'\x05\x05\x07\x03\x01\x06\x08+\x06\x01\x05\x05\x07\x03\x02'
|
||||
)
|
||||
|
||||
|
||||
class test_ExternalCAProfile:
|
||||
def test_MSCSTemplateV1_good(self):
|
||||
o = x509.MSCSTemplateV1("MySubCA")
|
||||
assert hexlify(o.get_ext_data()) == b'1e0e004d007900530075006200430041'
|
||||
|
||||
def test_MSCSTemplateV1_bad(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV1("MySubCA:1")
|
||||
|
||||
def test_MSCSTemplateV1_pickle_roundtrip(self):
|
||||
o = x509.MSCSTemplateV1("MySubCA")
|
||||
s = pickle.dumps(o)
|
||||
assert o.get_ext_data() == pickle.loads(s).get_ext_data()
|
||||
|
||||
def test_MSCSTemplateV2_too_few_parts(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4")
|
||||
|
||||
def test_MSCSTemplateV2_too_many_parts(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:100:200:300")
|
||||
|
||||
def test_MSCSTemplateV2_bad_oid(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("not_an_oid:1")
|
||||
|
||||
def test_MSCSTemplateV2_non_numeric_major_version(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:major:200")
|
||||
|
||||
def test_MSCSTemplateV2_non_numeric_minor_version(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:100:minor")
|
||||
|
||||
def test_MSCSTemplateV2_major_version_lt_zero(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:-1:200")
|
||||
|
||||
def test_MSCSTemplateV2_minor_version_lt_zero(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:100:-1")
|
||||
|
||||
def test_MSCSTemplateV2_major_version_gt_max(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:4294967296:200")
|
||||
|
||||
def test_MSCSTemplateV2_minor_version_gt_max(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.MSCSTemplateV2("1.2.3.4:100:4294967296")
|
||||
|
||||
def test_MSCSTemplateV2_good_major(self):
|
||||
o = x509.MSCSTemplateV2("1.2.3.4:4294967295")
|
||||
assert hexlify(o.get_ext_data()) == b'300c06032a0304020500ffffffff'
|
||||
|
||||
def test_MSCSTemplateV2_good_major_minor(self):
|
||||
o = x509.MSCSTemplateV2("1.2.3.4:4294967295:0")
|
||||
assert hexlify(o.get_ext_data()) \
|
||||
== b'300f06032a0304020500ffffffff020100'
|
||||
|
||||
def test_MSCSTemplateV2_pickle_roundtrip(self):
|
||||
o = x509.MSCSTemplateV2("1.2.3.4:4294967295:0")
|
||||
s = pickle.dumps(o)
|
||||
assert o.get_ext_data() == pickle.loads(s).get_ext_data()
|
||||
|
||||
def test_ExternalCAProfile_dispatch(self):
|
||||
"""
|
||||
Test that constructing ExternalCAProfile actually returns an
|
||||
instance of the appropriate subclass.
|
||||
"""
|
||||
assert isinstance(
|
||||
x509.ExternalCAProfile("MySubCA"),
|
||||
x509.MSCSTemplateV1)
|
||||
assert isinstance(
|
||||
x509.ExternalCAProfile("1.2.3.4:100"),
|
||||
x509.MSCSTemplateV2)
|
||||
|
||||
def test_write_pkispawn_config_file_MSCSTemplateV1(self):
|
||||
template = x509.MSCSTemplateV1(u"SubCA")
|
||||
expected = (
|
||||
'[CA]\n'
|
||||
'pki_req_ext_oid = 1.3.6.1.4.1.311.20.2\n'
|
||||
'pki_req_ext_data = 1e0a00530075006200430041\n\n'
|
||||
)
|
||||
self._test_write_pkispawn_config_file(template, expected)
|
||||
|
||||
def test_write_pkispawn_config_file_MSCSTemplateV2(self):
|
||||
template = x509.MSCSTemplateV2(u"1.2.3.4:4294967295")
|
||||
expected = (
|
||||
'[CA]\n'
|
||||
'pki_req_ext_oid = 1.3.6.1.4.1.311.21.7\n'
|
||||
'pki_req_ext_data = 300c06032a0304020500ffffffff\n\n'
|
||||
)
|
||||
self._test_write_pkispawn_config_file(template, expected)
|
||||
|
||||
def _test_write_pkispawn_config_file(self, template, expected):
|
||||
"""
|
||||
Test that the values we read from an ExternalCAProfile
|
||||
object can be used to produce a reasonable-looking pkispawn
|
||||
configuration.
|
||||
"""
|
||||
config = RawConfigParser()
|
||||
config.optionxform = str
|
||||
config.add_section("CA")
|
||||
config.set("CA", "pki_req_ext_oid", template.ext_oid)
|
||||
config.set("CA", "pki_req_ext_data",
|
||||
hexlify(template.get_ext_data()).decode('ascii'))
|
||||
out = StringIO()
|
||||
config.write(out)
|
||||
assert out.getvalue() == expected
|
||||
|
||||
Reference in New Issue
Block a user