From 91a5d3349be3a8c6044684405a4e66f4ed1dd543 Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Mon, 10 Jun 2013 18:57:08 -0400 Subject: Require rid-base and secondary-rid-base in idrange-add after ipa-adtrust-install Add a new API command 'adtrust_is_enabled', which can be used to determine whether ipa-adtrust-install has been run on the system. This new command is not visible in IPA CLI. Use this command in idrange_add to conditionally require rid-base and secondary-rid-base options. Add tests to cover the new functionality https://fedorahosted.org/freeipa/ticket/3634 --- ipatests/test_cmdline/test_cli.py | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'ipatests/test_cmdline/test_cli.py') diff --git a/ipatests/test_cmdline/test_cli.py b/ipatests/test_cmdline/test_cli.py index fe411b70..fe5ffacd 100644 --- a/ipatests/test_cmdline/test_cli.py +++ b/ipatests/test_cmdline/test_cli.py @@ -325,3 +325,77 @@ class TestCLIParsing(object): force=False, version=API_VERSION ) + + def test_idrange_add(self): + """ + Test idrange-add with interative prompt + """ + def test_with_interactive_input(): + with self.fake_stdin('5\n500000\n'): + self.check_command( + 'idrange_add range1 --base-id=1 --range-size=1', + 'idrange_add', + cn=u'range1', + ipabaseid=u'1', + ipaidrangesize=u'1', + ipabaserid=5, + ipasecondarybaserid=500000, + all=False, + raw=False, + version=API_VERSION + ) + + def test_with_command_line_options(): + self.check_command( + 'idrange_add range1 --base-id=1 --range-size=1 ' + '--rid-base=5 --secondary-rid-base=500000', + 'idrange_add', + cn=u'range1', + ipabaseid=u'1', + ipaidrangesize=u'1', + ipabaserid=u'5', + ipasecondarybaserid=u'500000', + all=False, + raw=False, + version=API_VERSION + ) + + def test_without_options(): + self.check_command( + 'idrange_add range1 --base-id=1 --range-size=1', + 'idrange_add', + cn=u'range1', + ipabaseid=u'1', + ipaidrangesize=u'1', + all=False, + raw=False, + version=API_VERSION + ) + + adtrust_dn = 'cn=ADTRUST,cn=%s,cn=masters,cn=ipa,cn=etc,%s' % \ + (api.env.host, api.env.basedn) + adtrust_is_enabled = api.Command['adtrust_is_enabled']()['result'] + mockldap = None + + if not adtrust_is_enabled: + # ipa-adtrust-install not run - no need to pass rid-base + # and secondary-rid-base + test_without_options() + + # Create a mock service object to test against + adtrust_add = dict( + ipaconfigstring='enabledService', + objectclass=['top', 'nsContainer', 'ipaConfigObject'] + ) + + mockldap = util.MockLDAP() + mockldap.add_entry(adtrust_dn, adtrust_add) + + # Pass rid-base and secondary-rid-base interactively + test_with_interactive_input() + + # Pass rid-base and secondary-rid-base on the command-line + test_with_command_line_options() + + if not adtrust_is_enabled: + mockldap.del_entry(adtrust_dn) -- cgit