From 435c372ce5059082212d37ac7039844f14f34a80 Mon Sep 17 00:00:00 2001 From: Samuel BF <8824801-samuelbf@users.noreply.gitlab.com> Date: Thu, 5 Oct 2023 21:39:45 +0200 Subject: journal-gatewayd: add since/until parameters for /entries Request with Range header like 'entries=:' (with a colon at the end, invalid syntax per the doc), is now rejected with error 400 Bad Request. fix #4883 --- test/units/testsuite-04.journal-gatewayd.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/units/testsuite-04.journal-gatewayd.sh') diff --git a/test/units/testsuite-04.journal-gatewayd.sh b/test/units/testsuite-04.journal-gatewayd.sh index 5755ef1a0a..1b55bd39db 100755 --- a/test/units/testsuite-04.journal-gatewayd.sh +++ b/test/units/testsuite-04.journal-gatewayd.sh @@ -11,10 +11,13 @@ fi TEST_MESSAGE="-= This is a test message $RANDOM =-" TEST_TAG="$(systemd-id128 new)" +BEFORE_TIMESTAMP="$(date +%s)" echo "$TEST_MESSAGE" | systemd-cat -t "$TEST_TAG" +sleep 1 journalctl --sync TEST_CURSOR="$(journalctl -q -t "$TEST_TAG" -n 0 --show-cursor | awk '{ print $3; }')" BOOT_CURSOR="$(journalctl -q -b -n 0 --show-cursor | awk '{ print $3; }')" +AFTER_TIMESTAMP="$(date +%s)" /usr/lib/systemd/systemd-journal-gatewayd --version /usr/lib/systemd/systemd-journal-gatewayd --help @@ -47,6 +50,28 @@ curl -Lfs --header "Accept: application/json" --header "Range: entries=$BOOT_CUR # Check if the specified cursor refers to an existing entry and return just that entry curl -Lfs --header "Accept: application/json" --header "Range: entries=$TEST_CURSOR" http://localhost:19531/entries?discrete | \ jq -se "length == 1 and select(.[].MESSAGE == \"$TEST_MESSAGE\")" +# Check entry is present (resp. absent) when filtering by timestamp +curl -Lfs --header "Range: realtime=$BEFORE_TIMESTAMP:" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + grep -qE " $TEST_TAG\[[0-9]+\]: $TEST_MESSAGE" +curl -Lfs --header "Range: realtime=:$AFTER_TIMESTAMP" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + grep -qE " $TEST_TAG\[[0-9]+\]: $TEST_MESSAGE" +curl -Lfs --header "Accept: application/json" --header "Range: realtime=:$BEFORE_TIMESTAMP" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + jq -se "length == 0" +curl -Lfs --header "Accept: application/json" --header "Range: realtime=$AFTER_TIMESTAMP:" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + jq -se "length == 0" +# Check positive and negative skip when filtering by timestamp +echo "-= This is a second test message =-" | systemd-cat -t "$TEST_TAG" +journalctl --sync +TEST2_CURSOR="$(journalctl -q -t "$TEST_TAG" -n 0 --show-cursor | awk '{ print $3; }')" +echo "-= This is a third test message =-" | systemd-cat -t "$TEST_TAG" +journalctl --sync +sleep 1 +END_TIMESTAMP="$(date +%s)" +curl -Lfs --header "Accept: application/json" --header "Range: realtime=$BEFORE_TIMESTAMP::1:1" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + jq -se "length == 1 and select(.[].__CURSOR == \"$TEST2_CURSOR\")" +curl -Lfs --header "Accept: application/json" --header "Range: realtime=$END_TIMESTAMP::-1:1" http://localhost:19531/entries?SYSLOG_IDENTIFIER="$TEST_TAG" | \ + jq -se "length == 1 and select(.[].__CURSOR == \"$TEST2_CURSOR\")" + # No idea how to properly parse this (jq won't cut it), so let's at least do some sanity checks that every # line is either empty or begins with data: curl -Lfs --header "Accept: text/event-stream" http://localhost:19531/entries | \ -- cgit v1.2.3