[PATCH 2/3] Add check testing visibility of password entries

Vratislav Podzimek vpodzime at redhat.com
Fri Nov 29 11:06:42 UTC 2013


All password entrires should have visibility set to False. We can check for
problematic cases if we stick to a simple naming convention for the password
entry widgets.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 tests/Makefile.am                                  |  4 +-
 tests/glade/pw_visibility/check_pw_visibility.py   | 81 ++++++++++++++++++++++
 .../glade/pw_visibility/run_check_pw_visibility.sh |  6 ++
 3 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100755 tests/glade/pw_visibility/check_pw_visibility.py
 create mode 100755 tests/glade/pw_visibility/run_check_pw_visibility.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2feab20..0dd998a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,6 +38,7 @@ dist_check_DATA = pylint/pylint-false-positives
 # Test scripts need to be listed both here and in TESTS
 dist_check_SCRIPTS = glade/accelerators/check_accelerators.py \
 		     glade/accelerators/run_check_accelerators.sh \
+             glade/pw_visibility/run_check_pw_visibility.sh \
 		     nosetests.sh \
 		     pylint/intl.py \
 		     pylint/preconf.py \
@@ -53,7 +54,8 @@ TESTS = nosetests.sh \
 	pylint/runpylint.sh \
 	gettext/gettext_warnings.sh \
 	storage/run_storage_tests.py \
-	glade/accelerators/run_check_accelerators.sh
+	glade/accelerators/run_check_accelerators.sh \
+	glade/pw_visibility/run_check_pw_visibility.sh
 
 clean-local:
 	-rm -rf pylint/.pylint.d
diff --git a/tests/glade/pw_visibility/check_pw_visibility.py b/tests/glade/pw_visibility/check_pw_visibility.py
new file mode 100755
index 0000000..aac7130
--- /dev/null
+++ b/tests/glade/pw_visibility/check_pw_visibility.py
@@ -0,0 +1,81 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2013  Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Vratislav Podzimek <vpodzime at redhat.com>
+#
+
+"""
+Simple python script checking that password GtkEntries in the given .glade files
+have the visibility set to False.
+
+"""
+
+import sys
+
+try:
+    from lxml import etree
+except ImportError:
+    print("You need to install the python-lxml package to use check_pw_visibility.py")
+    sys.exit(1)
+
+PW_ID_INDICATORS = ("pw", "password", "passwd", "passphrase")
+
+def check_glade_file(glade_file_path):
+    def check_entry(entry, fpath):
+        succ = True
+
+        entry_id = entry.attrib.get("id", "UNKNOWN ID")
+        visibility_props = entry.xpath("./property[@name='visibility']")
+
+        # no entry should have visibility specified multiple times
+        if len(visibility_props) > 1:
+            print "Visibility specified multiple times for the entry %s (%s)" % (entry_id, fpath)
+            succ = False
+
+        # password entry should have visibility set to False
+        if any(ind in entry_id.lower() for ind in PW_ID_INDICATORS):
+            if not visibility_props:
+                print "Visibility not specified for the password entry %s (%s)" % (entry_id, fpath)
+                succ = False
+            elif visibility_props[0].text.strip() != "False":
+                print "Visibility not set properly for the password entry %s (%s)" % (entry_id, fpath)
+                succ = False
+        # only password entries should have the visibility set to False
+        elif visibility_props and visibility_props[0].text.strip() == "False":
+            print "Non-password entry %s (%s) has the visibility set to False (bad id?)" % (entry_id, fpath)
+            succ = False
+
+        return succ
+
+    succ = True
+    with open(glade_file_path, "r") as glade_file:
+        tree = etree.parse(glade_file)
+        for entry in tree.xpath("//object[@class='GtkEntry']"):
+            succ = succ and check_entry(entry, glade_file_path)
+
+        return succ
+
+if __name__ == "__main__":
+    if len(sys.argv) < 2:
+        print "Need to specify .glade files to check"
+        sys.exit(1)
+
+    succ = True
+    for fpath in sys.argv[1:]:
+        succ = succ and check_glade_file(fpath)
+
+    sys.exit(0 if succ else 1)
diff --git a/tests/glade/pw_visibility/run_check_pw_visibility.sh b/tests/glade/pw_visibility/run_check_pw_visibility.sh
new file mode 100755
index 0000000..3b58830
--- /dev/null
+++ b/tests/glade/pw_visibility/run_check_pw_visibility.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+: "${top_srcdir:=$(dirname "$0")/../..}"
+srcdir="${top_srcdir}/tests/glade/pw_visibility"
+
+find "${top_srcdir}/pyanaconda" -name '*.glade' -exec "${srcdir}/check_pw_visibility.py" "$@" {} +
-- 
1.8.4.2



More information about the anaconda-patches mailing list