Sfoglia il codice sorgente

htpasswd: ignore comments

Unrud 8 anni fa
parent
commit
f912642c20
2 ha cambiato i file con 4 aggiunte e 1 eliminazioni
  1. 1 1
      radicale/auth.py
  2. 3 0
      radicale/tests/test_auth.py

+ 1 - 1
radicale/auth.py

@@ -216,7 +216,7 @@ class Auth(BaseAuth):
             with open(self.filename) as f:
                 for line in f:
                     line = line.rstrip("\n")
-                    if line.lstrip():
+                    if line.lstrip() and not line.lstrip().startswith("#"):
                         try:
                             login, hash_value = line.split(":", maxsplit=1)
                             # Always compare both login and password to avoid

+ 3 - 0
radicale/tests/test_auth.py

@@ -121,6 +121,9 @@ class TestBaseAuthRequests(BaseTest):
         self._test_htpasswd("plain", " tmp : bepo ", (
             (" tmp ", " bepo ", 207), ("tmp", "bepo", 401)))
 
+    def test_htpasswd_comment(self):
+        self._test_htpasswd("plain", "#comment\n #comment\n \ntmp:bepo\n\n")
+
     def test_remote_user(self):
         self.configuration["auth"]["type"] = "remote_user"
         self.application = Application(self.configuration, self.logger)