test_php_application.py (2190:fbfec2aaf4c3) test_php_application.py (2230:83b2d20d8f5c)
1import getpass
2import os
3import re
4import shutil
5import signal
6import time
1import getpass
2import os
3import re
4import shutil
5import signal
6import time
7from pathlib import Path
7
8import pytest
9from unit.applications.lang.php import TestApplicationPHP
10from unit.option import option
11
12
13class TestPHPApplication(TestApplicationPHP):
14 prerequisites = {'modules': {'php': 'all'}}

--- 600 unchanged lines hidden (view full) ---

615 }
616 ), 'configure index default'
617
618 resp = self.get()
619
620 assert resp['status'] == 200, 'status'
621 assert resp['body'] != '', 'body not empty'
622
8
9import pytest
10from unit.applications.lang.php import TestApplicationPHP
11from unit.option import option
12
13
14class TestPHPApplication(TestApplicationPHP):
15 prerequisites = {'modules': {'php': 'all'}}

--- 600 unchanged lines hidden (view full) ---

616 }
617 ), 'configure index default'
618
619 resp = self.get()
620
621 assert resp['status'] == 200, 'status'
622 assert resp['body'] != '', 'body not empty'
623
624 def test_php_application_trailing_slash(self, temp_dir):
625 new_root = temp_dir + "/php-root"
626 os.makedirs(new_root + '/path')
627
628 Path(new_root + '/path/index.php').write_text('<?php echo "OK\n"; ?>')
629
630 addr = temp_dir + '/sock'
631
632 assert 'success' in self.conf(
633 {
634 "listeners": {
635 "*:7080": {"pass": "applications/php-path"},
636 "unix:" + addr: {"pass": "applications/php-path"},
637 },
638 "applications": {
639 "php-path": {
640 "type": self.get_application_type(),
641 "processes": {"spare": 0},
642 "root": new_root,
643 }
644 },
645 }
646 ), 'configure trailing slash'
647
648 assert self.get(url='/path/')['status'] == 200, 'uri with trailing /'
649
650 resp = self.get(url='/path?q=a')
651 assert resp['status'] == 301, 'uri without trailing /'
652 assert (
653 resp['headers']['Location'] == 'http://localhost:7080/path/?q=a'
654 ), 'Location with query string'
655
656 resp = self.get(
657 sock_type='unix',
658 addr=addr,
659 url='/path',
660 headers={'Host': 'foo', 'Connection': 'close'},
661 )
662 assert resp['status'] == 301, 'uri without trailing /'
663 assert (
664 resp['headers']['Location'] == 'http://foo/path/'
665 ), 'Location with custom Host over UDS'
666
623 def test_php_application_extension_check(self, temp_dir):
624 self.load('phpinfo')
625
626 assert self.get(url='/index.wrong')['status'] != 200, 'status'
627
628 new_root = temp_dir + "/php"
629 os.mkdir(new_root)
630 shutil.copy(option.test_dir + '/php/phpinfo/index.wrong', new_root)

--- 139 unchanged lines hidden ---
667 def test_php_application_extension_check(self, temp_dir):
668 self.load('phpinfo')
669
670 assert self.get(url='/index.wrong')['status'] != 200, 'status'
671
672 new_root = temp_dir + "/php"
673 os.mkdir(new_root)
674 shutil.copy(option.test_dir + '/php/phpinfo/index.wrong', new_root)

--- 139 unchanged lines hidden ---