only allow absolute php ini paths
This commit is contained in:
Родитель
3b4ec2beb2
Коммит
0ecb3ded6c
|
@ -73,6 +73,9 @@ class ConfigValidator:
|
|||
if config.apilevel not in ['v1-2', 'v2']:
|
||||
result += ['Unknown apilevel: %s' % config.apilevel]
|
||||
|
||||
if config.phpini and not os.path.isabs(config.phpini):
|
||||
result += ['Path to php.ini must be absolute']
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class TestCli(TestCase):
|
|||
self.cli = MagicMock(spec=Cli)
|
||||
self.container.register(Cli, lambda c: self.cli)
|
||||
self.base_url = '/'
|
||||
self.phpini = '/path/to/ini'
|
||||
|
||||
def _set_config(self, **kwargs):
|
||||
config = Config()
|
||||
|
@ -35,8 +36,12 @@ class TestCli(TestCase):
|
|||
api = self.container.resolve(CliApi)
|
||||
self.assertIsInstance(api, CliApiV2)
|
||||
|
||||
def _create_commands(self):
|
||||
base_cmd = ['php', '-f', '%socc' % self.base_url]
|
||||
def _create_commands(self, phpini_path=None):
|
||||
if phpini_path:
|
||||
phpini_cmd = ['-c', phpini_path]
|
||||
else:
|
||||
phpini_cmd = []
|
||||
base_cmd = ['php', '-f', '%socc' % self.base_url] + phpini_cmd
|
||||
before_cmd = base_cmd + ['news:updater:before-update']
|
||||
feeds_cmd = base_cmd + ['news:updater:all-feeds']
|
||||
update_cmd1 = base_cmd + ['news:updater:update-feed', '2', 'deb']
|
||||
|
@ -70,3 +75,29 @@ class TestCli(TestCase):
|
|||
updater.run()
|
||||
|
||||
self.assertIn(self.cli.run.call_args_list, self._create_commands())
|
||||
|
||||
def test_api_v2_calls_phpini(self):
|
||||
self._set_config(apilevel='v2', url=self.base_url, mode='singlerun',
|
||||
phpini=self.phpini)
|
||||
updater = self.container.resolve(Updater)
|
||||
self._set_cli_run({
|
||||
'data': {
|
||||
'updater': [{'feedId': 3, 'userId': 'john'},
|
||||
{'feedId': 2, 'userId': 'deb'}]
|
||||
}
|
||||
})
|
||||
updater.run()
|
||||
|
||||
self.assertIn(self.cli.run.call_args_list,
|
||||
self._create_commands(self.phpini))
|
||||
|
||||
def test_api_v1_calls_phpini(self):
|
||||
self._set_config(apilevel='v1-2', url=self.base_url, mode='singlerun',
|
||||
phpini=self.phpini)
|
||||
updater = self.container.resolve(Updater)
|
||||
self._set_cli_run({
|
||||
'feeds': [{'id': 3, 'userId': 'john'}, {'id': 2, 'userId': 'deb'}]
|
||||
})
|
||||
updater.run()
|
||||
self.assertIn(self.cli.run.call_args_list,
|
||||
self._create_commands(self.phpini))
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from unittest import TestCase
|
||||
from configparser import MissingSectionHeaderError
|
||||
|
||||
from owncloud_news_updater.common.argumentparser import ArgumentParser
|
||||
from owncloud_news_updater.config import InvalidConfigException, \
|
||||
ConfigParser, merge_configs, ConfigValidator, InvalidConfigKeyException
|
||||
ConfigParser, merge_configs, ConfigValidator, InvalidConfigKeyException, \
|
||||
Config
|
||||
from owncloud_news_updater.container import Container
|
||||
from tests.owncloud_news_updater import find_test_config, assert_raises
|
||||
|
||||
|
||||
|
@ -10,11 +13,19 @@ class Args:
|
|||
def __init__(self):
|
||||
self.user = 'john'
|
||||
self.threads = 100
|
||||
self.config = None
|
||||
|
||||
def parse(self):
|
||||
return self
|
||||
|
||||
def print_help(self, file):
|
||||
pass
|
||||
|
||||
|
||||
class TestConfig(TestCase):
|
||||
def setUp(self):
|
||||
self.parser = ConfigParser()
|
||||
self.container = Container()
|
||||
|
||||
def test_parse_full(self):
|
||||
config = self.parser.parse_file(find_test_config('full.ini'))
|
||||
|
@ -102,6 +113,13 @@ class TestConfig(TestCase):
|
|||
result = validator.validate(config)
|
||||
self.assertListEqual(['Unknown loglevel: debug'], result)
|
||||
|
||||
def test_validate_invalid_phpini(self):
|
||||
config = self.parser.parse_file(find_test_config('full.ini'))
|
||||
config.phpini = 'php.ini'
|
||||
validator = ConfigValidator()
|
||||
result = validator.validate(config)
|
||||
self.assertListEqual(['Path to php.ini must be absolute'], result)
|
||||
|
||||
def test_validate_ok(self):
|
||||
config = self.parser.parse_file(find_test_config('full.ini'))
|
||||
validator = ConfigValidator()
|
||||
|
@ -119,3 +137,18 @@ class TestConfig(TestCase):
|
|||
@assert_raises(InvalidConfigKeyException)
|
||||
def test_load_fails(self):
|
||||
self.parser.parse_file(find_test_config('unknown_key.ini'))
|
||||
|
||||
def test_integration_merge(self):
|
||||
args = Args()
|
||||
args.config = find_test_config('full.ini')
|
||||
self.container.register(ArgumentParser, lambda c: args)
|
||||
config = self.container.resolve(Config)
|
||||
self.assertEqual(config.user, 'john')
|
||||
self.assertEqual(config.password, 'pass')
|
||||
self.assertEqual(config.threads, 100)
|
||||
self.assertEqual(config.interval, 9)
|
||||
self.assertEqual(config.loglevel, 'info')
|
||||
self.assertEqual(config.url, '/')
|
||||
self.assertEqual(config.phpini, '/path/to/custom/php.ini')
|
||||
self.assertEqual(config.apilevel, 'v2')
|
||||
self.assertEqual(config.mode, 'singlerun')
|
||||
|
|
Загрузка…
Ссылка в новой задаче