diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/php/cwd/index.php | 19 | ||||
-rw-r--r-- | test/php/cwd/subdir/index.php | 1 | ||||
-rw-r--r-- | test/php/open/index.php | 7 | ||||
-rw-r--r-- | test/php/open/test.txt | 1 | ||||
-rw-r--r-- | test/test_php_application.py | 135 | ||||
-rw-r--r-- | test/unit/applications/lang/php.py | 4 |
6 files changed, 161 insertions, 6 deletions
diff --git a/test/php/cwd/index.php b/test/php/cwd/index.php new file mode 100644 index 00000000..24ae3a21 --- /dev/null +++ b/test/php/cwd/index.php @@ -0,0 +1,19 @@ +<?php + +if (isset($_GET['chdir']) && $_GET['chdir'] != "") { + if (!chdir($_GET['chdir'])) { + echo "failure to chdir(" . $_GET['chdir'] . ")\n"; + exit; + } +} + +$opcache = -1; + +if (function_exists('opcache_get_status')) { + $opcache = opcache_get_status()->opcache_enabled; +} + +header('X-OPcache: ' . $opcache); + +print(getcwd()); +?> diff --git a/test/php/cwd/subdir/index.php b/test/php/cwd/subdir/index.php new file mode 100644 index 00000000..597bcac4 --- /dev/null +++ b/test/php/cwd/subdir/index.php @@ -0,0 +1 @@ +<?php print(getcwd()); ?> diff --git a/test/php/open/index.php b/test/php/open/index.php new file mode 100644 index 00000000..a5bebc54 --- /dev/null +++ b/test/php/open/index.php @@ -0,0 +1,7 @@ +<?php +if (isset($_GET['chdir'])) { + chdir($_GET['chdir']); +} + +echo file_get_contents('test.txt'); +?> diff --git a/test/php/open/test.txt b/test/php/open/test.txt new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/test/php/open/test.txt @@ -0,0 +1 @@ +test
\ No newline at end of file diff --git a/test/test_php_application.py b/test/test_php_application.py index 37606fa2..c3645a99 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -13,6 +13,28 @@ class TestPHPApplication(TestApplicationPHP): self.assertRegex(body, r'time: \d+', 'disable_functions before time') self.assertRegex(body, r'exec: \/\w+', 'disable_functions before exec') + def set_opcache(self, app, val): + self.assertIn( + 'success', + self.conf( + { + "admin": { + "opcache.enable": val, + "opcache.enable_cli": val, + }, + }, + 'applications/' + app + '/options', + ), + ) + + opcache = self.get()['headers']['X-OPcache'] + + if not opcache or opcache == '-1': + print('opcache is not supported') + raise unittest.SkipTest() + + self.assertEqual(opcache, val, 'opcache value') + def test_php_application_variables(self): self.load('variables') @@ -466,7 +488,8 @@ class TestPHPApplication(TestApplicationPHP): def test_php_application_script(self): self.assertIn( - 'success', self.conf( + 'success', + self.conf( { "listeners": {"*:7080": {"pass": "applications/script"}}, "applications": { @@ -478,7 +501,8 @@ class TestPHPApplication(TestApplicationPHP): } }, } - ), 'configure script' + ), + 'configure script', ) resp = self.get() @@ -488,7 +512,8 @@ class TestPHPApplication(TestApplicationPHP): def test_php_application_index_default(self): self.assertIn( - 'success', self.conf( + 'success', + self.conf( { "listeners": {"*:7080": {"pass": "applications/phpinfo"}}, "applications": { @@ -499,7 +524,8 @@ class TestPHPApplication(TestApplicationPHP): } }, } - ), 'configure index default' + ), + 'configure index default', ) resp = self.get() @@ -541,6 +567,107 @@ class TestPHPApplication(TestApplicationPHP): str(resp['status']) + resp['body'], '200', 'status new root' ) + def run_php_application_cwd_root_tests(self): + self.assertIn( + 'success', self.conf_delete('applications/cwd/working_directory') + ) + + script_cwd = self.current_dir + '/php/cwd' + + resp = self.get() + self.assertEqual(resp['status'], 200, 'status ok') + self.assertEqual(resp['body'], script_cwd, 'default cwd') + + self.assertIn( + 'success', + self.conf( + '"' + self.current_dir + '"', + 'applications/cwd/working_directory', + ), + ) + + resp = self.get() + self.assertEqual(resp['status'], 200, 'status ok') + self.assertEqual(resp['body'], script_cwd, 'wdir cwd') + + resp = self.get(url='/?chdir=/') + self.assertEqual(resp['status'], 200, 'status ok') + self.assertEqual(resp['body'], '/', 'cwd after chdir') + + # cwd must be restored + + resp = self.get() + self.assertEqual(resp['status'], 200, 'status ok') + self.assertEqual(resp['body'], script_cwd, 'cwd restored') + + resp = self.get(url='/subdir/') + self.assertEqual( + resp['body'], script_cwd + '/subdir', 'cwd subdir', + ) + + def test_php_application_cwd_root(self): + self.load('cwd') + self.run_php_application_cwd_root_tests() + + def test_php_application_cwd_opcache_disabled(self): + self.load('cwd') + self.set_opcache('cwd', '0') + self.run_php_application_cwd_root_tests() + + def test_php_application_cwd_opcache_enabled(self): + self.load('cwd') + self.set_opcache('cwd', '1') + self.run_php_application_cwd_root_tests() + + def run_php_application_cwd_script_tests(self): + self.load('cwd') + + script_cwd = self.current_dir + '/php/cwd' + + self.assertIn( + 'success', self.conf_delete('applications/cwd/working_directory') + ) + + self.assertIn( + 'success', self.conf('"index.php"', 'applications/cwd/script') + ) + + self.assertEqual( + self.get()['body'], script_cwd, 'default cwd', + ) + + self.assertEqual( + self.get(url='/?chdir=/')['body'], '/', 'cwd after chdir', + ) + + # cwd must be restored + self.assertEqual(self.get()['body'], script_cwd, 'cwd restored') + + def test_php_application_cwd_script(self): + self.load('cwd') + self.run_php_application_cwd_script_tests() + + def test_php_application_cwd_script_opcache_disabled(self): + self.load('cwd') + self.set_opcache('cwd', '0') + self.run_php_application_cwd_script_tests() + + def test_php_application_cwd_script_opcache_enabled(self): + self.load('cwd') + self.set_opcache('cwd', '1') + self.run_php_application_cwd_script_tests() + + def test_php_application_path_relative(self): + self.load('open') + + self.assertEqual(self.get()['body'], 'test', 'relative path') + + self.assertNotEqual( + self.get(url='/?chdir=/')['body'], 'test', 'relative path w/ chdir' + ) + + self.assertEqual(self.get()['body'], 'test', 'relative path 2') + if __name__ == '__main__': TestPHPApplication.main() diff --git a/test/unit/applications/lang/php.py b/test/unit/applications/lang/php.py index 6b1677e6..e8c70c62 100644 --- a/test/unit/applications/lang/php.py +++ b/test/unit/applications/lang/php.py @@ -4,7 +4,7 @@ from unit.applications.proto import TestApplicationProto class TestApplicationPHP(TestApplicationProto): application_type = "php" - def load(self, script, name='index.php', **kwargs): + def load(self, script, index='index.php', **kwargs): script_path = self.current_dir + '/php/' + script self._load_conf( @@ -16,7 +16,7 @@ class TestApplicationPHP(TestApplicationProto): "processes": {"spare": 0}, "root": script_path, "working_directory": script_path, - "index": name, + "index": index, } }, }, |