diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2024-01-17 14:36:36 +0000 |
---|---|---|
committer | andrey-zelenkov <xim.andrew@gmail.com> | 2024-02-20 14:55:00 +0000 |
commit | 2765522b94e748d01e449d5508f83ea4a5b46ea5 (patch) | |
tree | 525b36155cabf70c82349541c028c5ab696e8258 | |
parent | d52a9361a85ed7694815df5b707649dd6b31ead1 (diff) | |
download | unit-2765522b94e748d01e449d5508f83ea4a5b46ea5.tar.gz unit-2765522b94e748d01e449d5508f83ea4a5b46ea5.tar.bz2 |
Tests: NJS request variables
-rw-r--r-- | test/test_njs.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/test_njs.py b/test/test_njs.py index aaaa23aa..8ef815fd 100644 --- a/test/test_njs.py +++ b/test/test_njs.py @@ -23,7 +23,7 @@ def setup_method_fixture(temp_dir): def create_files(*files): assets_dir = f'{option.temp_dir}/assets/' - Path(assets_dir).mkdir() + Path(assets_dir).mkdir(exist_ok=True) _ = [Path(assets_dir + f).touch() for f in files] waitforfiles(*[assets_dir + f for f in files]) @@ -83,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:') @@ -93,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') @@ -100,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}`"') |