Tests: fixed PHP "disable_functions" and "disable_classes" tests.

This commit is contained in:
Andrey Zelenkov
2019-02-28 21:18:33 +03:00
parent a5dd0f8aa9
commit 38ea191fbb
4 changed files with 60 additions and 69 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
$d = new DateTime('2011-01-01T15:03:01.012345Z'); date_default_timezone_set('Europe/Moscow');
$d = new DateTime('2011-01-01T15:03:01.012345');
echo $d->format('u'); echo $d->format('u');
?> ?>

View File

@@ -1,4 +0,0 @@
<?php
highlight_file('index.php');
exec('pwd');
?>

View File

@@ -0,0 +1,4 @@
<?php
echo 'time: ' . time();
echo 'exec: ' . exec('pwd');
?>

View File

@@ -7,9 +7,11 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
def setUpClass(): def setUpClass():
unit.TestUnit().check_modules('php') unit.TestUnit().check_modules('php')
def search_disabled(self, name): def before_disable_functions(self):
p = re.compile(name + '\(\) has been disabled') body = self.get()['body']
return self.search_in_log(p)
self.assertRegex(body, r'time: \d+', 'disable_functions before time')
self.assertRegex(body, r'exec: \/\w+', 'disable_functions before exec')
def test_php_application_variables(self): def test_php_application_variables(self):
self.load('variables') self.load('variables')
@@ -239,109 +241,97 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP):
'ini value repeat') 'ini value repeat')
def test_php_application_disable_functions_exec(self): def test_php_application_disable_functions_exec(self):
self.load('highlight_file_exec') self.load('time_exec')
self.before_disable_functions()
self.conf({"admin": { "disable_functions": "exec" }}, self.conf({"admin": { "disable_functions": "exec" }},
'applications/highlight_file_exec/options') 'applications/time_exec/options')
self.get() body = self.get()['body']
self.assertIsNotNone(self.search_disabled('exec'), self.assertRegex(body, r'time: \d+', 'disable_functions time')
'disable_functions exec') self.assertNotRegex(body, r'exec: \/\w+', 'disable_functions exec')
self.assertIsNone(self.search_disabled('highlight_file'),
'disable_functions highlight_file')
def test_php_application_disable_functions_highlight_file(self):
self.load('highlight_file_exec')
self.conf({"admin": { "disable_functions": "highlight_file" }},
'applications/highlight_file_exec/options')
self.get()
self.assertIsNone(self.search_disabled('exec'),
'disable_functions exec')
self.assertIsNotNone(self.search_disabled('highlight_file'),
'disable_functions highlight_file')
def test_php_application_disable_functions_comma(self): def test_php_application_disable_functions_comma(self):
self.load('highlight_file_exec') self.load('time_exec')
self.conf({"admin": { "disable_functions": "exec,highlight_file" }}, self.before_disable_functions()
'applications/highlight_file_exec/options')
self.get() self.conf({"admin": { "disable_functions": "exec,time" }},
'applications/time_exec/options')
self.assertIsNotNone(self.search_disabled('exec'), body = self.get()['body']
'disable_functions exec')
self.assertIsNotNone(self.search_disabled('highlight_file'), self.assertNotRegex(body, r'time: \d+', 'disable_functions comma time')
'disable_functions highlight_file') self.assertNotRegex(body, r'exec: \/\w+',
'disable_functions comma exec')
def test_php_application_disable_functions_space(self): def test_php_application_disable_functions_space(self):
self.load('highlight_file_exec') self.load('time_exec')
self.conf({"admin": { "disable_functions": "exec highlight_file" }}, self.before_disable_functions()
'applications/highlight_file_exec/options')
self.get() self.conf({"admin": { "disable_functions": "exec time" }},
'applications/time_exec/options')
self.assertIsNotNone(self.search_disabled('exec'), body = self.get()['body']
'disable_functions exec')
self.assertIsNotNone(self.search_disabled('highlight_file'), self.assertNotRegex(body, r'time: \d+', 'disable_functions space time')
'disable_functions highlight_file') self.assertNotRegex(body, r'exec: \/\w+',
'disable_functions space exec')
def test_php_application_disable_functions_user(self): def test_php_application_disable_functions_user(self):
self.load('highlight_file_exec') self.load('time_exec')
self.before_disable_functions()
self.conf({"user": { "disable_functions": "exec" }}, self.conf({"user": { "disable_functions": "exec" }},
'applications/highlight_file_exec/options') 'applications/time_exec/options')
self.get() body = self.get()['body']
self.assertIsNotNone(self.search_disabled('exec'), self.assertRegex(body, r'time: \d+', 'disable_functions user time')
'disable_functions exec') self.assertNotRegex(body, r'exec: \/\w+', 'disable_functions user exec')
self.assertIsNone(self.search_disabled('highlight_file'),
'disable_functions highlight_file')
def test_php_application_disable_functions_nonexistent(self): def test_php_application_disable_functions_nonexistent(self):
self.load('highlight_file_exec') self.load('time_exec')
self.before_disable_functions()
self.conf({"admin": { "disable_functions": "blah" }}, self.conf({"admin": { "disable_functions": "blah" }},
'applications/highlight_file_exec/options') 'applications/time_exec/options')
self.get() body = self.get()['body']
self.assertIsNone(self.search_disabled('exec'), self.assertRegex(body, r'time: \d+',
'disable_functions exec') 'disable_functions nonexistent time')
self.assertIsNone(self.search_disabled('highlight_file'), self.assertRegex(body, r'exec: \/\w+',
'disable_functions highlight_file') 'disable_functions nonexistent exec')
def test_php_application_disable_classes(self): def test_php_application_disable_classes(self):
self.load('date_time') self.load('date_time')
self.get() self.assertRegex(self.get()['body'], r'012345',
self.assertIsNone(self.search_disabled('DateTime'),
'disable_classes before') 'disable_classes before')
self.conf({"admin": { "disable_classes": "DateTime" }}, self.conf({"admin": { "disable_classes": "DateTime" }},
'applications/date_time/options') 'applications/date_time/options')
self.get() self.assertNotRegex(self.get()['body'], r'012345',
'disable_classes before')
self.assertIsNotNone(self.search_disabled('DateTime'),
'disable_classes')
def test_php_application_disable_classes_user(self): def test_php_application_disable_classes_user(self):
self.load('date_time') self.load('date_time')
self.assertRegex(self.get()['body'], r'012345',
'disable_classes before')
self.conf({"user": { "disable_classes": "DateTime" }}, self.conf({"user": { "disable_classes": "DateTime" }},
'applications/date_time/options') 'applications/date_time/options')
self.get() self.assertNotRegex(self.get()['body'], r'012345',
'disable_classes before')
self.assertIsNotNone(self.search_disabled('DateTime'),
'disable_classes user')
if __name__ == '__main__': if __name__ == '__main__':
TestUnitPHPApplication.main() TestUnitPHPApplication.main()