diff options
| author | Ippolitov Igor <iippolitov@nginx.com> | 2023-10-19 12:50:39 +0100 |
|---|---|---|
| committer | Ippolitov Igor <iippolitov@nginx.com> | 2023-10-19 12:50:39 +0100 |
| commit | c43629880472bba8d389dfb0b7ae6d883b0ba499 (patch) | |
| tree | acecdcb36cfb85fac3d8cdbfbe473c26ac2e2686 /test | |
| parent | 8c4425ccb9a413e8d0506e0254f0e84bd89a32a6 (diff) | |
| parent | fb33ec86a3b6ca6a844dfa6980bb9e083094abec (diff) | |
| download | unit-1.31.1-1.tar.gz unit-1.31.1-1.tar.bz2 | |
Merged with the default branch.1.31.1-1
Diffstat (limited to '')
| -rw-r--r-- | test/node/write_array/app.js | 4 | ||||
| -rw-r--r-- | test/node/write_buffer/app.js | 2 | ||||
| -rw-r--r-- | test/test_java_application.py | 17 | ||||
| -rw-r--r-- | test/test_node_application.py | 4 | ||||
| -rw-r--r-- | test/test_php_application.py | 30 | ||||
| -rw-r--r-- | test/test_response_headers.py | 173 | ||||
| -rw-r--r-- | test/unit/applications/lang/java.py | 2 |
7 files changed, 230 insertions, 2 deletions
diff --git a/test/node/write_array/app.js b/test/node/write_array/app.js new file mode 100644 index 00000000..b7abb3fc --- /dev/null +++ b/test/node/write_array/app.js @@ -0,0 +1,4 @@ +require('http').createServer(function (req, res) { + res.writeHead(200, {'Content-Length': 5, 'Content-Type': 'text/plain'}) + .end(new Uint8Array(Buffer.from('array', 'utf8'))); +}).listen(7080); diff --git a/test/node/write_buffer/app.js b/test/node/write_buffer/app.js index 506e8613..72e9c600 100644 --- a/test/node/write_buffer/app.js +++ b/test/node/write_buffer/app.js @@ -1,5 +1,5 @@ require('http').createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}) - .end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])); + .end(Buffer.from('buffer', 'utf8')); }).listen(7080); diff --git a/test/test_java_application.py b/test/test_java_application.py index a8814583..eefc5c79 100644 --- a/test/test_java_application.py +++ b/test/test_java_application.py @@ -875,6 +875,23 @@ def test_java_application_get_headers(): assert headers['X-Reply-0'] == 'blah', 'get headers' assert headers['X-Reply-1'] == 'blah', 'get headers 2' +def test_java_application_many_headers(): + client.load('get_headers') + + value = '0123456789' * 10 + + headers = client.get( + headers={ + 'X-Header': [value] * 100, + 'Content-Type': 'text/html', + 'Host': 'localhost', + 'Connection': 'close', + } + )['headers'] + + for i in range(0, 99): + assert headers[f'X-Reply-{i}'] == value, 'many headers' + def test_java_application_get_headers_empty(): client.load('get_headers') diff --git a/test/test_node_application.py b/test/test_node_application.py index e4226535..ab8aa8f8 100644 --- a/test/test_node_application.py +++ b/test/test_node_application.py @@ -149,6 +149,10 @@ def test_node_application_write_buffer(): assert client.get()['body'] == 'buffer', 'write buffer' +def test_node_application_write_array(): + client.load('write_array') + + assert client.get()['body'] == 'array', 'write array' def test_node_application_write_callback(temp_dir): client.load('write_callback') diff --git a/test/test_php_application.py b/test/test_php_application.py index 6c1f227b..17440909 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -171,6 +171,36 @@ def test_php_application_query_string_empty(): assert resp['headers']['Query-String'] == '', 'query string empty' +def test_php_application_query_string_rewrite(): + assert 'success' in client.conf( + { + "listeners": {"*:7080": {"pass": "routes"}}, + "routes": [ + { + "action": { + "rewrite": "/new", + "pass": "applications/query_string", + }, + }, + ], + "applications": { + "query_string": { + "type": client.get_application_type(), + "processes": {"spare": 0}, + "root": f"{option.test_dir}/php/query_string", + "script": "index.php", + } + }, + }, + ) + + assert client.get(url='/old')['status'] == 200 + + resp = client.get(url='/old?arg=val') + assert resp['status'] == 200 + assert resp['headers']['Query-String'] == 'arg=val' + + def test_php_application_fastcgi_finish_request(findall, unit_pid): client.load('fastcgi_finish_request') diff --git a/test/test_response_headers.py b/test/test_response_headers.py new file mode 100644 index 00000000..50f47d9a --- /dev/null +++ b/test/test_response_headers.py @@ -0,0 +1,173 @@ +from pathlib import Path + +import pytest +from unit.applications.proto import ApplicationProto +from unit.applications.lang.python import ApplicationPython +from unit.option import option + +client = ApplicationProto() +client_python = ApplicationPython() + + +@pytest.fixture(autouse=True) +def setup_method_fixture(temp_dir): + path = Path(f'{temp_dir}/index.html') + path.write_text('0123456789') + + assert 'success' in client.conf( + { + "listeners": { + "*:7080": {"pass": "routes"}, + }, + "routes": [ + { + "action": { + "share": str(path), + "response_headers": { + "X-Foo": "foo", + }, + } + } + ], + } + ) + + +def action_update(conf): + assert 'success' in client.conf(conf, 'routes/0/action') + + +def test_response_headers(temp_dir): + resp = client.get() + assert resp['status'] == 200, 'status 200' + assert resp['headers']['X-Foo'] == 'foo', 'header 200' + + assert 'success' in client.conf(f'"{temp_dir}"', 'routes/0/action/share') + + resp = client.get() + assert resp['status'] == 301, 'status 301' + assert resp['headers']['X-Foo'] == 'foo', 'header 301' + + assert 'success' in client.conf('"/blah"', 'routes/0/action/share') + + resp = client.get() + assert resp['status'] == 404, 'status 404' + assert 'X-Foo' not in client.get()['headers'], 'header 404' + + +def test_response_last_action(): + assert 'success' in client.conf( + { + "listeners": { + "*:7080": {"pass": "routes/first"}, + }, + "routes": { + "first": [ + { + "action": { + "pass": "routes/second", + "response_headers": { + "X-Foo": "foo", + }, + } + } + ], + "second": [ + { + "action": {"return": 200}, + } + ], + }, + "applications": {}, + } + ) + + assert 'X-Foo' not in client.get()['headers'] + + +def test_response_pass(require): + require({'modules': {'python': 'any'}}) + + assert 'success' in client_python.conf( + { + "listeners": { + "*:7080": {"pass": "routes"}, + }, + "routes": [ + { + "action": { + "pass": "applications/empty", + "response_headers": { + "X-Foo": "foo", + }, + } + }, + ], + "applications": { + "empty": { + "type": client_python.get_application_type(), + "processes": {"spare": 0}, + "path": f'{option.test_dir}/python/empty', + "working_directory": f'{option.test_dir}/python/empty', + "module": "wsgi", + } + }, + } + ) + + assert client.get()['headers']['X-Foo'] == 'foo' + + +def test_response_fallback(): + assert 'success' in client.conf( + { + "listeners": {"*:7080": {"pass": "routes"}}, + "routes": [ + { + "action": { + "share": "/blah", + "fallback": { + "return": 200, + "response_headers": { + "X-Foo": "foo", + }, + }, + } + } + ], + } + ) + + assert client.get()['headers']['X-Foo'] == 'foo' + + +def test_response_headers_var(): + assert 'success' in client.conf( + { + "X-Foo": "$uri", + }, + 'routes/0/action/response_headers', + ) + + assert client.get()['headers']['X-Foo'] == '/' + + +def test_response_headers_remove(): + assert 'success' in client.conf( + {"etag": None}, + 'routes/0/action/response_headers', + ) + + assert 'ETag' not in client.get()['headers'] + + +def test_response_headers_invalid(skip_alert): + skip_alert(r'failed to apply new conf') + + def check_invalid(conf): + assert 'error' in client.conf( + conf, + 'routes/0/action/response_headers', + ) + + check_invalid({"X-Foo": "$u"}) diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py index a253aea5..dc6d2bfc 100644 --- a/test/unit/applications/lang/java.py +++ b/test/unit/applications/lang/java.py @@ -53,7 +53,7 @@ class ApplicationJava(ApplicationProto): os.makedirs(classes_path) classpath = ( - f'{option.current_dir}/build/tomcat-servlet-api-9.0.75.jar' + f'{option.current_dir}/build/tomcat-servlet-api-9.0.82.jar' ) ws_jars = glob.glob( |
