Commit Graph

49 Commits

Author SHA1 Message Date
Andrei Zeliankou
7934dcabbc Tests: switched to using f-strings.
Previously, it was necessary to support older versions of Python for
compatibility.  F-strings were released in Python 3.6.  Python 3.5 was
marked as unsupported by the end of 2020, so now it's possible to start
using f-strings safely for better readability and performance.
2023-02-21 17:21:29 +00:00
Andrew Clayton
0be289b7fc Tests: Add some PHP tests for 403 and 404 error handling.
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>
2023-01-30 17:00:13 +00:00
Andrew Clayton
a03274456b PHP: allowed to specify URLs without a trailing '/'.
Both @lucatacconi & @mwoodpatrick reported what appears to be the same
issue on GitHub. Namely that when using the PHP language module and
trying to access a URL that is a directory but without specifying the
trailing '/', they were getting a '503 Service Unavailable' error.

Note: This is when _not_ using the 'script' option.

E.g with the following config

  {
      "listeners": {
          "[::1]:8080": {
              "pass": "applications/php"
          }
      },

      "applications": {
          "php": {
              "type": "php",
              "root": "/var/tmp/unit-php"
          }
      }
  }

and with a directory path of /var/tmp/unit-php/foo containing an
index.php, you would see the following

  $ curl http://localhost/foo
  <title>Error 503</title>
  Error 503

However

  $ curl http://localhost/foo/

would work and serve up the index.php

This commit fixes the above so you get the desired behaviour without
specifying the trailing '/' by doing the following

  1] If the URL doesn't end in .php and doesn't have a trailing '/'
     then check if the requested path is a directory.

  2) If it is a directory then create a 301 re-direct pointing to it.
     This matches the behaviour of the likes of nginx, Apache and
     lighttpd.

     This also matches the behaviour of the "share" action in Unit.

This doesn't effect the behaviour of the 'script' option which bypasses
the nxt_php_dynamic_request() function.

This also adds a couple of tests to test/test_php_application.py to
ensure this continues to work.

Closes: <https://github.com/nginx/unit/issues/717>
Closes: <https://github.com/nginx/unit/issues/753>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
2022-11-02 14:22:39 +00:00
Andrei Zeliankou
c65e04682e Tests: minor fixes. 2022-09-07 01:11:04 +01:00
Andrei Zeliankou
0f72534660 Tests: style. 2022-04-11 21:05:14 +01:00
Andrei Zeliankou
9bea8c452f Tests: fixed type of applications. 2021-12-12 21:36:44 +00:00
Andrei Zeliankou
4b3efcea0d Tests: added more OPcache tests. 2021-12-11 00:16:59 +00:00
Andrei Zeliankou
ad843df965 Tests: fixed path to the "php.ini" file. 2021-12-10 15:34:52 +00:00
Max Romanov
b424a00ec5 Tests: PHP shared opcache test added. 2021-11-09 15:48:44 +03:00
Andrei Zeliankou
39adb292d5 Tests: style. 2021-10-18 01:10:11 +01:00
Andrei Zeliankou
b9e8d8073c Tests: PHP test with getting variable before the script is loaded. 2021-05-07 16:55:42 +01:00
Max Romanov
74b1b1fc17 Tests: preserving unit.log when run without restart.
Introducing "unit.log.Log" class for "unit.log" file management.
Moving "findall()" function into TestApplicationProto.
Using "os.kill()" to send signals.
2021-04-08 19:11:11 +03:00
Andrei Zeliankou
6c97a1a069 Tests: style. 2021-04-05 14:03:05 +01:00
Andrei Zeliankou
d43a84139d Tests: added missing checks for configuration results. 2021-01-14 03:04:20 +00:00
Andrei Zeliankou
6dc9c47ccd Tests: style. 2021-01-13 06:22:43 +00:00
Andrei Zeliankou
f5ac143246 Tests: unit_stop() removed where possible.
Since wait_for_record() was introduced there is no need
to stop Unit before parsing unit.log.
2021-01-12 06:20:23 +00:00
Andrei Zeliankou
16ac829c8f Tests: added tests for PHP_AUTH_* variables. 2020-12-10 19:28:41 +00:00
Andrei Zeliankou
07789a23e9 Tests: options moved to the separate class.
This change is necessary to separate the logic
and prevent possible circular dependency.
2020-12-06 16:01:59 +00:00
Andrei Zeliankou
a0ee50826a Tests: added a test for fastcgi_finish_request() function. 2020-11-11 14:24:40 +00:00
Andrei Zeliankou
54837759f3 Tests: fixed unit.log print. 2020-10-19 22:25:29 +01:00
Valentin Bartenev
2821b3347c PHP: compatibility with 8.0.0 RC1.
This closes #474 PR on GitHub.
2020-10-06 18:12:05 +03:00
Andrei Zeliankou
6ec0ff3596 Tests: minor fixes. 2020-10-07 23:18:43 +01:00
Andrei Zeliankou
d5e9159340 Tests: migrated to the pytest. 2020-09-16 21:31:15 +01:00
Andrei Zeliankou
f1e445bdef Tests: added PHP test with time check in error log messages. 2020-07-28 04:53:40 +01:00
Andrei Zeliankou
ce4a2bbd05 Tests: style. 2020-05-15 04:20:56 +01:00
Andrei Zeliankou
6a9a4fe0d4 Tests: introduced module version specification in prerequisites. 2020-04-24 05:08:56 +01:00
Andrei Zeliankou
0bfa09dfa0 Tests: minor fixes and style. 2020-04-14 02:35:04 +01:00
Tiago Natel de Moura
80763b3e64 Tests: chdir() and open() for PHP module.
These tests ensure optimizations in the chdir calls don't break
SAPI semantics.
2020-03-03 18:53:26 +00:00
Andrei Zeliankou
5406d1e320 Tests: added PHP test with invalid index extension only. 2020-02-20 21:06:56 +00:00
Tiago Natel de Moura
117a4f11b9 Tests: check for php extension. 2020-01-23 11:57:15 +00:00
Andrey Zelenkov
65ca2d7b19 Tests: refactored prerequisites model. 2019-09-14 14:44:35 +03:00
Andrey Zelenkov
4153fad89d Tests: added PHP tests with "script" and "index" options. 2019-07-17 16:50:24 +03:00
Andrey Zelenkov
4ea7d71405 Tests: added PATH_INFO variable test. 2019-07-08 19:23:33 +03:00
Valentin Bartenev
924165c90b PHP: improved response status code handling.
There's no reason to parse "http_status_line"; the PHP interpreter already
does this.  If the line contains a valid status code, it's assigned to
"http_response_code".

This also fixes invalid status line handling, where the nxt_int_parse()
function returned -1; it was cast to unsigned, yielding response code 65535.
2019-07-05 18:42:30 +03:00
Andrey Zelenkov
90c5d3f5c0 Tests: adjusted skipping tests. 2019-05-30 16:46:04 +03:00
Andrey Zelenkov
29b4e4431f Tests: speed up tests. 2019-04-09 20:59:35 +03:00
Andrey Zelenkov
af24e4dec4 Tests: simplified module checking. 2019-04-09 16:14:42 +03:00
Andrey Zelenkov
19eba1730a Tests: unit module refactoring. 2019-03-28 18:43:13 +03:00
Andrey Zelenkov
281899fcef Tests: style. 2019-03-26 23:38:30 +03:00
Andrey Zelenkov
ae36276cfc Tests: made tests compatible with PHP 5.3. 2019-03-01 18:58:16 +03:00
Andrey Zelenkov
38ea191fbb Tests: fixed PHP "disable_functions" and "disable_classes" tests. 2019-02-28 21:18:33 +03:00
Andrey Zelenkov
4de2c8b567 Tests: added "Host" and "Connetion" headers where necessary.
Also minor header organizing.
2019-02-27 19:15:02 +03:00
Andrey Zelenkov
f9a3328a25 Tests: more QUERY_STRING tests. 2018-12-24 20:35:18 +03:00
Andrey Zelenkov
37cd6d23b6 Tests: PHP directives "disable_classes" and "disable_functions". 2018-11-28 03:14:38 +03:00
Andrey Zelenkov
eff760bd2b Tests: added command line arguments parsing in tests.
Added the following command line arguments:

  -d, --detailed: Show detailed output for tests

    Usage examples:

    ./test/run.py --detailed
    python3 test/test_access_log.py --detailed
    python3 test/test_access_log.py -d TestUnitAccessLog.test_access_log_ipv6


  -l, --log: Save unit.log after the test execution

    Usage examples:

    ./test/run.py -l
    python3 test/test_access_log.py -l
    python3 test/test_access_log.py --log TestUnitAccessLog.test_access_log_ipv6
2018-11-15 21:26:15 +03:00
Andrey Zelenkov
511a0fa760 Tests: used relative path for configuration. 2018-09-06 20:18:33 +03:00
Andrey Zelenkov
96a4f9f032 Tests: more php.ini options tests. 2018-07-11 19:35:46 +03:00
Andrey Zelenkov
2b39ed5dfb Tests: added tests for "precision" option in php.ini. 2018-06-07 21:13:55 +03:00
Andrey Zelenkov
3b7238996a Tests: initial PHP application tests. 2018-05-22 20:20:14 +03:00