URL: https://github.com/freeipa/freeipa/pull/4991
Author: fcami
 Title: #4991: IPA-EPN: enhance input validation
Action: opened

PR body:
"""
Enhance input validation:
* make sure --from-nbdays and --to-nbdays are integer
* make sure --from-nbdays < --to-nbdays

Fixes: https://pagure.io/freeipa/issue/8444
Signed-off-by: François Cami <fc...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/4991/head:pr4991
git checkout pr4991
From dfdbce6563aaf33e8d3d997db512123add5aeaf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fc...@redhat.com>
Date: Tue, 4 Aug 2020 21:36:23 +0200
Subject: [PATCH] IPA-EPN: enhance input validation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Enhance input validation:
* make sure --from-nbdays and --to-nbdays are integer
* make sure --from-nbdays < --to-nbdays

Fixes: https://pagure.io/freeipa/issue/8444
Signed-off-by: François Cami <fc...@redhat.com>
---
 ipaclient/install/ipa_epn.py | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/ipaclient/install/ipa_epn.py b/ipaclient/install/ipa_epn.py
index 6e1b001464..23fa35a1a4 100644
--- a/ipaclient/install/ipa_epn.py
+++ b/ipaclient/install/ipa_epn.py
@@ -238,12 +238,35 @@ def add_options(cls, parser):
 
     def validate_options(self):
         super(EPN, self).validate_options(needs_root=True)
-        if self.options.to_nbdays:
+        if self.options.to_nbdays is not None:
+            try:
+                int(self.options.to_nbdays)
+                assert float(self.options.to_nbdays) == \
+                    int(self.options.to_nbdays)
+            except Exception as e:
+                self.option_parser.error(
+                    "--to-nbdays must be an integer. {error}".format(error=e)
+                )
             self.options.dry_run = True
-        if self.options.from_nbdays and not self.options.to_nbdays:
+        if self.options.from_nbdays is not None:
+            try:
+                int(self.options.from_nbdays)
+                assert float(self.options.from_nbdays) == \
+                    int(self.options.from_nbdays)
+            except Exception as e:
+                self.option_parser.error(
+                    "--from-nbdays must be an integer. {error}".format(error=e)
+                )
+        if self.options.from_nbdays is not None and not self.options.to_nbdays:
             self.option_parser.error(
                 "You cannot specify --from-nbdays without --to-nbdays"
             )
+        if self.options.from_nbdays is not None and \
+                self.options.to_nbdays is not None:
+            if self.options.from_nbdays >= self.options.to_nbdays:
+                self.option_parser.error(
+                    "--from-nbdays must be smaller than --to-nbdays."
+                )
         if self.options.mailtest and self.options.dry_run:
             self.option_parser.error(
                 "You cannot specify --mail-test and --dry-run together"
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to