Commit d27e68b1 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2710] Better handling of nonexistent file

parent 0a55e2f3
......@@ -509,8 +509,11 @@ class SecureHTTPServer(socketserver_mixin.NoPollMixIn,
'''Read all user's name and its' salt, hashed password
from accounts file.'''
# If the file does not exist, do nothing
# If the file does not exist, set accounts to empty, and return
if not os.path.exists(accounts_file):
self._user_infos = {}
self._accounts_file = accounts_file
self.__accounts_file_mtime = 0
# If the filename hasn't changed, and the file itself
......@@ -554,6 +554,22 @@ class TestSecureHTTPServer(unittest.TestCase):
self.assertEqual(1, len(self.server._user_infos))
self.assertTrue('otherroot' in self.server._user_infos)
def test_create_user_info_nonexistent_file(self):
# Even if there was data initially, if set to a nonexistent
# file it should result in no users
accounts_file = BUILD_FILE_PATH + 'new_file.csv'
fake_users_val = { 'notinfile': [] }
self.server._user_infos = fake_users_val
self.assertEqual({}, self.server._user_infos)
# Should it now be created it should be read
with TmpTextFile(accounts_file, ['root,foo,bar']):
self.assertEqual(1, len(self.server._user_infos))
self.assertTrue('root' in self.server._user_infos)
def test_check_file(self):
# Just some file that we know exists
file_name = BUILD_FILE_PATH + 'cmdctl-keyfile.pem'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment