diff options
| author | Dan Callahan <d.callahan@f5.com> | 2024-02-27 15:15:42 +0000 |
|---|---|---|
| committer | Dan Callahan <d.callahan@f5.com> | 2024-02-27 15:15:42 +0000 |
| commit | d76761901c4084bcdbc5a449e9bbb47d56b7093c (patch) | |
| tree | b4b7b4e3d588b73a2adcc0094cab466d9194c679 /test/test_njs.py | |
| parent | c43629880472bba8d389dfb0b7ae6d883b0ba499 (diff) | |
| parent | 088117008c9e8f397a58cc8d8070ce047beff12f (diff) | |
| download | unit-1.32.0-1.tar.gz unit-1.32.0-1.tar.bz2 | |
Merge tag '1.32.0' into branches/packaging1.32.0-1
Unit 1.32.0 release.
Diffstat (limited to 'test/test_njs.py')
| -rw-r--r-- | test/test_njs.py | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/test/test_njs.py b/test/test_njs.py index 162cc0bd..8ef815fd 100644 --- a/test/test_njs.py +++ b/test/test_njs.py @@ -1,6 +1,7 @@ -import os +from pathlib import Path import pytest + from unit.applications.proto import ApplicationProto from unit.option import option from unit.utils import waitforfiles @@ -14,7 +15,7 @@ client = ApplicationProto() def setup_method_fixture(temp_dir): assert 'success' in client.conf( { - "listeners": {"*:7080": {"pass": "routes"}}, + "listeners": {"*:8080": {"pass": "routes"}}, "routes": [{"action": {"share": f"{temp_dir}/assets$uri"}}], } ) @@ -22,9 +23,9 @@ def setup_method_fixture(temp_dir): def create_files(*files): assets_dir = f'{option.temp_dir}/assets/' - os.makedirs(assets_dir) + Path(assets_dir).mkdir(exist_ok=True) - [open(assets_dir + f, 'a') for f in files] + _ = [Path(assets_dir + f).touch() for f in files] waitforfiles(*[assets_dir + f for f in files]) @@ -82,6 +83,38 @@ def test_njs_variables(temp_dir): set_share(f'"`{temp_dir}/assets/${{args.foo}}`"') assert client.get(url='/?foo=str')['status'] == 200, 'args' + check_expression('/${vars.header_host}') + + set_share(f'"`{temp_dir}/assets/${{vars[\\"arg_foo\\"]}}`"') + assert client.get(url='/?foo=str')['status'] == 200, 'vars' + + set_share(f'"`{temp_dir}/assets/${{vars.non_exist}}`"') + assert client.get()['status'] == 404, 'undefined' + + create_files('undefined') + assert client.get()['status'] == 200, 'undefined 2' + + +def test_njs_variables_cacheable(temp_dir): + create_files('str') + + def check_rewrite(rewrite, uri): + assert 'success' in client.conf( + [ + { + "action": { + "rewrite": rewrite, + "share": f"`{temp_dir}/assets{uri}`", + }, + }, + ], + 'routes', + ) + assert client.get()['status'] == 200 + + check_rewrite('/str', '${uri}') + check_rewrite('/str', '${vars.uri}') + def test_njs_invalid(skip_alert): skip_alert(r'js exception:') @@ -92,6 +125,7 @@ def test_njs_invalid(skip_alert): check_invalid('"`a"') check_invalid('"`a``"') check_invalid('"`a`/"') + check_invalid('"`${vars.}`"') def check_invalid_resolve(template): assert 'success' in client.conf(template, 'routes/0/action/share') @@ -99,3 +133,4 @@ def test_njs_invalid(skip_alert): check_invalid_resolve('"`${a}`"') check_invalid_resolve('"`${uri.a.a}`"') + check_invalid_resolve('"`${vars.a.a}`"') |
