This is an automated email from the git hooks/post-receive script.
firstyear pushed a commit to branch master
in repository lib389.
commit ede3dc03e9ae66e161efa6c3eb2b6a4d7cc5df20
Author: Ilias Stamatis <stamatis.iliass@gmail.com>
Date: Thu Jun 8 04:20:43 2017 +0300
Issue 31 - Initial MemberOf plugin support
Description: Add initial support for MemberOf by implementing
the basic methods for configuring the plugin and writing dsconf
hooks to manage it from the cli.
https://pagure.io/lib389/issue/31
Author: Ilias95
Review by: wibrown (Thank you very much!)
---
cli/dsconf | 2 +
lib389/_mapped_object.py | 9 +
lib389/cli_conf/plugin.py | 15 +
lib389/cli_conf/plugins/__init__.py | 0
lib389/cli_conf/plugins/memberof.py | 240 ++++++++++++++
lib389/plugins.py | 94 ++++++
lib389/tests/cli/conf_plugins/__init__.py | 0
lib389/tests/cli/conf_plugins/memberof_test.py | 422 +++++++++++++++++++++++++
8 files changed, 782 insertions(+)
diff --git a/cli/dsconf b/cli/dsconf
index e6cb95d..a114afb 100755
--- a/cli/dsconf
+++ b/cli/dsconf
@@ -22,6 +22,7 @@ from lib389.cli_conf import backend as cli_backend
from lib389.cli_conf import plugin as cli_plugin
from lib389.cli_conf import schema as cli_schema
from lib389.cli_conf import lint as cli_lint
+from lib389.cli_conf.plugins import memberof as cli_memberof
from lib389.cli_base import disconnect_instance, connect_instance
from lib389.cli_base.dsrc import dsrc_to_ldap, dsrc_arg_concat
@@ -63,6 +64,7 @@ if __name__ == '__main__':
cli_schema.create_parser(subparsers)
cli_lint.create_parser(subparsers)
cli_plugin.create_parser(subparsers)
+ cli_memberof.create_parser(subparsers)
args = parser.parse_args()
diff --git a/lib389/_mapped_object.py b/lib389/_mapped_object.py
index 38e52f9..c307cf2 100644
--- a/lib389/_mapped_object.py
+++ b/lib389/_mapped_object.py
@@ -184,6 +184,15 @@ class DSLdapObject(DSLogging):
# Do a mod_delete on the value.
self.set(key, value, action=ldap.MOD_DELETE)
+ def remove_all(self, key):
+ """Remove all values defined by key (if possible).
+
+ If an attribute is multi-valued AND required all values except one will
+ be deleted.
+ """
+ for val in self.get_attr_vals(key):
+ self.remove(key, val)
+
# maybe this could be renamed?
def set(self, key, value, action=ldap.MOD_REPLACE):
self._log.debug("%s set(%r, %r)" % (self._dn, key, value))
diff --git a/lib389/cli_conf/plugin.py b/lib389/cli_conf/plugin.py
index 8736c3e..2d02f87 100644
--- a/lib389/cli_conf/plugin.py
+++ b/lib389/cli_conf/plugin.py
@@ -61,6 +61,21 @@ def plugin_disable(inst, basedn, log, args, warn=True):
def plugin_configure(inst, basedn, log, args):
pass
+def generic_show(inst, basedn, log, args):
+ """Display plugin configuration."""
+ plugin = args.plugin_cls(inst)
+ log.info(plugin.display())
+
+def generic_enable(inst, basedn, log, args):
+ plugin = args.plugin_cls(inst)
+ plugin.enable()
+ log.info("Enabled %s", plugin.rdn)
+
+def generic_disable(inst, basedn, log, args):
+ plugin = args.plugin_cls(inst)
+ plugin.disable()
+ log.info("Disabled %s", plugin.rdn)
+
def create_parser(subparsers):
plugin_parser = subparsers.add_parser('plugin', help="Manage plugins available on the server")
diff --git a/lib389/cli_conf/plugins/__init__.py b/lib389/cli_conf/plugins/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/lib389/cli_conf/plugins/memberof.py b/lib389/cli_conf/plugins/memberof.py
new file mode 100644
index 0000000..ceaecad
--- /dev/null
+++ b/lib389/cli_conf/plugins/memberof.py
@@ -0,0 +1,240 @@
+# --- BEGIN COPYRIGHT BLOCK ---
+# Copyright (C) 2016-2017 Red Hat, Inc.
+# All rights reserved.
+#
+# License: GPL (version 3 or any later version).
+# See LICENSE for details.
+# --- END COPYRIGHT BLOCK ---
+
+import ldap
+
+from lib389.plugins import MemberOfPlugin
+from lib389.cli_conf.plugin import generic_enable, generic_disable, generic_show
+
+
+def manage_attr(inst, basedn, log, args):
+ if args.value is not None:
+ set_attr(inst, basedn, log, args)
+ else:
+ display_attr(inst, basedn, log, args)
+
+def display_attr(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ log.info(plugin.get_attr_formatted())
+
+def set_attr(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.set_attr(args.value)
+ except ldap.UNWILLING_TO_PERFORM:
+ log.error('Error: Illegal value "{}". Failed to set.'.format(args.value))
+ else:
+ log.info('memberOfAttr set to "{}"'.format(args.value))
+
+def display_groupattr(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ log.info(plugin.get_groupattr_formatted())
+
+def add_groupattr(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.add_groupattr(args.value)
+ except ldap.UNWILLING_TO_PERFORM:
+ log.error('Error: Illegal value "{}". Failed to add.'.format(args.value))
+ except ldap.TYPE_OR_VALUE_EXISTS:
+ log.info('Value "{}" already exists.'.format(args.value))
+ else:
+ log.info('successfully added memberOfGroupAttr value "{}"'.format(args.value))
+
+def remove_groupattr(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.remove_groupattr(args.value)
+ except ldap.UNWILLING_TO_PERFORM:
+ log.error("Error: Failed to delete. memberOfGroupAttr is required.")
+ except ldap.NO_SUCH_ATTRIBUTE as ex:
+ log.error('Error: Failed to delete. No value "{0}" found.'.format(args.value))
+ else:
+ log.info('successfully removed memberOfGroupAttr value "{}"'.format(args.value))
+
+def display_allbackends(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ val = plugin.get_allbackends_formatted()
+ if not val:
+ log.info("memberOfAllBackends is not set")
+ else:
+ log.info(val)
+
+def enable_allbackends(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ plugin.enable_allbackends()
+ log.info("memberOfAllBackends enabled successfully")
+
+def disable_allbackends(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ plugin.disable_allbackends()
+ log.info("memberOfAllBackends disabled successfully")
+
+def manage_autoaddoc(inst, basedn, log, args):
+ if args.value == "del":
+ remove_autoaddoc(inst, basedn, log, args)
+ elif args.value is not None:
+ set_autoaddoc(inst, basedn, log, args)
+ else:
+ display_autoaddoc(inst, basedn, log, args)
+
+def display_autoaddoc(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ val = plugin.get_autoaddoc_formatted()
+ if not val:
+ log.info("memberOfAutoAddOc is not set")
+ else:
+ log.info(val)
+
+def set_autoaddoc(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ d = {'nsmemberof': 'nsMemberOf', 'inetuser': 'inetUser', 'inetadmin': 'inetAdmin'}
+ plugin.set_autoaddoc(d[args.value])
+ log.info('memberOfAutoAddOc set to "{}"'.format(d[args.value]))
+
+def remove_autoaddoc(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ if not plugin.get_autoaddoc():
+ log.info("memberOfAutoAddOc was not set")
+ else:
+ plugin.remove_autoaddoc()
+ log.info("memberOfAutoAddOc attribute deleted")
+
+def display_scope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ val = plugin.get_entryscope_formatted()
+ if not val:
+ log.info("memberOfEntryScope is not set")
+ else:
+ log.info(val)
+
+def add_scope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.add_entryscope(args.value)
+ except ldap.UNWILLING_TO_PERFORM as ex:
+ if "is also listed as an exclude suffix" in ex.args[0]['info']:
+ log.error('Error: Include suffix ({0}) is also listed as an exclude suffix.'.format(args.value))
+ else:
+ log.error('Error: Invalid DN "{}". Failed to add.'.format(args.value))
+ except ldap.TYPE_OR_VALUE_EXISTS:
+ log.info('Value "{}" already exists.'.format(args.value))
+ else:
+ log.info('successfully added memberOfEntryScope value "{}"'.format(args.value))
+
+def remove_scope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.remove_entryscope(args.value)
+ except ldap.NO_SUCH_ATTRIBUTE as ex:
+ log.error('Error: Failed to delete. No value "{0}" found.'.format(args.value))
+ else:
+ log.info('successfully removed memberOfEntryScope value "{}"'.format(args.value))
+
+def display_excludescope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ val = plugin.get_excludescope_formatted()
+ if not val:
+ log.info("memberOfEntryScopeExcludeSubtree is not set")
+ else:
+ log.info(val)
+
+def add_excludescope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.add_excludescope(args.value)
+ except ldap.UNWILLING_TO_PERFORM as ex:
+ if "is also listed as an exclude suffix" in ex.args[0]['info']:
+ log.error('Error: Suffix ({0}) is listed in entry scope.'.format(args.value))
+ else:
+ log.error('Error: Invalid DN "{}". Failed to add.'.format(args.value))
+ except ldap.TYPE_OR_VALUE_EXISTS:
+ log.info('Value "{}" already exists.'.format(args.value))
+ else:
+ log.info('successfully added memberOfEntryScopeExcludeSubtree value "{}"'.format(args.value))
+
+def remove_excludescope(inst, basedn, log, args):
+ plugin = MemberOfPlugin(inst)
+ try:
+ plugin.remove_excludescope(args.value)
+ except ldap.NO_SUCH_ATTRIBUTE as ex:
+ log.error('Error: Failed to delete. No value "{0}" found.'.format(args.value))
+ else:
+ log.info('successfully removed memberOfEntryScopeExcludeSubtree value "{}"'.format(args.value))
+
+def fixup(inst, basedn, log, args):
+ """Run the fix-up task for memberof plugin."""
+ pass
+
+def create_parser(subparsers):
+ memberof_parser = subparsers.add_parser('memberof', help='Manage and configure MemberOf plugin')
+
+ subcommands = memberof_parser.add_subparsers(help='action')
+
+ show_parser = subcommands.add_parser('show', help='display memberof plugin configuration')
+ show_parser.set_defaults(func=generic_show, plugin_cls=MemberOfPlugin)
+
+ enable_parser = subcommands.add_parser('enable', help='enable memberof plugin')
+ enable_parser.set_defaults(func=generic_enable, plugin_cls=MemberOfPlugin)
+
+ disable_parser = subcommands.add_parser('disable', help='disable memberof plugin')
+ disable_parser.set_defaults(func=generic_disable, plugin_cls=MemberOfPlugin)
+
+ attr_parser = subcommands.add_parser('attr', help='get or set memberofattr')
+ attr_parser.set_defaults(func=manage_attr)
+ attr_parser.add_argument('value', nargs='?', help='The value to set as memberofattr')
+
+ groupattr_parser = subcommands.add_parser('groupattr', help='get or manage memberofgroupattr')
+ groupattr_parser.set_defaults(func=display_groupattr)
+ # argparse doesn't support optional subparsers in python2!
+ groupattr_subcommands = groupattr_parser.add_subparsers(help='action')
+ add_groupattr_parser = groupattr_subcommands.add_parser('add', help='add memberofgroupattr value')
+ add_groupattr_parser.set_defaults(func=add_groupattr)
+ add_groupattr_parser.add_argument('value', help='The value to add in memberofgroupattr')
+ del_groupattr_parser = groupattr_subcommands.add_parser('del', help='remove memberofgroupattr value')
+ del_groupattr_parser.set_defaults(func=remove_groupattr)
+ del_groupattr_parser.add_argument('value', help='The value to remove from memberofgroupattr')
+
+ allbackends_parser = subcommands.add_parser('allbackends', help='get or manage memberofallbackends')
+ allbackends_parser.set_defaults(func=display_allbackends)
+ # argparse doesn't support optional subparsers in python2!
+ allbackends_subcommands = allbackends_parser.add_subparsers(help='action')
+ on_allbackends_parser = allbackends_subcommands.add_parser('on', help='enable all backends for memberof')
+ on_allbackends_parser.set_defaults(func=enable_allbackends)
+ off_allbackends_parser = allbackends_subcommands.add_parser('off', help='disable all backends for memberof')
+ off_allbackends_parser.set_defaults(func=disable_allbackends)
+
+ autoaddoc_parser = subcommands.add_parser('autoaddoc', help='get or set memberofautoaddoc')
+ autoaddoc_parser.set_defaults(func=manage_autoaddoc)
+ autoaddoc_parser.add_argument('value', nargs='?', choices=['nsmemberof', 'inetuser', 'inetadmin', 'del'],
+ type=str.lower, help='The value to set as memberofautoaddoc or del to remove the attribute')
+
+ scope_parser = subcommands.add_parser('scope', help='get or manage memberofentryscope')
+ scope_parser.set_defaults(func=display_scope)
+ # argparse doesn't support optional subparsers in python2!
+ scope_subcommands = scope_parser.add_subparsers(help='action')
+ add_scope_parser = scope_subcommands.add_parser('add', help='add memberofentryscope value')
+ add_scope_parser.set_defaults(func=add_scope)
+ add_scope_parser.add_argument('value', help='The value to add in memberofentryscope')
+ del_scope_parser = scope_subcommands.add_parser('del', help='remove memberofentryscope value')
+ del_scope_parser.set_defaults(func=remove_scope)
+ del_scope_parser.add_argument('value', help='The value to remove from memberofentryscope')
+
+ exclude_parser = subcommands.add_parser('exclude', help='get or manage memberofentryscopeexcludesubtree')
+ exclude_parser.set_defaults(func=display_excludescope)
+ # argparse doesn't support optional subparsers in python2!
+ exclude_subcommands = exclude_parser.add_subparsers(help='action')
+ add_exclude_parser = exclude_subcommands.add_parser('add', help='add memberofentryscopeexcludesubtree value')
+ add_exclude_parser.set_defaults(func=add_excludescope)
+ add_exclude_parser.add_argument('value', help='The value to add in memberofentryscopeexcludesubtree')
+ del_exclude_parser = exclude_subcommands.add_parser('del', help='remove memberofentryscopeexcludesubtree value')
+ del_exclude_parser.set_defaults(func=remove_excludescope)
+ del_exclude_parser.add_argument('value', help='The value to remove from memberofentryscopeexcludesubtree')
+
+ fixup_parser = subcommands.add_parser('fixup', help='run the fix-up task for memberof plugin')
+ fixup_parser.set_defaults(func=fixup)
diff --git a/lib389/plugins.py b/lib389/plugins.py
index 0a46d35..bde4c92 100644
--- a/lib389/plugins.py
+++ b/lib389/plugins.py
@@ -150,8 +150,102 @@ class RolesPlugin(Plugin):
super(RolesPlugin, self).__init__(instance, dn, batch)
class MemberOfPlugin(Plugin):
+ _plugin_properties = {
+ 'cn' : 'MemberOf Plugin',
+ 'nsslapd-pluginEnabled' : 'off',
+ 'nsslapd-pluginPath' : 'libmemberof-plugin',
+ 'nsslapd-pluginInitfunc' : 'memberof_postop_init',
+ 'nsslapd-pluginType' : 'betxnpostoperation',
+ 'nsslapd-plugin-depends-on-type' : 'database',
+ 'nsslapd-pluginId' : 'memberof',
+ 'nsslapd-pluginVendor' : '389 Project',
+ 'nsslapd-pluginVersion' : '1.3.7.0',
+ 'nsslapd-pluginDescription' : 'memberof plugin',
+ 'memberOfGroupAttr' : 'member',
+ 'memberOfAttr' : 'memberOf',
+ }
+
def __init__(self, instance, dn="cn=MemberOf Plugin,cn=plugins,cn=config", batch=False):
super(MemberOfPlugin, self).__init__(instance, dn, batch)
+ self._create_objectclasses = ['top', 'nsSlapdPlugin', 'extensibleObject']
+
+ def get_attr(self):
+ return self.get_attr_val('memberofattr')
+
+ def get_attr_formatted(self):
+ return self.display_attr('memberofattr')
+
+ def set_attr(self, attr):
+ self.set('memberofattr', attr)
+
+ def get_groupattr(self):
+ return self.get_attr_vals('memberofgroupattr')
+
+ def get_groupattr_formatted(self):
+ return self.display_attr('memberofgroupattr')
+
+ def add_groupattr(self, attr):
+ self.add('memberofgroupattr', attr)
+
+ def remove_groupattr(self, attr):
+ self.remove('memberofgroupattr', attr)
+
+ def get_allbackends(self):
+ return self.get_attr_val('memberofallbackends')
+
+ def get_allbackends_formatted(self):
+ return self.display_attr('memberofallbackends')
+
+ def enable_allbackends(self):
+ self.set('memberofallbackends', 'on')
+
+ def disable_allbackends(self):
+ self.set('memberofallbackends', 'off')
+
+ def get_autoaddoc(self):
+ return self.get_attr_val('memberofautoaddoc')
+
+ def get_autoaddoc_formatted(self):
+ return self.display_attr('memberofautoaddoc')
+
+ def set_autoaddoc(self, object_class):
+ self.set('memberofautoaddoc', object_class)
+
+ def remove_autoaddoc(self):
+ self.remove_all('memberofautoaddoc')
+
+ def get_entryscope(self, formatted=False):
+ return self.get_attr_vals('memberofentryscope')
+
+ def get_entryscope_formatted(self):
+ return self.display_attr('memberofentryscope')
+
+ def add_entryscope(self, attr):
+ self.add('memberofentryscope', attr)
+
+ def remove_entryscope(self, attr):
+ self.remove('memberofentryscope', attr)
+
+ # def remove_all_entryscope(self):
+ # self.remove_all('memberofentryscope')
+
+ def get_excludescope(self):
+ return self.get_attr_vals('memberofentryscopeexcludesubtree')
+
+ def get_excludescope_formatted(self):
+ return self.display_attr('memberofentryscopeexcludesubtree')
+
+ def add_excludescope(self, attr):
+ self.add('memberofentryscopeexcludesubtree', attr)
+
+ def remove_excludescope(self, attr):
+ self.remove('memberofentryscopeexcludesubtree', attr)
+
+ # def remove_all_excludescope(self):
+ # self.remove_all('memberofentryscopeexcludesubtree')
+
+ def fixup(self):
+ pass
class RetroChangelogPlugin(Plugin):
def __init__(self, instance, dn="cn=Retro Changelog Plugin,cn=plugins,cn=config", batch=False):
diff --git a/lib389/tests/cli/conf_plugins/__init__.py b/lib389/tests/cli/conf_plugins/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/lib389/tests/cli/conf_plugins/memberof_test.py b/lib389/tests/cli/conf_plugins/memberof_test.py
new file mode 100644
index 0000000..4c8296a
--- /dev/null
+++ b/lib389/tests/cli/conf_plugins/memberof_test.py
@@ -0,0 +1,422 @@
+# --- BEGIN COPYRIGHT BLOCK ---
+# Copyright (C) 2016-2017 Red Hat, Inc.
+# All rights reserved.
+#
+# License: GPL (version 3 or any later version).
+# See LICENSE for details.
+# --- END COPYRIGHT BLOCK ---
+
+import pytest
+
+from lib389.tests.cli import topology as default_topology
+from lib389.cli_base import LogCapture, FakeArgs
+from lib389.plugins import MemberOfPlugin
+from lib389.cli_conf.plugins import memberof as memberof_cli
+
+
+@pytest.fixture(scope="module")
+def topology(request):
+ topology = default_topology(request)
+
+ plugin = MemberOfPlugin(topology.standalone)
+ # no memberof entry exists by default
+ plugin.create()
+
+ # At the moment memberof plugin needs to be enabled in order to perform
+ # syntax checking. Additionally, we have to restart the server in order
+ # for the action of enabling the pluging to take effect.
+ plugin.enable()
+ topology.standalone.restart()
+ topology.logcap.flush()
+
+ return topology
+
+
+def test_set_attr_with_legal_value(topology):
+ args = FakeArgs()
+
+ args.value = "memberOf"
+ memberof_cli.manage_attr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAttr set to")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.manage_attr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": memberOf")
+ topology.logcap.flush()
+
+def test_set_attr_with_illegal_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.manage_attr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("Failed to set")
+ topology.logcap.flush()
+
+def test_set_groupattr_with_legal_value(topology):
+ args = FakeArgs()
+
+ args.value = "uniqueMember"
+ memberof_cli.add_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully added memberOfGroupAttr value")
+ topology.logcap.flush()
+
+ memberof_cli.display_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": uniqueMember")
+ topology.logcap.flush()
+
+def test_set_groupattr_with_value_that_already_exists(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "uniqueMember" in plugin.get_groupattr():
+ plugin.add_groupattr("uniqueMember")
+
+ args = FakeArgs()
+
+ args.value = "uniqueMember"
+ memberof_cli.add_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("already exists")
+ topology.logcap.flush()
+
+def test_set_groupattr_with_illegal_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.add_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("Illegal value")
+ topology.logcap.flush()
+
+def test_remove_groupattr_with_value_that_exists(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "uniqueMember" in plugin.get_groupattr():
+ plugin.add_groupattr("uniqueMember")
+
+ args = FakeArgs()
+
+ args.value = "uniqueMember"
+ memberof_cli.remove_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully removed memberOfGroupAttr value")
+ topology.logcap.flush()
+
+ memberof_cli.display_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert not topology.logcap.contains(": uniqueMember")
+ topology.logcap.flush()
+
+def test_remove_groupattr_with_value_that_doesnt_exist(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.remove_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains('No value "{0}" found'.format(args.value))
+ topology.logcap.flush()
+
+def test_try_remove_all_groupattr_values(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # make sure "member" value exists and it is the only one
+ assert "member" in plugin.get_groupattr() # exists from default
+ assert len(plugin.get_groupattr()) == 1
+
+ args = FakeArgs()
+
+ args.value = "member"
+ memberof_cli.remove_groupattr(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("Error: Failed to delete. memberOfGroupAttr is required.")
+ topology.logcap.flush()
+
+def test_get_allbackends_when_not_set(topology):
+ args = FakeArgs()
+
+ memberof_cli.display_allbackends(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAllBackends is not set")
+ topology.logcap.flush()
+
+def test_enable_allbackends(topology):
+ args = FakeArgs()
+
+ memberof_cli.enable_allbackends(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("enabled successfully")
+ topology.logcap.flush()
+
+ memberof_cli.display_allbackends(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": on")
+ topology.logcap.flush()
+
+def test_disable_all_backends(topology):
+ args = FakeArgs()
+
+ memberof_cli.disable_allbackends(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("disabled successfully")
+ topology.logcap.flush()
+
+ memberof_cli.display_allbackends(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": off")
+ topology.logcap.flush()
+
+def test_set_autoaddoc(topology):
+ args = FakeArgs()
+
+ # argparse makes sure that only choices 'nsmemberof', 'inetuser', 'inetadmin', 'del' are allowed
+ args.value = "nsmemberof"
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAutoAddOc set to")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": nsMemberOf")
+ topology.logcap.flush()
+
+def test_remove_autoaddoc(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not plugin.get_autoaddoc():
+ plugin.set_autoaddoc("nsmemberof")
+
+ args = FakeArgs()
+
+ # argparse makes sure that only choices 'nsmemberof', 'inetuser', 'inetadmin', 'del' are allowed
+ args.value = "del"
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAutoAddOc attribute deleted")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert not topology.logcap.contains(": nsMemberOf")
+ topology.logcap.flush()
+
+def test_remove_autoaddoc_when_not_set(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if plugin.get_autoaddoc():
+ plugin.remove_autoaddoc()
+
+ args = FakeArgs()
+
+ args.value = "del"
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAutoAddOc was not set")
+ topology.logcap.flush()
+
+def test_get_autoaddoc_when_not_set(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if plugin.get_autoaddoc():
+ plugin.remove_autoaddoc()
+
+ args = FakeArgs()
+
+ args.value = None
+ memberof_cli.manage_autoaddoc(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfAutoAddOc is not set")
+ topology.logcap.flush()
+
+def test_get_entryscope_when_not_set(topology):
+ args = FakeArgs()
+
+ args.value = None
+ memberof_cli.display_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfEntryScope is not set")
+ topology.logcap.flush()
+
+def test_add_entryscope_with_legal_value(topology):
+ args = FakeArgs()
+
+ args.value = "dc=example,dc=com"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully added memberOfEntryScope value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": dc=example,dc=com")
+ topology.logcap.flush()
+
+ args.value = "a=b"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully added memberOfEntryScope value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": dc=example,dc=com")
+ assert topology.logcap.contains(": a=b")
+ topology.logcap.flush()
+
+def test_add_entryscope_with_illegal_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("Error: Invalid DN")
+ topology.logcap.flush()
+
+def test_add_entryscope_with_existing_value(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "dc=example,dc=com" in plugin.get_entryscope():
+ plugin.add_entryscope("dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "dc=example,dc=com"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains('Value "{}" already exists'.format(args.value))
+ topology.logcap.flush()
+
+def test_remove_entryscope_with_existing_value(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "a=b" in plugin.get_entryscope():
+ plugin.add_entryscope("a=b")
+ if not "dc=example,dc=com" in plugin.get_entryscope():
+ plugin.add_entryscope("dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "a=b"
+ memberof_cli.remove_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully removed memberOfEntryScope value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_scope(topology.standalone, None, topology.logcap.log, args)
+ assert not topology.logcap.contains(": a=b")
+ topology.logcap.flush()
+
+ # THIS MAKES THE SERVER CRASH!!!
+ # caused when trying to remove all memberofentryscope values
+
+ # args.value = "dc=example,dc=com"
+ # memberof_cli.remove_scope(topology.standalone, None, topology.logcap.log, args)
+ # assert topology.logcap.contains("successfully removed value")
+ # topology.logcap.flush()
+
+def test_remove_entryscope_with_non_existing_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.remove_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains('No value "{0}" found'.format(args.value))
+ topology.logcap.flush()
+
+def test_get_excludescope_when_not_set(topology):
+ args = FakeArgs()
+
+ args.value = None
+ memberof_cli.display_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("memberOfEntryScopeExcludeSubtree is not set")
+ topology.logcap.flush()
+
+def test_add_excludescope_with_legal_value(topology):
+ args = FakeArgs()
+
+ args.value = "ou=People,dc=example,dc=com"
+ memberof_cli.add_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully added memberOfEntryScopeExcludeSubtree value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": ou=People,dc=example,dc=com")
+ topology.logcap.flush()
+
+ args.value = "a=b"
+ memberof_cli.add_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully added memberOfEntryScopeExcludeSubtree value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": ou=People,dc=example,dc=com")
+ assert topology.logcap.contains(": a=b")
+ topology.logcap.flush()
+
+def test_add_excludescope_with_illegal_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.add_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("Error: Invalid DN")
+ topology.logcap.flush()
+
+def test_add_excludescope_with_existing_value(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "ou=People,dc=example,dc=com" in plugin.get_excludescope():
+ plugin.add_excludescope("ou=People,dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "ou=People,dc=example,dc=com"
+ memberof_cli.add_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains('Value "{}" already exists'.format(args.value))
+ topology.logcap.flush()
+
+def test_remove_excludescope_with_existing_value(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "a=b" in plugin.get_excludescope():
+ plugin.add_excludescope("a=b")
+ if not "ou=People,dc=example,dc=com" in plugin.get_excludescope():
+ plugin.add_excludescope("ou=People,dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "a=b"
+ memberof_cli.remove_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("successfully removed memberOfEntryScopeExcludeSubtree value")
+ topology.logcap.flush()
+
+ args.value = None
+ memberof_cli.display_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains(": ou=People,dc=example,dc=com")
+ assert not topology.logcap.contains(": a=b")
+ topology.logcap.flush()
+
+ # THIS MAKES THE SERVER CRASH!!!
+ # caused when trying to remove all memberofentryscopeexcludesubtree values
+
+ # args.value = "ou=People,dc=example,dc=com"
+ # memberof_cli.remove_excludescope(topology.standalone, None, topology.logcap.log, args)
+ # assert topology.logcap.contains("successfully removed value")
+ # topology.logcap.flush()
+
+def test_remove_excludescope_with_non_existing_value(topology):
+ args = FakeArgs()
+
+ args.value = "whatever"
+ memberof_cli.remove_excludescope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains('No value "{0}" found'.format(args.value))
+ topology.logcap.flush()
+
+def test_add_entryscope_with_value_that_exists_in_excludescope(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "dc=example,dc=com" in plugin.get_entryscope():
+ plugin.add_entryscope("dc=example,dc=com")
+ if not "ou=People,dc=example,dc=com" in plugin.get_excludescope():
+ plugin.add_excludescope("ou=People,dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "ou=People,dc=example,dc=com"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("is also listed as an exclude suffix")
+ topology.logcap.flush()
+
+def test_add_excludescope_with_value_that_exists_in_entryscope(topology):
+ plugin = MemberOfPlugin(topology.standalone)
+ # setup test
+ if not "dc=example,dc=com" in plugin.get_entryscope():
+ plugin.add_entryscope("dc=example,dc=com")
+ if not "ou=People,dc=example,dc=com" in plugin.get_excludescope():
+ plugin.add_excludescope("ou=People,dc=example,dc=com")
+
+ args = FakeArgs()
+
+ args.value = "ou=People,dc=example,dc=com"
+ memberof_cli.add_scope(topology.standalone, None, topology.logcap.log, args)
+ assert topology.logcap.contains("is also listed as an exclude suffix")
+ topology.logcap.flush()
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
389-commits mailing list -- 389-commits@lists.fedoraproject.org
To unsubscribe send an email to 389-commits-leave@lists.fedoraproject.org
No comments:
Post a Comment