From b91647902503c1a069c2fabeabdb6a1bf02bc443 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 25 Feb 2024 23:54:55 +0100 Subject: [PATCH] Add a test --- programs/server/config.d/handlers.yaml | 1 + tests/config/config.d/handlers.yaml | 8 ++++++++ tests/config/install.sh | 1 + .../02998_http_redirects.reference | 5 +++++ .../0_stateless/02998_http_redirects.sh | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+) create mode 120000 programs/server/config.d/handlers.yaml create mode 100644 tests/config/config.d/handlers.yaml create mode 100644 tests/queries/0_stateless/02998_http_redirects.reference create mode 100755 tests/queries/0_stateless/02998_http_redirects.sh diff --git a/programs/server/config.d/handlers.yaml b/programs/server/config.d/handlers.yaml new file mode 120000 index 00000000000..86dfc38179b --- /dev/null +++ b/programs/server/config.d/handlers.yaml @@ -0,0 +1 @@ +../../../tests/config/config.d/handlers.yaml \ No newline at end of file diff --git a/tests/config/config.d/handlers.yaml b/tests/config/config.d/handlers.yaml new file mode 100644 index 00000000000..c77dd6578c1 --- /dev/null +++ b/tests/config/config.d/handlers.yaml @@ -0,0 +1,8 @@ +http_handlers: + rule: + url: '/upyachka' + empty_query_string: + handler: + type: redirect + location: "/?query=SELECT+'Pepyaka'" + defaults: diff --git a/tests/config/install.sh b/tests/config/install.sh index 9d55529c1f3..f19a87c98d8 100755 --- a/tests/config/install.sh +++ b/tests/config/install.sh @@ -66,6 +66,7 @@ ln -sf $SRC_PATH/config.d/filesystem_caches_path.xml $DEST_SERVER_PATH/config.d/ ln -sf $SRC_PATH/config.d/validate_tcp_client_information.xml $DEST_SERVER_PATH/config.d/ ln -sf $SRC_PATH/config.d/zero_copy_destructive_operations.xml $DEST_SERVER_PATH/config.d/ ln -sf $SRC_PATH/config.d/block_number.xml $DEST_SERVER_PATH/config.d/ +ln -sf $SRC_PATH/config.d/handlers.yaml $DEST_SERVER_PATH/config.d/ # Not supported with fasttest. if [ "${DEST_SERVER_PATH}" = "/etc/clickhouse-server" ] diff --git a/tests/queries/0_stateless/02998_http_redirects.reference b/tests/queries/0_stateless/02998_http_redirects.reference new file mode 100644 index 00000000000..527e7df71c3 --- /dev/null +++ b/tests/queries/0_stateless/02998_http_redirects.reference @@ -0,0 +1,5 @@ +Ok. +HTTP/1.1 302 Found +Location: /?query=SELECT+'Pepyaka' +HTTP/1.1 404 Not Found +Pepyaka diff --git a/tests/queries/0_stateless/02998_http_redirects.sh b/tests/queries/0_stateless/02998_http_redirects.sh new file mode 100755 index 00000000000..8a8df884f9f --- /dev/null +++ b/tests/queries/0_stateless/02998_http_redirects.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +URL="${CLICKHOUSE_PORT_HTTP_PROTO}://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTP}" + +# Ping handler +${CLICKHOUSE_CURL} -s -S "${URL}/" + +# A handler that is configured to return a redirect +${CLICKHOUSE_CURL} -s -S -I "${URL}/upyachka" | grep -i -P '^HTTP|Location' + +# This handler is configured to not accept any query string +${CLICKHOUSE_CURL} -s -S -I "${URL}/upyachka?hello=world" | grep -i -P '^HTTP|Location' + +# Check that actual redirect works +${CLICKHOUSE_CURL} -s -S -L "${URL}/upyachka"