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)
def test_context_session_cookie(self): """ Test that session_cookie is set in `ipalib.rpc.rpcclient.connect` """ fuzzy_cookie = Fuzzy( r'^ipa_session=MagBearerToken=[A-Za-z0-9+\/]+=*;$') session_cookie = getattr(context, 'session_cookie', None) unquoted = urllib.parse.unquote(session_cookie) assert (unquoted == fuzzy_cookie)
def test_context_session_cookie(self): """ Test that session_cookie is set in `ipalib.rpc.rpcclient.connect` """ fuzzy_cookie = Fuzzy('^ipa_session=MagBearerToken=[A-Za-z0-9+\/]+=*;$') session_cookie = getattr(context, 'session_cookie', None) # pylint-2 is incorrectly spewing Too many positional arguments # pylint: disable=E1121 unquoted = urllib.parse.unquote(session_cookie) assert (unquoted == fuzzy_cookie)
class test_ping(Declarative): tests = [ dict( desc='Ping the server', command=('ping', [], {}), expected=dict( summary=Fuzzy('IPA server version .*. API version .*')), ), dict( desc='Try to ping with an argument', command=('ping', ['bad_arg'], {}), expected=errors.ZeroArgumentError(name='ping'), ), dict( desc='Try to ping with an option', command=('ping', [], dict(bad_arg=True)), expected=errors.OptionError(_('Unknown option: %(option)s'), option='bad_arg'), ), ]
def fuzzy_set_ci(s): return Fuzzy(test=lambda other: set(x.lower() for x in other) == set( y.lower() for y in s))
from ipatests.util import assert_deepequal, Fuzzy from ipalib import api, request, errors 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('^\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}' # Matches an ipauniqueid like u'784d85fd-eae7-11de-9d01-54520012478b' fuzzy_uuid = Fuzzy('^%s$' % uuid_re) # Matches an automember task DN 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):
rule1 = u'selinuxrule1' selinuxuser1 = u'guest_u:s0' selinuxuser2 = u'xguest_u:s0' user1 = u'tuser1' group1 = u'testgroup1' host1 = u'testhost1.%s' % api.env.domain hostdn1 = DN(('fqdn', host1), ('cn', 'computers'), ('cn', 'accounts'), api.env.basedn) hbacrule1 = u'testhbacrule1' hbacrule2 = u'testhbacrule12' # Note (?i) at the beginning of the regexp is the ingnore case flag fuzzy_selinuxusermapdn = Fuzzy( '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}' '-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_selinux, api.env.basedn) ) fuzzy_hbacruledn = Fuzzy( '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}' '-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s' % (api.env.container_hbac, api.env.basedn) ) allow_all_rule_dn = api.Command['hbacrule_show'](u'allow_all')['result']['dn'] @pytest.mark.tier1 class test_selinuxusermap(Declarative): cleanup_commands = [ ('selinuxusermap_del', [rule1], {}),
class test_batch(Declarative): cleanup_commands = [ ('group_del', [group1], {}), ] tests = [ dict( desc='Batch ping', command=('batch', [dict(method='ping', params=([], {}))], {}), expected=dict(count=1, results=[ dict(summary=Fuzzy('IPA server version .*'), error=None), ]), ), dict( desc='Batch two pings', command=('batch', [dict(method='ping', params=([], {}))] * 2, {}), expected=dict(count=2, results=[ dict(summary=Fuzzy('IPA server version .*'), error=None), dict(summary=Fuzzy('IPA server version .*'), error=None), ]), ), dict( desc='Create and deleting a group', command=('batch', [ dict(method='group_add', params=([group1], dict(description=u'Test desc 1'))), dict(method='group_del', params=([group1], dict())), ], {}), expected=dict( count=2, results=deepequal_list( dict(value=group1, summary=u'Added group "testgroup1"', result=dict( cn=[group1], description=[u'Test desc 1'], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], gidnumber=[fuzzy_digits], dn=DN(('cn', 'testgroup1'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), ), error=None), dict(summary=u'Deleted group "%s"' % group1, result=dict(failed=[]), value=[group1], error=None), ), ), ), dict( desc='Try to delete nonexistent group twice', command=('batch', [ dict(method='group_del', params=([group1], dict())), dict(method='group_del', params=([group1], dict())), ], {}), expected=dict( count=2, results=[ dict( error=u'%s: group not found' % group1, error_name=u'NotFound', error_code=4001, error_kw=dict(reason=u'%s: group not found' % group1, ), ), dict( error=u'%s: group not found' % group1, error_name=u'NotFound', error_code=4001, error_kw=dict(reason=u'%s: group not found' % group1, ), ), ], ), ), dict( desc='Try to delete non-existent group first, then create it', command=('batch', [ dict(method='group_del', params=([group1], dict())), dict(method='group_add', params=([group1], dict(description=u'Test desc 1'))), ], {}), expected=dict( count=2, results=deepequal_list( dict( error=u'%s: group not found' % group1, error_name=u'NotFound', error_code=4001, error_kw=dict(reason=u'%s: group not found' % group1, ), ), dict(value=group1, summary=u'Added group "testgroup1"', result=dict( cn=[group1], description=[u'Test desc 1'], objectclass=objectclasses.group + [u'posixgroup'], ipauniqueid=[fuzzy_uuid], gidnumber=[fuzzy_digits], dn=DN(('cn', 'testgroup1'), ('cn', 'groups'), ('cn', 'accounts'), api.env.basedn), ), error=None), ), ), ), dict( desc='Try bad command invocations', command=( 'batch', [ # bad command name dict(method='nonexistent_ipa_command', params=([], dict())), # dash, not underscore, in command name dict(method='user-del', params=([], dict())), # missing command name dict(params=([group1], dict())), # missing params dict(method='user_del'), # missing required argument dict(method='user_add', params=([], dict())), # missing required option dict(method='user_add', params=([], dict(givenname=first1))), # bad type dict(method='group_add', params=([group1], dict(description=u't', gidnumber=u'bad'))), ], {}), expected=dict( count=7, results=deepequal_list( dict( error=u"unknown command 'nonexistent_ipa_command'", error_name=u'CommandError', error_code=905, error_kw=dict(name=u'nonexistent_ipa_command', ), ), dict( error=u"unknown command 'user-del'", error_name=u'CommandError', error_code=905, error_kw=dict(name=u'user-del', ), ), dict( error=u"'method' is required", error_name=u'RequirementError', error_code=3007, error_kw=dict(name=u'method', ), ), dict( error=u"'params' is required", error_name=u'RequirementError', error_code=3007, error_kw=dict(name=u'params', ), ), dict( error=u"'givenname' is required", error_name=u'RequirementError', error_code=3007, error_kw=dict(name=u'givenname', ), ), dict( error=u"'sn' is required", error_name=u'RequirementError', error_code=3007, error_kw=dict(name=u'sn', ), ), dict( error=Fuzzy(u"invalid 'gid'.*"), error_name=u'ConversionError', error_code=3008, error_kw=dict( name=u'gid', error=Fuzzy(u'.*'), ), ), ), ), ), ]
def test_ping(self): """Ping the server.""" result = self.tracker.run_command('ping') exp = {'summary': Fuzzy('IPA server version .*. API version .*')} assert_equal(result, exp)
def fuzzy_set_optional_oc(s, oc): return Fuzzy(test=lambda other: set(x.lower() for x in other if x != oc) == set(y.lower() for y in s if y != oc))