testbench: test for leading space issue in RFC 5424 parser

see also https://github.com/rsyslog/rsyslog/pull/3671
see also https://github.com/rsyslog/rsyslog/pull/3667
This commit is contained in:
Rainer Gerhards 2019-05-17 16:46:09 +02:00
parent 85cb8a11e9
commit 12a7a4809e
No known key found for this signature in database
GPG Key ID: 0CB6B2A8BE80B499
8 changed files with 42 additions and 57 deletions

View File

@ -201,6 +201,7 @@ TESTS += \
fac_invld2.sh \
fac_invld3.sh \
fac_invld4_rfc5424.sh \
rfc5424parser-sp_at_msg_start.sh \
compresssp.sh \
compresssp-stringtpl.sh \
rawmsg-after-pri.sh \
@ -1537,6 +1538,7 @@ EXTRA_DIST= \
timestamp-subseconds.sh \
rsf_getenv.sh \
diskq-rfc5424.sh \
rfc5424parser-sp_at_msg_start.sh \
diskqueue-full.sh \
diskqueue.sh \
diskqueue-non-unique-prefix.sh \

View File

@ -539,15 +539,18 @@ startup_vgthread() {
# inject messages via our inject interface (imdiag)
# $1 is start message number, env var NUMMESSAGES is number of messages to inject
injectmsg() {
if [ "$3" != "" ] ; then
printf 'error: injectmsg only has two arguments, extra arg is %s\n' "$3"
fi
msgs=${2:-$NUMMESSAGES}
echo injecting $msgs messages
echo injectmsg ${1:-0} $msgs $3 $4 | $TESTTOOL_DIR/diagtalker -p$IMDIAG_PORT || error_exit $?
echo injectmsg "${1:-0}" "$msgs" | $TESTTOOL_DIR/diagtalker -p$IMDIAG_PORT || error_exit $?
}
# inject messages in INSTANCE 2 via our inject interface (imdiag)
injectmsg2() {
echo injecting $2 messages
echo injectmsg $1 $2 $3 $4 | $TESTTOOL_DIR/diagtalker -p$IMDIAG_PORT2 || error_exit $?
echo injectmsg "$1" "$2" $3 $4 | $TESTTOOL_DIR/diagtalker -p$IMDIAG_PORT2 || error_exit $?
# TODO: some return state checking? (does it really make sense here?)
}

View File

@ -36,16 +36,7 @@ startup
injectmsg litteral "<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq"
shutdown_when_empty
wait_shutdown
export EXPECTED=$(printf 'Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq')
echo $EXPECTED | cmp - $RSYSLOG_DYNNAME.amqp.log
if [ ! $? -eq 0 ]; then
echo "Expected:"
echo $EXPECTED
echo "invalid response generated, $RSYSLOG_DYNNAME.amqp.log is:"
cat $RSYSLOG_DYNNAME.amqp.log
echo "Rsyslog internal output log:"
cat $RSYSLOG_OUT_LOG
error_exit 1
fi;
export EXPECTED='Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq'
cmp_exact $RSYSLOG_DYNNAME.amqp.log
content_check "exchange declare failed PRECONDITION_FAILED"
exit_test

View File

@ -36,16 +36,7 @@ startup
injectmsg litteral "<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq"
shutdown_when_empty
wait_shutdown
expected=$(printf 'Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq')
echo ${expected} | cmp - $RSYSLOG_DYNNAME.amqp.log
if [ ! $? -eq 0 ]; then
echo "Expected:"
echo ${expected}
echo "invalid response generated, $RSYSLOG_DYNNAME.amqp.log is:"
cat $RSYSLOG_DYNNAME.amqp.log
echo "Rsyslog internal output log:"
cat $RSYSLOG_OUT_LOG
error_exit 1
fi;
export EXPECTED='Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq'
cmp_exact $RSYSLOG_DYNNAME.amqp.log
content_check "disconnected while exchange declare"
exit_test

View File

@ -36,16 +36,7 @@ startup
injectmsg litteral "<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq"
shutdown_when_empty
wait_shutdown
expected=$(printf 'Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq')
echo ${expected} | cmp - $RSYSLOG_DYNNAME.amqp.log
if [ ! $? -eq 0 ]; then
echo "Expected:"
echo ${expected}
echo "invalid response generated, $RSYSLOG_DYNNAME.amqp.log is:"
cat $RSYSLOG_DYNNAME.amqp.log
echo "Rsyslog internal output log:"
cat $RSYSLOG_OUT_LOG
error_exit 1
fi;
export EXPECTED='Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq'
cmp_exact $RSYSLOG_DYNNAME.amqp.log
content_check "Connection closed : reconnect"
exit_test

View File

@ -35,16 +35,7 @@ startup
injectmsg litteral "<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq"
shutdown_when_empty
wait_shutdown
expected=$(printf 'Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq')
echo ${expected} | cmp - $RSYSLOG_DYNNAME.amqp.log
if [ ! $? -eq 0 ]; then
echo "Expected:"
echo ${expected}
echo "invalid response generated, $RSYSLOG_DYNNAME.amqp.log is:"
cat $RSYSLOG_DYNNAME.amqp.log
echo "Rsyslog internal output log:"
cat $RSYSLOG_OUT_LOG
error_exit 1
fi;
export EXPECTED='Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq'
cmp_exact $RSYSLOG_DYNNAME.amqp.log
content_check "Connection closed : reconnect"
exit_test

View File

@ -34,16 +34,7 @@ startup
injectmsg litteral "<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq"
shutdown_when_empty
wait_shutdown
expected=$(printf 'Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq')
echo ${expected} | cmp - $RSYSLOG_DYNNAME.amqp.log
if [ ! $? -eq 0 ]; then
echo "Expected:"
echo ${expected}
echo "invalid response generated, $RSYSLOG_DYNNAME.amqp.log is:"
cat $RSYSLOG_DYNNAME.amqp.log
echo "Rsyslog internal output log:"
cat $RSYSLOG_OUT_LOG
error_exit 1
fi;
export EXPECTED='Exchange:in, routing-key:tag.local4.debug, content-type:plain/text, facility:local4, severity:debug, hostname:172.20.245.8, fromhost:127.0.0.1, delivery-mode:transient, expiration:5000, timestamp:OK, app-id:tag, msg:<167>Mar 1 01:00:00 172.20.245.8 tag msgrmq'
cmp_exact $RSYSLOG_DYNNAME.amqp.log
content_check "server localhost port"
exit_test

View File

@ -0,0 +1,25 @@
#!/bin/bash
# checks that in RFC5424 mode SP at beginning of MSG part is properly handled
# This file is part of the rsyslog project, released under ASL 2.0
# rgerhards, 2019-05-17
. ${srcdir:=.}/diag.sh init
generate_conf
add_conf '
template(name="outfmt" type="string" string="%msg%--END\n")
if $syslogtag == "tag" then
action(type="omfile" template="outfmt" file="'$RSYSLOG_OUT_LOG'")
'
startup
injectmsg litteral '<13>1 2019-05-15T11:21:57+03:00 domain.tld tag - - - nosd-nosp'
injectmsg litteral '<13>1 2019-05-15T11:21:57+03:00 domain.tld tag - - [abc@123 a="b"] sd-nosp'
injectmsg litteral '<13>1 2019-05-15T11:21:57+03:00 domain.tld tag - - - nosd-sp'
injectmsg litteral '<13>1 2019-05-15T11:21:57+03:00 domain.tld tag - - [abc@123 a="b"] sd-sp'
shutdown_when_empty
wait_shutdown
export EXPECTED='nosd-nosp--END
sd-nosp--END
nosd-sp--END
sd-sp--END'
cmp_exact
exit_test