Example #1
0
 def test_envGet(self):
     c = conf.Config()
     log_path = c.log_file
     conf_path = c.config_file
     d1 = c.envGet()
     d2 = {'LXDUI_CONF': conf_path, 'LXDUI_LOG': log_path}
     self.assertDictEqual(d1, d2)
Example #2
0
 def test_external_config_empty_file(self):
     # assert = FileNotFoundError
     file = '../conf/lxdui.conf'
     if pathlib.Path(file).exists():
         os.remove(file)
     with self.assertRaises(Exception):
         conf.Config(conf='../conf/lxdui.conf.empty')
Example #3
0
 def test_envSet(self):
     c = conf.Config()
     log_path = '/path/to/log/file'
     conf_path = '/path/to/conf/file'
     c.envSet(log=log_path, conf=conf_path)
     d1 = c.envGet()
     d2 = {'LXDUI_CONF': conf_path, 'LXDUI_LOG': log_path}
     self.assertDictEqual(d1, d2)
Example #4
0
 def test_meta_config(self):
     # Tests the case when no conf file exists
     # assert = Config object (using default config from meta)
     file = '../conf/lxdui.conf'
     if pathlib.Path(file).exists():
         os.remove(file)
     time.sleep(1)
     c = conf.Config()
     self.assertIsInstance(c, conf.Config)
Example #5
0
    def __init__(self):
        try:
            self.auth_file = conf.Config().get(meta.APP_NAME, '{}.auth.conf'.format(meta.APP_NAME.lower()))
            self.users = self.load()
        except Exception('Unable to load configuration.') as e:
            log.debug(e)

        if self.users is None:
            print('Please initialize {} first.  e.g: {} init '.format(meta.APP_NAME, meta.APP_CLI_CMD))
            exit()
Example #6
0
    def test_save(self):
        file = pathlib.Path('../conf/lxdui.conf')
        file_before = 0
        file_after = 0

        if file.exists():
            file_before = file.stat()

        conf.Config().save()
        file_after = file.stat()
        self.assertEqual(file_before, file_after)
Example #7
0
 def __init__(self, password):
     c = conf.Config()
     self.password = auth.User.sha_password(password)
     self.username = c.get(self.APP, '{}.admin.user'.format(self.APP.lower()))
     self.auth_file = c.get(self.APP, '{}.auth.conf'.format(self.APP.lower()))
     self.cert_file = c.get(self.APP, '{}.ssl.cert'.format(self.APP.lower()))
     self.key_file = c.get(self.APP, '{}.ssl.key'.format(self.APP.lower()))
     self.key, self.cert = cert.Certificate().create()
     self.account = [{'username': self.username, 'password': self.password}]
     #self.create('auth', self.auth_file)
     #self.create('key', self.key_file)
     #self.create('cert', self.cert_file)
     log.debug('Initializing auth file with: username = {}, password = {}'.format(self.username, self.password))
     print('LXDUI is now configured.  You can now use '
           'the admin account to log in to the app.')
Example #8
0
    def delete(self, username):
        account, err = self.get(username)
        admin = conf.Config().get(meta.APP_NAME, '{}.admin.user'.format(meta.APP_NAME.lower()))

        if account is None:
            return err
            # raise Exception(err)

        # the admin user can't be deleted, panic!
        if username == admin:
            print('The admin user cannot be deleted.')
            exit(1)

        # remove the user from the list and save the new auth state
        else:
            self.users.remove(account)
            print('User "{}" has been deleted.'.format(username))
            self.save(self.users)
Example #9
0
 def test_config_show(self):
     print('='*120)
     conf.Config().show()
     print('=' * 120)
Example #10
0
 def test_envShow(self):
     conf.Config().envShow()
Example #11
0
 def test_parseConfig(self):
     # assert = configparser.ConfigParser
     file = pathlib.Path('../conf/lxdui.conf')
     c = conf.Config().parseConfig(file)
     self.assertIsInstance(c, configparser.ConfigParser)
Example #12
0
 def test_get(self):
     c = conf.Config().get('LXDUI', 'lxdui.port')
     self.assertEqual(c, '15151')
Example #13
0
 def test_ini_config(self):
     # assert = Config object
     c = conf.Config()
     self.assertIsInstance(c, conf.Config)
Example #14
0
 def test_getConfig_fnf(self):
     # assert = FileNotFoundError
     file = pathlib.Path('../conf/lxdui.conf.bad')
     with self.assertRaises(FileNotFoundError):
         conf.Config().getConfig(file)
Example #15
0
 def test_external_config_fnf(self):
     # assert = FileNotFoundError
     with self.assertRaises(FileNotFoundError):
         conf.Config(conf='../conf/lxdui.conf.bad')
Example #16
0
 def test_load_not_unknown(self):
     with self.assertRaises(Exception):
         conf.Config().load('foo')
Example #17
0
 def test_set(self):
     c = conf.Config()
     c.set('LXDUI', 'lxdui.port', '9999')
     port = c.config.get('LXDUI', 'lxdui.port')
     self.assertEqual(port, '9999')
Example #18
0
 def test_external_config(self):
     # assert = Config object
     c = conf.Config(conf='../conf/lxdui.conf')
     self.assertIsInstance(c, conf.Config)
Example #19
0
 def __init__(self):
     self.conf = conf.Config()
     self.key_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.key')
     self.cert_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.cert')
     self.key, self.cert = self.create()