summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_access_log.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/test_access_log.py b/test/test_access_log.py
index 873c941a..1b0ec8ad 100644
--- a/test/test_access_log.py
+++ b/test/test_access_log.py
@@ -28,6 +28,10 @@ def set_format(log_format):
), 'access_log format'
+def set_if(condition):
+ assert 'success' in client.conf(f'"{condition}"', 'access_log/if')
+
+
def test_access_log_keepalive(wait_for_record):
load('mirror')
@@ -308,6 +312,62 @@ def test_access_log_variables(wait_for_record):
), '$body_bytes_sent'
+def test_access_log_if(search_in_file, wait_for_record):
+ load('empty')
+ set_format('$uri')
+
+ def try_if(condition):
+ set_if(condition)
+ assert client.get(url=f'/{condition}')['status'] == 200
+
+ # const
+
+ try_if('')
+ try_if('0')
+ try_if('false')
+ try_if('undefined')
+ try_if('!')
+ try_if('!null')
+ try_if('1')
+
+ # variable
+
+ set_if('$arg_foo')
+ assert client.get(url='/bar?bar')['status'] == 200
+ assert client.get(url='/foo_empty?foo')['status'] == 200
+ assert client.get(url='/foo?foo=1')['status'] == 200
+
+ # check results
+
+ assert wait_for_record(r'^/foo$', 'access.log') is not None
+
+ assert search_in_file(r'^/$', 'access.log') is None
+ assert search_in_file(r'^/0$', 'access.log') is None
+ assert search_in_file(r'^/false$', 'access.log') is None
+ assert search_in_file(r'^/undefined$', 'access.log') is None
+ assert search_in_file(r'^/!$', 'access.log') is not None
+ assert search_in_file(r'^/!null$', 'access.log') is not None
+ assert search_in_file(r'^/1$', 'access.log') is not None
+
+ assert search_in_file(r'^/bar$', 'access.log') is None
+ assert search_in_file(r'^/foo_empty$', 'access.log') is None
+
+
+def test_access_log_if_njs(require, search_in_file, wait_for_record):
+ require({'modules': {'njs': 'any'}})
+
+ load('empty')
+ set_format('$uri')
+
+ set_if('`${args.foo == \'1\'}`')
+
+ assert client.get(url='/foo_2?foo=2')['status'] == 200
+ assert client.get(url='/foo_1?foo=1')['status'] == 200
+
+ assert wait_for_record(r'^/foo_1$', 'access.log') is not None
+ assert search_in_file(r'^/foo_2$', 'access.log') is None
+
+
def test_access_log_incorrect(temp_dir, skip_alert):
skip_alert(r'failed to apply new conf')
@@ -323,3 +383,5 @@ def test_access_log_incorrect(temp_dir, skip_alert):
},
'access_log',
), 'access_log format incorrect'
+
+ assert 'error' in client.conf('$arg_', 'access_log/if')