[Git][NTPsec/ntpsec][master] Added tests and comments to Authenticator.control()

Eric S. Raymond gitlab at mg.gitlab.com
Fri Jan 18 04:34:26 UTC 2019


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
121f4618 by Ian Bruene at 2019-01-18T04:34:21Z
Added tests and comments to Authenticator.control()

- - - - -


3 changed files:

- ntpclients/ntpq.py
- pylib/packet.py
- tests/pylib/test_packet.py


Changes:

=====================================
ntpclients/ntpq.py
=====================================
@@ -544,6 +544,8 @@ usage: poll [n] [verbose]
             self.session.password()
         except ntp.packet.ControlException as e:
             self.warn(e.message + "\n")
+        except IOError:
+            print("***Can't read control key from /etc/ntp.conf")
 
     def help_passwd(self):
         self.say("""\
@@ -1152,6 +1154,9 @@ usage: lopeers
         except ntp.packet.ControlException as e:
             self.warn(e.message + "\n")
             return
+        except IOError:
+            print("***Can't read control key from /etc/ntp.conf")
+            return
         if self.debug > 2:
             self.warn("In Config\nKeyword = :config\nCommand = %s\n" % line)
         try:
@@ -1298,6 +1303,8 @@ usage: mrulist [tag=value] [tag=value] [tag=value] [tag=value]
         except ntp.packet.ControlException as e:
             self.warn(e.message + "\n")
             return
+        except IOError:
+            print("***Can't read control key from /etc/ntp.conf")
 
     def help_ifstats(self):
         self.say("""\
@@ -1321,6 +1328,8 @@ usage: ifstats
         except ntp.packet.ControlException as e:
             self.warn(e.message + "\n")
             return
+        except IOError:
+            print("***Can't read control key from /etc/ntp.conf")
 
     def help_reslist(self):
         self.say("""\


=====================================
pylib/packet.py
=====================================
@@ -1603,11 +1603,13 @@ class Authenticator:
                 keyid = int(line.split()[1])
                 (keytype, passwd) = self.passwords[keyid]
                 if passwd is None:
+                    # Invalid key ID
                     raise ValueError
                 if len(passwd) > 20:
                     passwd = ntp.util.hexstr2octets(passwd)
                 return (keyid, keytype, passwd)
         else:
+            # No control lines found
             raise ValueError
 
     @staticmethod


=====================================
tests/pylib/test_packet.py
=====================================
@@ -1919,6 +1919,22 @@ class TestAuthenticator(unittest.TestCase):
             except ValueError:
                 errored = True
             self.assertEqual(errored, True)
+            # Malformed control line
+            self.open_data = ["control foo"]
+            try:
+                cls.control()
+                errored = False
+            except ValueError:
+                errored = True
+            self.assertEqual(errored, True)
+            # Non-existent key
+            self.open_data = ["control 42"]
+            try:
+                cls.control()
+                errored = False
+            except KeyError:
+                errored = True
+            self.assertEqual(errored, True)
         finally:
             ntpp.open = open
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/121f461806bca542f370b11e9d7635c682477bbd

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/121f461806bca542f370b11e9d7635c682477bbd
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190118/5f59c832/attachment-0001.html>


More information about the vc mailing list