|
|
@ -23,7 +23,7 @@ __metaclass__ = type
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import passlib
|
|
|
|
import passlib
|
|
|
|
from passlib.handlers import pbkdf2
|
|
|
|
from passlib.handlers import pbkdf2
|
|
|
|
except ImportError:
|
|
|
|
except ImportError: # pragma: nocover
|
|
|
|
passlib = None
|
|
|
|
passlib = None
|
|
|
|
pbkdf2 = None
|
|
|
|
pbkdf2 = None
|
|
|
|
|
|
|
|
|
|
|
@ -416,8 +416,6 @@ class BaseTestLookupModule(unittest.TestCase):
|
|
|
|
password.os.open = lambda path, flag: None
|
|
|
|
password.os.open = lambda path, flag: None
|
|
|
|
self.os_close = password.os.close
|
|
|
|
self.os_close = password.os.close
|
|
|
|
password.os.close = lambda fd: None
|
|
|
|
password.os.close = lambda fd: None
|
|
|
|
self.os_remove = password.os.remove
|
|
|
|
|
|
|
|
password.os.remove = lambda path: None
|
|
|
|
|
|
|
|
self.makedirs_safe = password.makedirs_safe
|
|
|
|
self.makedirs_safe = password.makedirs_safe
|
|
|
|
password.makedirs_safe = lambda path, mode: None
|
|
|
|
password.makedirs_safe = lambda path, mode: None
|
|
|
|
|
|
|
|
|
|
|
@ -425,7 +423,6 @@ class BaseTestLookupModule(unittest.TestCase):
|
|
|
|
password.os.path.exists = self.os_path_exists
|
|
|
|
password.os.path.exists = self.os_path_exists
|
|
|
|
password.os.open = self.os_open
|
|
|
|
password.os.open = self.os_open
|
|
|
|
password.os.close = self.os_close
|
|
|
|
password.os.close = self.os_close
|
|
|
|
password.os.remove = self.os_remove
|
|
|
|
|
|
|
|
password.makedirs_safe = self.makedirs_safe
|
|
|
|
password.makedirs_safe = self.makedirs_safe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -467,23 +464,17 @@ class TestLookupModuleWithoutPasslib(BaseTestLookupModule):
|
|
|
|
def test_lock_been_held(self, mock_sleep):
|
|
|
|
def test_lock_been_held(self, mock_sleep):
|
|
|
|
# pretend the lock file is here
|
|
|
|
# pretend the lock file is here
|
|
|
|
password.os.path.exists = lambda x: True
|
|
|
|
password.os.path.exists = lambda x: True
|
|
|
|
try:
|
|
|
|
with pytest.raises(AnsibleError):
|
|
|
|
with patch.object(builtins, 'open', mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
|
|
|
|
with patch.object(builtins, 'open', mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
|
|
|
|
# should timeout here
|
|
|
|
# should timeout here
|
|
|
|
results = self.password_lookup.run([u'/path/to/somewhere chars=anything'], None)
|
|
|
|
self.password_lookup.run([u'/path/to/somewhere chars=anything'], None)
|
|
|
|
self.fail("Lookup didn't timeout when lock already been held")
|
|
|
|
|
|
|
|
except AnsibleError:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_lock_not_been_held(self):
|
|
|
|
def test_lock_not_been_held(self):
|
|
|
|
# pretend now there is password file but no lock
|
|
|
|
# pretend now there is password file but no lock
|
|
|
|
password.os.path.exists = lambda x: x == to_bytes('/path/to/somewhere')
|
|
|
|
password.os.path.exists = lambda x: x == to_bytes('/path/to/somewhere')
|
|
|
|
try:
|
|
|
|
with patch.object(builtins, 'open', mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
|
|
|
|
with patch.object(builtins, 'open', mock_open(read_data=b'hunter42 salt=87654321\n')) as m:
|
|
|
|
# should not timeout here
|
|
|
|
# should not timeout here
|
|
|
|
results = self.password_lookup.run([u'/path/to/somewhere chars=anything'], None)
|
|
|
|
results = self.password_lookup.run([u'/path/to/somewhere chars=anything'], None)
|
|
|
|
|
|
|
|
except AnsibleError:
|
|
|
|
|
|
|
|
self.fail('Lookup timeouts when lock is free')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for result in results:
|
|
|
|
for result in results:
|
|
|
|
self.assertEqual(result, u'hunter42')
|
|
|
|
self.assertEqual(result, u'hunter42')
|
|
|
|