diff options
author | Samuel BF <8824801-samuelbf@users.noreply.gitlab.com> | 2023-10-05 21:39:45 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-12-06 22:22:27 +0100 |
commit | 435c372ce5059082212d37ac7039844f14f34a80 (patch) | |
tree | 3e8eeb0b5f4eb16e48405efede2c944c4555a208 /test/units/testsuite-04.journal-gatewayd.sh | |
parent | udev: generate system-unique storage symlinks using device path (diff) | |
download | systemd-435c372ce5059082212d37ac7039844f14f34a80.tar.xz systemd-435c372ce5059082212d37ac7039844f14f34a80.zip |
journal-gatewayd: add since/until parameters for /entries
Request with Range header like 'entries=<cursor>:' (with a colon at the end,
invalid syntax per the doc), is now rejected with error 400 Bad Request.
fix #4883
Diffstat (limited to '')
-rwxr-xr-x | test/units/testsuite-04.journal-gatewayd.sh | 25 |
1 files changed, 25 insertions, 0 deletions
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 | \ |