Browse Source

[desktop] Raise an exception if the password script config fails

Erick Tryzelaar 10 years ago
parent
commit
a174aabd4c
2 changed files with 47 additions and 0 deletions
  1. 3 0
      desktop/core/src/desktop/conf.py
  2. 44 0
      desktop/core/src/desktop/tests.py

+ 3 - 0
desktop/core/src/desktop/conf.py

@@ -56,6 +56,9 @@ def coerce_password_from_script(script):
   p = subprocess.Popen(script, shell=True, stdout=subprocess.PIPE)
   p = subprocess.Popen(script, shell=True, stdout=subprocess.PIPE)
   password = p.communicate()[0]
   password = p.communicate()[0]
 
 
+  if p.returncode != 0:
+    raise subprocess.CalledProcessError(p.returncode, script)
+
   # whitespace may be significant in the password, but most files have a
   # whitespace may be significant in the password, but most files have a
   # trailing newline.
   # trailing newline.
   return password.strip('\n')
   return password.strip('\n')

+ 44 - 0
desktop/core/src/desktop/tests.py

@@ -19,6 +19,7 @@
 import json
 import json
 import logging
 import logging
 import os
 import os
+import subprocess
 import sys
 import sys
 import tempfile
 import tempfile
 import time
 import time
@@ -726,6 +727,32 @@ class BaseTestPasswordConfig(object):
       for reset in resets:
       for reset in resets:
         reset()
         reset()
 
 
+  @nottest
+  def run_test_password_script_raises_exception(self):
+    resets = [
+      self.get_config_password().set_for_testing(None),
+      self.get_config_password_script().set_for_testing(
+          '%s -c "import sys; sys.exit(1)"' % sys.executable
+      ),
+    ]
+
+    try:
+      assert_raises(subprocess.CalledProcessError, self.get_password)
+    finally:
+      for reset in resets:
+        reset()
+
+    resets = [
+      self.get_config_password().set_for_testing(None),
+      self.get_config_password_script().set_for_testing('/does-not-exist')
+    ]
+
+    try:
+      assert_raises(subprocess.CalledProcessError, self.get_password)
+    finally:
+      for reset in resets:
+        reset()
+
 
 
 class TestSecretKeyConfig(BaseTestPasswordConfig):
 class TestSecretKeyConfig(BaseTestPasswordConfig):
 
 
@@ -744,6 +771,9 @@ class TestSecretKeyConfig(BaseTestPasswordConfig):
   def test_config_password_overrides_script_password(self):
   def test_config_password_overrides_script_password(self):
     self.run_test_config_password_overrides_script_password()
     self.run_test_config_password_overrides_script_password()
 
 
+  def test_password_script_raises_exception(self):
+    self.run_test_password_script_raises_exception()
+
 
 
 class TestDatabasePasswordConfig(BaseTestPasswordConfig):
 class TestDatabasePasswordConfig(BaseTestPasswordConfig):
 
 
@@ -762,6 +792,9 @@ class TestDatabasePasswordConfig(BaseTestPasswordConfig):
   def test_config_password_overrides_script_password(self):
   def test_config_password_overrides_script_password(self):
     self.run_test_config_password_overrides_script_password()
     self.run_test_config_password_overrides_script_password()
 
 
+  def test_password_script_raises_exception(self):
+    self.run_test_password_script_raises_exception()
+
 
 
 class TestLDAPPasswordConfig(BaseTestPasswordConfig):
 class TestLDAPPasswordConfig(BaseTestPasswordConfig):
 
 
@@ -780,6 +813,10 @@ class TestLDAPPasswordConfig(BaseTestPasswordConfig):
   def test_config_password_overrides_script_password(self):
   def test_config_password_overrides_script_password(self):
     self.run_test_config_password_overrides_script_password()
     self.run_test_config_password_overrides_script_password()
 
 
+  def test_password_script_raises_exception(self):
+    self.run_test_password_script_raises_exception()
+
+
 class TestLDAPBindPasswordConfig(BaseTestPasswordConfig):
 class TestLDAPBindPasswordConfig(BaseTestPasswordConfig):
 
 
   def setup(self):
   def setup(self):
@@ -803,6 +840,10 @@ class TestLDAPBindPasswordConfig(BaseTestPasswordConfig):
   def test_config_password_overrides_script_password(self):
   def test_config_password_overrides_script_password(self):
     self.run_test_config_password_overrides_script_password()
     self.run_test_config_password_overrides_script_password()
 
 
+  def test_password_script_raises_exception(self):
+    self.run_test_password_script_raises_exception()
+
+
 class TestSMTPPasswordConfig(BaseTestPasswordConfig):
 class TestSMTPPasswordConfig(BaseTestPasswordConfig):
 
 
   def get_config_password(self):
   def get_config_password(self):
@@ -819,3 +860,6 @@ class TestSMTPPasswordConfig(BaseTestPasswordConfig):
 
 
   def test_config_password_overrides_script_password(self):
   def test_config_password_overrides_script_password(self):
     self.run_test_config_password_overrides_script_password()
     self.run_test_config_password_overrides_script_password()
+
+  def test_password_script_raises_exception(self):
+    self.run_test_password_script_raises_exception()