Skip to content

Commit

Permalink
Tests: Add some PHP tests for 403 and 404 error handling.
Browse files Browse the repository at this point in the history
Since the previous commit, we now properly handle 403 Forbidden & 404
Not Found errors in the PHP language module.

This adds a test for 403 Forbidden to test/test_php_application.py, but
also fixes a test in test/test_php_targets.py where we were checking for
503 but should have been a 404, which we now do.

Acked-by: Alejandro Colomar <alx@nginx.com>
Cc: Andrei Zeliankou <zelenkov@nginx.com>
[ Incorporates a couple of small test cleanups from Andrei ]
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
  • Loading branch information
ac000 committed Jan 31, 2023
1 parent 5f186d5 commit 8cb7e0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/test_php_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,26 @@ def test_php_application_trailing_slash(self, temp_dir):
resp['headers']['Location'] == 'http://foo/path/'
), 'Location with custom Host over UDS'

def test_php_application_forbidden(self, temp_dir):
new_root = temp_dir + "/php-root"
os.makedirs(new_root + '/path')
os.chmod(new_root + '/path', 0o000)

assert 'success' in self.conf(
{
"listeners": {"*:7080": {"pass": "applications/php-path"}},
"applications": {
"php-path": {
"type": self.get_application_type(),
"processes": {"spare": 0},
"root": new_root,
}
},
}
), 'forbidden directory'

assert self.get(url='/path/')['status'] == 403, 'access forbidden'

def test_php_application_extension_check(self, temp_dir):
self.load('phpinfo')

Expand Down
2 changes: 1 addition & 1 deletion test/test_php_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_php_application_targets(self):

assert self.get(url='/1')['body'] == '1'
assert self.get(url='/2')['body'] == '2'
assert self.get(url='/blah')['status'] == 503 # TODO 404
assert self.get(url='/blah')['status'] == 404
assert self.get(url='/')['body'] == 'index'
assert self.get(url='/1.php?test=test.php/')['body'] == '1'

Expand Down

0 comments on commit 8cb7e0b

Please sign in to comment.