[node-patches] Change in ovirt-node[master]: rhn_page: Add validators for username and profile

dougsland at redhat.com dougsland at redhat.com
Sat Apr 11 13:44:18 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: rhn_page: Add validators for username and profile
......................................................................

rhn_page: Add validators for username and profile

Username and Profile field must have the ASCII validator.

Change-Id: I34f80719034f28b252a889230753dd79d288b279
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1055916
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M src/ovirt/node/setup/rhn/rhn_page.py
M src/ovirt/node/valid.py
2 files changed, 24 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/65/39765/1

diff --git a/src/ovirt/node/setup/rhn/rhn_page.py b/src/ovirt/node/setup/rhn/rhn_page.py
index 35d7d64..fa7cfc2 100644
--- a/src/ovirt/node/setup/rhn/rhn_page.py
+++ b/src/ovirt/node/setup/rhn/rhn_page.py
@@ -156,8 +156,8 @@
         return model
 
     def validators(self):
-        return {"rhn.user": valid.Text(),
-                "rhn.profilename": valid.Empty() | valid.Text(),
+        return {"rhn.username": valid.IsAscii(),
+                "rhn.profilename": valid.IsAscii() | valid.Empty(),
                 "rhn.url": valid.Empty() | valid.URL(),
                 "rhn.ca": valid.Empty() | valid.URL(),
                 "rhn.proxyhost": (valid.FQDNOrIPAddress() |
diff --git a/src/ovirt/node/valid.py b/src/ovirt/node/valid.py
index bfdc3be..18b71d1 100644
--- a/src/ovirt/node/valid.py
+++ b/src/ovirt/node/valid.py
@@ -322,6 +322,28 @@
         return is_valid
 
 
+class IsAscii(Validator):
+    """ Checks if the param is ascii or not.
+
+    >>> IsAscii().validate('rhn.user.123')
+    True
+    >>> IsAscii().validate('rhn.usê€')
+    False
+    >>> IsAscii().validate('rhn.正體字')
+    False
+    """
+
+    description = "a valid ASCII char(s) field"
+
+    def validate(self, value):
+        valid = True
+        try:
+            value.decode('ascii')
+        except:
+            valid = False
+        return valid
+
+
 class HostnameLength(Validator):
     """hostname or hostnamectl tools only accepts 64 chars or less
 


-- 
To view, visit https://gerrit.ovirt.org/39765
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34f80719034f28b252a889230753dd79d288b279
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list