Tests: "if" option in access logging.
Conditional access logging was introduced here:
4c91bebb50
This commit is contained in:
committed by
andrey-zelenkov
parent
dcbff27d9b
commit
ad3645074e
@@ -28,6 +28,10 @@ def set_format(log_format):
|
|||||||
), 'access_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):
|
def test_access_log_keepalive(wait_for_record):
|
||||||
load('mirror')
|
load('mirror')
|
||||||
|
|
||||||
@@ -308,6 +312,62 @@ def test_access_log_variables(wait_for_record):
|
|||||||
), '$body_bytes_sent'
|
), '$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):
|
def test_access_log_incorrect(temp_dir, skip_alert):
|
||||||
skip_alert(r'failed to apply new conf')
|
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',
|
||||||
), 'access_log format incorrect'
|
), 'access_log format incorrect'
|
||||||
|
|
||||||
|
assert 'error' in client.conf('$arg_', 'access_log/if')
|
||||||
|
|||||||
Reference in New Issue
Block a user