f65af0
From 2461d69242108fe6f4bc067cc8255e41f66c58aa Mon Sep 17 00:00:00 2001
f65af0
From: Armando Neto <neto.armando@gmail.com>
f65af0
Date: Mon, 18 Jun 2018 18:26:01 -0300
f65af0
Subject: [PATCH] ipaserver config plugin: Increase search records minimum
f65af0
 limit
f65af0
f65af0
Check if the given search records value is greater than an arbitrary number that is not so close to zero.
f65af0
f65af0
https://pagure.io/freeipa/issue/6617
f65af0
f65af0
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
f65af0
---
f65af0
 ipaserver/plugins/config.py                | 14 +++++-
f65af0
 ipatests/test_xmlrpc/test_config_plugin.py | 76 ++++++++++++++++++++++++++++++
f65af0
 2 files changed, 89 insertions(+), 1 deletion(-)
f65af0
f65af0
diff --git a/ipaserver/plugins/config.py b/ipaserver/plugins/config.py
f65af0
index 33ed38ba016567b9df57503f2f8418cf7c7fc794..d367c3c5aa421bb22d1630c88bbac846e7d84386 100644
f65af0
--- a/ipaserver/plugins/config.py
f65af0
+++ b/ipaserver/plugins/config.py
f65af0
@@ -85,6 +85,18 @@ EXAMPLES:
f65af0
 
f65af0
 register = Registry()
f65af0
 
f65af0
+
f65af0
+def validate_search_records_limit(ugettext, value):
f65af0
+    """Check if value is greater than a realistic minimum.
f65af0
+
f65af0
+    Values 0 and -1 are valid, as they represent unlimited.
f65af0
+    """
f65af0
+    if value in {-1, 0}:
f65af0
+        return
f65af0
+    if value < 10:
f65af0
+        return _('must be at least 10')
f65af0
+
f65af0
+
f65af0
 @register()
f65af0
 class config(LDAPObject):
f65af0
     """
f65af0
@@ -161,10 +173,10 @@ class config(LDAPObject):
f65af0
             minvalue=-1,
f65af0
         ),
f65af0
         Int('ipasearchrecordslimit',
f65af0
+            validate_search_records_limit,
f65af0
             cli_name='searchrecordslimit',
f65af0
             label=_('Search size limit'),
f65af0
             doc=_('Maximum number of records to search (-1 or 0 is unlimited)'),
f65af0
-            minvalue=-1,
f65af0
         ),
f65af0
         IA5Str('ipausersearchfields',
f65af0
             cli_name='usersearch',
f65af0
diff --git a/ipatests/test_xmlrpc/test_config_plugin.py b/ipatests/test_xmlrpc/test_config_plugin.py
f65af0
index c037224162e2c29f6dd76eabefe7fededc6f882d..666b7c2c87b4f0a1f7bde18c78780a1ea6072b71 100644
f65af0
--- a/ipatests/test_xmlrpc/test_config_plugin.py
f65af0
+++ b/ipatests/test_xmlrpc/test_config_plugin.py
f65af0
@@ -211,4 +211,80 @@ class test_config(Declarative):
f65af0
                 summary=None,
f65af0
                 ),
f65af0
         ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records to -1 (unlimited)',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'-1',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected={
f65af0
+                'result': lambda d: d['ipasearchrecordslimit'] == (u'-1',),
f65af0
+                'summary': None,
f65af0
+                'value': None,
f65af0
+            },
f65af0
+        ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records to greater than 10',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'100',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected={
f65af0
+                'result': lambda d: d['ipasearchrecordslimit'] == (u'100',),
f65af0
+                'summary': None,
f65af0
+                'value': None,
f65af0
+            },
f65af0
+        ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records to lower than -1',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'-10',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected=errors.ValidationError(
f65af0
+                name=u'searchrecordslimit',
f65af0
+                error=u'must be at least 10',
f65af0
+            ),
f65af0
+        ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records to lower than 10',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'1',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected=errors.ValidationError(
f65af0
+                name=u'searchrecordslimit',
f65af0
+                error=u'must be at least 10',
f65af0
+            ),
f65af0
+        ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records to zero (unlimited)',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'0',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected={
f65af0
+                'result': lambda d: d['ipasearchrecordslimit'] == (u'-1',),
f65af0
+                'summary': None,
f65af0
+                'value': None,
f65af0
+            },
f65af0
+        ),
f65af0
+        dict(
f65af0
+            desc='Set the number of search records back to 100',
f65af0
+            command=(
f65af0
+                'config_mod', [], {
f65af0
+                    'ipasearchrecordslimit': u'100',
f65af0
+                },
f65af0
+            ),
f65af0
+            expected={
f65af0
+                'result': lambda d: d['ipasearchrecordslimit'] == (u'100',),
f65af0
+                'summary': None,
f65af0
+                'value': None,
f65af0
+            },
f65af0
+        ),
f65af0
     ]
f65af0
-- 
f65af0
2.14.4
f65af0