Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ noinst_PROGRAMS += \
examples/nmsg-packet2pcap \
examples/print_version


AM_TESTS_ENVIRONMENT = export USE_JSON="$(use_json_c)";

TESTS += tests/group-operator-source-tests/test.sh
TESTS += tests/json-utf8-tests/test.sh
TESTS += tests/nmsg-dns-tests/test.sh
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ AC_SUBST(NMSG_PATCHLEVEL_VERSION)
AC_SUBST(NMSG_VERSION)
AC_SUBST(NMSG_VERSION_NUMBER)

use_json_c=$(test "x$with_json_c" != "xno" && echo "true" || echo "false")
AC_SUBST(use_json_c)

AC_PROG_LN_S

AC_CONFIG_FILES([Makefile doc/doxygen/Doxyfile nmsg/libnmsg.pc nmsg/version.h])
Expand Down
12 changes: 0 additions & 12 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,19 +351,13 @@ add_kafka_input(nmsgtool_ctx *c, const char *str_address) {
_add_kafka_nmsg_input(c, addr);
return;
}
#ifdef HAVE_JSON_C
addr = _strip_prefix_if_exists(str_address, "json:");
if (addr != NULL) {
_add_kafka_json_input(c, addr);
return;
}
fprintf(stderr, "%s: Error: nmsg or json protocol must be set for Kafka topic\n",
argv_program);
#else /* HAVE_JSON_C */
fprintf(stderr, "%s: Error: nmsg protocol must be set for Kafka topic\n",
argv_program);
#endif /* HAVE_JSON_C */
exit(EXIT_FAILURE);
}

void
Expand All @@ -373,19 +367,13 @@ add_kafka_output(nmsgtool_ctx *c, const char *str_address) {
_add_kafka_nmsg_output(c, addr);
return;
}
#ifdef HAVE_JSON_C
addr = _strip_prefix_if_exists(str_address, "json:");
if (addr != NULL) {
_add_kafka_json_output(c, addr);
return;
}
fprintf(stderr, "%s: Error: nmsg or json protocol must be set for Kafka topic\n",
argv_program);
#else /* HAVE_JSON_C */
fprintf(stderr, "%s: Error: nmsg protocol must be set for Kafka topic\n",
argv_program);
#endif /* HAVE_JSON_C */
exit(EXIT_FAILURE);
}

#ifdef HAVE_LIBZMQ
Expand Down
93 changes: 92 additions & 1 deletion tests/group-operator-source-tests/test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ check() {
fi
}

USE_JSON="@use_json_c@"

NMSG_MSGMOD_DIR="@abs_top_builddir@/nmsg/base/.libs"
export NMSG_MSGMOD_DIR
NMSGTOOL="@abs_top_builddir@/src/nmsgtool"
Expand All @@ -26,6 +28,7 @@ rm -f ${OUTPUT}/test*out

echo Testing no source results in no source ...

if [ "$USE_JSON" = "true" ]; then
echo "$JSON_PAYLOAD" | $NMSGTOOL -j - > ${OUTPUT}/test-no-source.pres.out
check read json base:http and create base:http presentation output
head -1 ${OUTPUT}/test-no-source.pres.out | grep '\[1:4 base http\] \[00000000\] \[\] \[\] $' >/dev/null
Expand Down Expand Up @@ -321,7 +324,95 @@ echo "$JSON_PAYLOAD" | $NMSGTOOL -j - --setgroup 4321 -J ${OUTPUT}/test-setgroup
check read json base:http and create base:http json output
egrep ',"group":4321,' ${OUTPUT}/test-setgroup-not-aliases.json.out >/dev/null
check numeric group in json

else
: ; check read json base:http and create base:http presentation output
: ; check no source results in 00000000 in presentation
: ; check read json base:http and create base:http json output
: ; check no source in json
: ; check read json base:http and create base:http presentation output
: ; check empty source results in 00000000 in presentation
: ; check read json base:http and create base:http json output
: ; check no source in json
: ; check read json base:http and create base:http presentation output
: ; check source presentation
: ; check read json base:http and create base:http json output
: ; check source in json
: ; check read json base:http and create base:http presentation output
: ; check previous source not in presentation
: ; check new source in presentation
: ; check read json base:http and create base:http json output
: ; check previous source not in json
: ; check new source in json
: ; check read json base:http and create base:http presentation output
: ; check no numerical operator and group in presentation
: ; check read json base:http and create base:http json output
: ; check no operator field in json
: ; check no group field in json
: ; check read json base:http and create base:http presentation output
: ; check numerical operator in presentation
: ; check read json base:http and create base:http json output
: ; check numerical operator in json
: ; check read json base:http and create base:http presentation output
: ; check numerical group in presentation
: ; check read json base:http and create base:http json output
: ; check numerical group in json
: ; check read json base:http and create base:http presentation output
: ; check no operator in presentation
: ; check read json base:http and create base:http json output
: ; check no operator in json
: ; check read json base:http and create base:http presentation output
: ; check no group in presentation
: ; check read json base:http and create base:http json output
: ; check no group in json
: ; check read json base:http and create base:http presentation output
: ; check named operator in presentation
: ; check read json base:http and create base:http json output
: ; check named operator in json
: ; check read json base:http and create base:http presentation output
: ; check named group in presentation
: ; check read json base:http and create base:http json output
: ; check named group in json
: ; check read json base:http and create base:http presentation output
: ; check named operator in presentation
: ; check read json base:http and create base:http json output
: ; check named operator in json
: ; check read json base:http and create base:http presentation output
: ; check named group in presentation
: ; check read json base:http and create base:http json output
: ; check named group in json
: ; check read json base:http and create base:http presentation output
: ; check no operator in presentation
: ; check read json base:http and create base:http json output
: ; check no operator in json
: ; check read json base:http and create base:http presentation output
: ; check no group in presentation
: ; check read json base:http and create base:http json output
: ; check no group in json
: ; check read json base:http and create base:http presentation output
: ; check named operator in presentation
: ; check read json base:http and create base:http json output
: ; check named operator in json
: ; check read json base:http and create base:http presentation output
: ; check named group in presentation
: ; check read json base:http and create base:http json output
: ; check named group in json
: ; check read json base:http and create base:http presentation output
: ; check named operator in presentation
: ; check read json base:http and create base:http json output
: ; check named operator in json
: ; check read json base:http and create base:http presentation output
: ; check named group in presentation
: ; check read json base:http and create base:http json output
: ; check named group in json
: ; check read json base:http and create base:http presentation output
: ; check numeric operator in presentation
: ; check read json base:http and create base:http json output
: ; check numeric operator in json
: ; check read json base:http and create base:http presentation output
: ; check numeric group in presentation
: ; check read json base:http and create base:http json output
: ; check numeric group in json
fi
# TODO: test no source
# test with broken aliases file

Expand Down
39 changes: 37 additions & 2 deletions tests/nmsg-dns-tests/test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NMSGTOOL="@abs_top_builddir@/src/nmsgtool"
SOURCE=@abs_top_srcdir@/tests/nmsg-dns-tests/test1-dns
OUTPUT=@abs_top_builddir@/tests/nmsg-dns-tests/test1-dns

USE_JSON="@use_json_c@"

# cleanup from previous run
rm -f ${OUTPUT}*out

Expand All @@ -37,22 +39,36 @@ check read nmsg base:dns and create nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.nmsg.nmsg.out
check nmsg-to-nmsg

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j ${SOURCE}.json > ${OUTPUT}.json.pres.out
check read json base:dns and create presentation output
cmp -s ${SOURCE}.pres ${OUTPUT}.json.pres.out
check json-to-presentation
else
:
check json-to-presentation
fi

if [ "$USE_JSON" = "true" ]; then
# output should be same as input
$NMSGTOOL -j ${SOURCE}.json -J ${OUTPUT}.json.json.out
check read json base:dns and create json output
cmp -s ${SOURCE}.json ${OUTPUT}.json.json.out
check json-to-json
else
:
check json-to-json
fi

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j ${SOURCE}.json -w ${OUTPUT}.json.nmsg.out
check read json base:dns and create nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.json.nmsg.out
check json-to-nmsg

else
:
check json-to-nmsg
fi
# another test input
# TODO: use a function since is repeated

Expand All @@ -66,23 +82,42 @@ check read nmsg base:dns and create json output
cmp -s @abs_top_srcdir@/tests/nmsg-dns-tests/test2-dns.json @abs_top_builddir@/tests/nmsg-dns-tests/test2-dns.nmsg.json.out
check nmsg-to-json

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j @abs_top_srcdir@/tests/nmsg-dns-tests/test2-dns.json > @abs_top_builddir@/tests/nmsg-dns-tests/test2-dns.json.pres.out
check read json base:dns and create presentation output
cmp -s @abs_top_srcdir@/tests/nmsg-dns-tests/test2-dns.pres @abs_top_builddir@/tests/nmsg-dns-tests/test2-dns.json.pres.out
check json-to-presentation
else
:
check json-to-presentation
fi

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j @abs_top_srcdir@/tests/nmsg-dns-tests/test2-dns.json -J @abs_top_builddir@/tests/nmsg-dns-tests/test2-dns.json.json.out
check read json base:dns and create json output
cmp -s @abs_top_srcdir@/tests/nmsg-dns-tests/test2-dns.json @abs_top_builddir@/tests/nmsg-dns-tests/test2-dns.json.json.out
check json-to-json

else
:
check json-to-json
fi
# NOTE: --readpres is not fully implemented for base:dns so aborts

if [ "$USE_JSON" = "true" ]; then
# JSON input mistakes should result in no output
$NMSGTOOL -dd -j @abs_top_srcdir@/tests/nmsg-dns-tests/test3-dns.json --writepres @abs_top_builddir@/tests/nmsg-dns-tests/test3-dns.json.pres.out 2>@abs_top_builddir@/tests/nmsg-dns-tests/test3-dns.json.pres.stderr.out
check read broken json base:dns and create empty output
else
:
check broken json base:dns and create empty output
fi
if [ "$USE_JSON" = "true" ]; then
grep "JSON parse error:" @abs_top_builddir@/tests/nmsg-dns-tests/test3-dns.json.pres.stderr.out >/dev/null
check reports JSON parse error
else
:
check reports JSON parse error
fi
test ! -s @abs_top_builddir@/tests/nmsg-dns-tests/test3-dns.json.pres.out
check broken-json-to-empty-pres

Expand Down
23 changes: 23 additions & 0 deletions tests/nmsg-dnsobs-tests/test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ PAYLOAD="@abs_top_srcdir@/tests/nmsg-dnsobs-tests/test-dnsobs.nmsg"
SOURCE=@abs_top_srcdir@/tests/nmsg-dnsobs-tests/test1-dnsobs
OUTPUT=@abs_top_builddir@/tests/nmsg-dnsobs-tests/test1-dnsobs

USE_JSON="@use_json_c@"

# cleanup from previous run
rm -f ${OUTPUT}*out

Expand All @@ -33,26 +35,47 @@ check read nmsg base:dnsobs and create base:dnsobs nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.nmsg.nmsg.out
check nmsg-to-nmsg

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -r ${SOURCE}.nmsg -J ${OUTPUT}.nmsg.json.out
check read nmsg base:dnsobs and create base:dnsobs json output
cmp -s ${SOURCE}.json ${OUTPUT}.nmsg.json.out
check nmsg-to-json
else
:
check nmsg-to-json
fi


if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL --readjson ${SOURCE}.json > ${OUTPUT}.json.pres.out
check read json base:dnsobs and create dnsobs presentation output
cmp -s ${SOURCE}.pres ${OUTPUT}.json.pres.out
check json-to-presentation
else
:
check json-to-presentation
fi

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL --readjson ${SOURCE}.json -w ${OUTPUT}.json.nmsg.out
check read json base:dnsobs and create base:dnsobs nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.json.nmsg.out
check json-to-nmsg
else
:
check json-to-nmsg
fi

if [ "$USE_JSON" = "true" ]; then
# output should be same as input
$NMSGTOOL --readjson ${SOURCE}.json -J ${OUTPUT}.json.json.out
check read json base:dnsobs and create base:dnsobs json output
cmp -s ${SOURCE}.json ${OUTPUT}.json.json.out
check json-to-json
else
:
check json-to-json
fi

# NOTE: --readpres is not fully implemented for base:dnsobs

Expand Down
24 changes: 23 additions & 1 deletion tests/nmsg-dnsqr-tests/test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NMSGTOOL="@abs_top_builddir@/src/nmsgtool"
SOURCE=@abs_top_srcdir@/tests/nmsg-dnsqr-tests/test1-dnsqr
OUTPUT=@abs_top_builddir@/tests/nmsg-dnsqr-tests/test1-dnsqr

USE_JSON="@use_json_c@"

# cleanup from previous run
rm -f ${OUTPUT}*out

Expand All @@ -32,28 +34,48 @@ check read nmsg base:dnsqr and create nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.nmsg.nmsg.out
check nmsg-to-nmsg

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -r ${SOURCE}.nmsg -J ${OUTPUT}.nmsg.json.out
check read nmsg base:dnsqr and create json output
cmp -s ${SOURCE}.json ${OUTPUT}.nmsg.json.out
check nmsg-to-json
else
:
check nmsg-to-json
fi

############

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j ${SOURCE}.json > ${OUTPUT}.json.pres.out
check read json base:dnsqr and create presentation output
cmp -s ${SOURCE}.pres ${OUTPUT}.json.pres.out
check json-to-presentation
else
:
check json-to-presentation
fi

# output should be same as input
if [ "$USE_JSON" = "true" ]; then
#output should be same as input
$NMSGTOOL -j ${SOURCE}.json -J ${OUTPUT}.json.json.out
check read json base:dnsqr and create json output
cmp -s ${SOURCE}.json ${OUTPUT}.json.json.out
check json-to-json
else
:
check json-to-json
fi

if [ "$USE_JSON" = "true" ]; then
$NMSGTOOL -j ${SOURCE}.json -w ${OUTPUT}.json.nmsg.out
check read json base:dnsqr and create nmsg output
cmp -s ${SOURCE}.nmsg ${OUTPUT}.json.nmsg.out
check json-to-nmsg
else
:
check json-to-nmsg
fi

##############

Expand Down
Loading