summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorMilan KubĂ­k <mkubik@redhat.com>2016-07-22 17:19:31 +0200
committerMartin Basti <mbasti@redhat.com>2016-07-29 09:04:42 +0200
commit7c03708734ad7cb8f1a6edd39817212794b5aabd (patch)
treeb31b2e64c65d96f8db620ac83d9a64825c0f963f /ipatests
parentdde1240f5d71f3a8c50226a720af6f1000a35be1 (diff)
downloadfreeipa-7c03708734ad7cb8f1a6edd39817212794b5aabd.tar.gz
freeipa-7c03708734ad7cb8f1a6edd39817212794b5aabd.tar.xz
freeipa-7c03708734ad7cb8f1a6edd39817212794b5aabd.zip
ipatests: Provide a context manager for mocking a trust in RPC tests
The new module contains utility functions and a context manager to make the mocking of an existing AD trust relation in the XMLRPC tests. The module provides with two functions that create and delete the containers for trusts and cifs domains. A context manager using these is provided as well. The user of the context manager is responsible for deleting all the LDAP entries created during the test within the context. If there are some entries left at the time of exiting the context manager, making the container entries non-leaf entries, the tests will fail. The context manager will not work when used on a server that already has trust established. https://fedorahosted.org/freeipa/ticket/6142 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_xmlrpc/mock_trust.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/ipatests/test_xmlrpc/mock_trust.py b/ipatests/test_xmlrpc/mock_trust.py
new file mode 100644
index 000000000..8313db62e
--- /dev/null
+++ b/ipatests/test_xmlrpc/mock_trust.py
@@ -0,0 +1,52 @@
+# coding: utf-8
+#
+# Copyright (C) 2016 FreeIPA Contributors see COPYING for license
+#
+from contextlib import contextmanager
+
+from ipalib import api
+from ipatests.util import MockLDAP
+
+trust_container_dn = "cn=ad,cn=trusts,{basedn}".format(
+ basedn=api.env.basedn)
+trust_container_add = dict(
+ objectClass=[b"nsContainer", b"top"]
+ )
+
+smb_cont_dn = "{cifsdomains},{basedn}".format(
+ cifsdomains=api.env.container_cifsdomains,
+ basedn=api.env.basedn)
+smb_cont_add = dict(
+ objectClass=[b"nsContainer", b"top"]
+ )
+
+
+def create_mock_trust_containers():
+ with MockLDAP() as ldap:
+ ldap.add_entry(trust_container_dn, trust_container_add)
+ ldap.add_entry(smb_cont_dn, smb_cont_add)
+
+
+def remove_mock_trust_containers():
+ with MockLDAP() as ldap:
+ ldap.del_entry(trust_container_dn)
+ ldap.del_entry(smb_cont_dn)
+
+
+@contextmanager
+def mocked_trust_containers():
+ """Mocked trust containers
+
+ Provides containers for the RPC tests:
+ cn=ad,cn=trusts,BASEDN
+ cn=ad,cn=etc,BASEDN
+
+ Upon exiting, it tries to remove the container entries.
+ If the user of the context manager failed to remove
+ all child entries, exiting the context manager will fail.
+ """
+ create_mock_trust_containers()
+ try:
+ yield
+ finally:
+ remove_mock_trust_containers()