mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipatests: Move trust mock helper functions to a separate module
Moves helper functions used in range plugin test to a separate module to allow code reuse. https://fedorahosted.org/freeipa/ticket/6142 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
committed by
Martin Basti
parent
7c03708734
commit
ddb7a08084
@@ -3,6 +3,7 @@
|
||||
# Copyright (C) 2016 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
from contextlib import contextmanager
|
||||
import six
|
||||
|
||||
from ipalib import api
|
||||
from ipatests.util import MockLDAP
|
||||
@@ -50,3 +51,46 @@ def mocked_trust_containers():
|
||||
yield
|
||||
finally:
|
||||
remove_mock_trust_containers()
|
||||
|
||||
def get_range_dn(name):
|
||||
format_str = "cn={name},cn=ranges,cn=etc,{basedn}"
|
||||
data = dict(name=name, basedn=api.env.basedn)
|
||||
return format_str.format(**data)
|
||||
|
||||
|
||||
def get_trust_dn(name):
|
||||
format_str = "cn={name},cn=ad,cn=trusts,{basedn}"
|
||||
data = dict(name=name, basedn=api.env.basedn)
|
||||
return format_str.format(**data)
|
||||
|
||||
|
||||
def encode_mockldap_value(value):
|
||||
value = str(value)
|
||||
if six.PY3:
|
||||
return value.encode('utf-8')
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def get_trusted_dom_range_dict(name, base_id, size, rangetype, base_rid, sid):
|
||||
return dict(
|
||||
objectClass=[b"ipaIDrange", b"ipatrustedaddomainrange"],
|
||||
ipaBaseID=encode_mockldap_value("{base_id}".format(base_id=base_id)),
|
||||
ipaBaseRID=encode_mockldap_value("{base_rid}".format(base_rid=base_rid)),
|
||||
ipaIDRangeSize=encode_mockldap_value("{size}".format(size=size)),
|
||||
ipaNTTrustedDomainSID=encode_mockldap_value("{sid}".format(sid=sid)),
|
||||
ipaRangeType=encode_mockldap_value("{rangetype}".format(rangetype=rangetype)),
|
||||
)
|
||||
|
||||
|
||||
def get_trusted_dom_dict(name, sid):
|
||||
return dict(
|
||||
objectClass=[b"ipaNTTrustedDomain", b"ipaIDobject", b"top"],
|
||||
ipaNTFlatName=encode_mockldap_value(name.split('.')[0].upper()),
|
||||
ipaNTTrustedDomainSID=encode_mockldap_value(sid),
|
||||
ipaNTSIDBlacklistIncoming=b'S-1-0',
|
||||
ipaNTTrustPartner=encode_mockldap_value('{name}.mock'.format(name=name)),
|
||||
ipaNTTrustType=b'2',
|
||||
ipaNTTrustDirection=b'3',
|
||||
ipaNTTrustAttributes=b'8',
|
||||
)
|
||||
|
||||
@@ -29,6 +29,9 @@ from ipatests.test_xmlrpc import objectclasses
|
||||
from ipatests.util import MockLDAP
|
||||
from ipapython.dn import DN
|
||||
from ipatests.test_xmlrpc.test_user_plugin import get_user_result
|
||||
from ipatests.test_xmlrpc.mock_trust import (
|
||||
get_range_dn, get_trusted_dom_dict, get_trusted_dom_range_dict,
|
||||
get_trust_dn)
|
||||
import pytest
|
||||
|
||||
if six.PY3:
|
||||
@@ -110,52 +113,6 @@ testrange8_size = 50
|
||||
testrange8_base_rid = rid_shift + 700
|
||||
testrange8_secondary_base_rid = rid_shift + 800
|
||||
|
||||
# Helper functions definitions
|
||||
|
||||
|
||||
def get_range_dn(name):
|
||||
format_str = "cn={name},cn=ranges,cn=etc,{basedn}"
|
||||
data = dict(name=name, basedn=api.env.basedn)
|
||||
return format_str.format(**data)
|
||||
|
||||
|
||||
def get_trust_dn(name):
|
||||
format_str = "cn={name},cn=ad,cn=trusts,{basedn}"
|
||||
data = dict(name=name, basedn=api.env.basedn)
|
||||
return format_str.format(**data)
|
||||
|
||||
|
||||
def encode_mockldap_value(value):
|
||||
value = str(value)
|
||||
if six.PY3:
|
||||
return value.encode('utf-8')
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def get_trusted_dom_range_dict(name, base_id, size, rangetype, base_rid, sid):
|
||||
return dict(
|
||||
objectClass=[b"ipaIDrange", b"ipatrustedaddomainrange"],
|
||||
ipaBaseID=encode_mockldap_value("{base_id}".format(base_id=base_id)),
|
||||
ipaBaseRID=encode_mockldap_value("{base_rid}".format(base_rid=base_rid)),
|
||||
ipaIDRangeSize=encode_mockldap_value("{size}".format(size=size)),
|
||||
ipaNTTrustedDomainSID=encode_mockldap_value("{sid}".format(sid=sid)),
|
||||
ipaRangeType=encode_mockldap_value("{rangetype}".format(rangetype=rangetype)),
|
||||
)
|
||||
|
||||
|
||||
def get_trusted_dom_dict(name, sid):
|
||||
return dict(
|
||||
objectClass=[b"ipaNTTrustedDomain", b"ipaIDobject", b"top"],
|
||||
ipaNTFlatName=encode_mockldap_value(name.upper()),
|
||||
ipaNTTrustedDomainSID=encode_mockldap_value(sid),
|
||||
ipaNTSIDBlacklistIncoming=b'S-1-0',
|
||||
ipaNTTrustPartner=encode_mockldap_value('{name}.mock'.format(name=name)),
|
||||
ipaNTTrustType=b'2',
|
||||
ipaNTTrustDirection=b'3',
|
||||
ipaNTTrustAttributes=b'8',
|
||||
)
|
||||
|
||||
# Domain ranges definitions
|
||||
|
||||
# Domain1 - AD domain nonactive (not present in LDAP)
|
||||
|
||||
Reference in New Issue
Block a user