diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index efe23d57478..f5e86b756fb 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -178,6 +178,9 @@ void Client::parseConnectionsCredentials(Poco::Util::AbstractConfiguration & con history_file = home_path + "/" + history_file.substr(1); config.setString("history_file", history_file); } + if (config.has(prefix + "accept-invalid-certificate")) { + config.setString("accept-invalid-certificate", prefix + "accept-invalid-certificate"); + } } if (!connection_name.empty() && !connection_found) @@ -721,7 +724,7 @@ bool Client::processWithFuzzing(const String & full_query) } if (auto *q = orig_ast->as()) { - if (auto *setDialect = q->changes.tryGet("dialect"); setDialect && setDialect->safeGet() == "kusto") + if (auto *set_dialect = q->changes.tryGet("dialect"); set_dialect && set_dialect->safeGet() == "kusto") return true; } @@ -1102,7 +1105,7 @@ void Client::processOptions(const OptionsDescription & options_description, config().setBool("no-warnings", true); if (options.count("fake-drop")) config().setString("ignore_drop_queries_probability", "1"); - if (options.count("accept-invalid-certificate")) + if (options.count("accept-invalid-certificate") || config().has("accept-invalid-certificate")) { config().setString("openSSL.client.invalidCertificateHandler.name", "AcceptCertificateHandler"); config().setString("openSSL.client.verificationMode", "none"); diff --git a/tests/queries/0_stateless/01189_clickhouse_accept_invalid_certificate.sh b/tests/queries/0_stateless/01189_clickhouse_accept_invalid_certificate.sh new file mode 100644 index 00000000000..00378abdb8e --- /dev/null +++ b/tests/queries/0_stateless/01189_clickhouse_accept_invalid_certificate.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash +# Tags: no-fasttest, no-random-settings + +CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CUR_DIR"/../shell_config.sh + +# use $CLICKHOUSE_DATABASE so that clickhouse-test will replace it with default to match .reference +config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE +xml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.xml +XML_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.XML +conf_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.conf +yml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.yml +yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.yaml +ini_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.ini + +function cleanup() { + rm "${config:?}" + rm "${xml_config:?}" + rm "${XML_config:?}" + rm "${conf_config:?}" + rm "${yml_config:?}" + rm "${yaml_config:?}" + rm "${ini_config:?}" +} +trap cleanup EXIT + +cat >"$config" < + + + + RejectCertificateHandler + + + + +EOL +cat >"$conf_config" < + + + + RejectCertificateHandler + + + + +EOL +cat >"$xml_config" < + + + + RejectCertificateHandler + + + + +EOL +cat >"$XML_config" < + + + + RejectCertificateHandler + + + + +EOL +cat >"$yml_config" <"$yaml_config" <"$ini_config" <RejectCertificateHandler') -q "select getSetting('invalidCertificateHandler')" + +echo 'yml' +$CLICKHOUSE_CLIENT --config "$yml_config" -q "select getSetting('invalidCertificateHandler')" +echo 'yaml' +$CLICKHOUSE_CLIENT --config "$yaml_config" -q "select getSetting('invalidCertificateHandler')" +echo 'ini' +$CLICKHOUSE_CLIENT --config "$ini_config" -q "select getSetting('invalidCertificateHandler')" 2>&1 |& sed -e "s#$CLICKHOUSE_TMP##" -e "s#DB::Exception: ##" diff --git a/tests/queries/0_stateless/01889_clickhouse_client_config_format.sh b/tests/queries/0_stateless/01889_clickhouse_client_config_format.sh index 4e970f17d3a..4af4e27653c 100755 --- a/tests/queries/0_stateless/01889_clickhouse_client_config_format.sh +++ b/tests/queries/0_stateless/01889_clickhouse_client_config_format.sh @@ -14,45 +14,44 @@ yml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.yml yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.yaml ini_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.ini -function cleanup() -{ - rm "${config:?}" - rm "${xml_config:?}" - rm "${XML_config:?}" - rm "${conf_config:?}" - rm "${yml_config:?}" - rm "${yaml_config:?}" - rm "${ini_config:?}" +function cleanup() { + rm "${config:?}" + rm "${xml_config:?}" + rm "${XML_config:?}" + rm "${conf_config:?}" + rm "${yml_config:?}" + rm "${yaml_config:?}" + rm "${ini_config:?}" } trap cleanup EXIT -cat > "$config" <"$config" < 2 EOL -cat > "$conf_config" <"$conf_config" < 2 EOL -cat > "$xml_config" <"$xml_config" < 2 EOL -cat > "$XML_config" <"$XML_config" < 2 EOL -cat > "$yml_config" <"$yml_config" < "$yaml_config" <"$yaml_config" < "$ini_config" <"$ini_config" < $CONFIG <$CONFIG < $TEST_HOST $TEST_PORT @@ -66,12 +66,21 @@ cat > $CONFIG <$TEST_HOST /no/such/dir/.history + + + test_accept_invalid_certificate + $TEST_HOST + $CLICKHOUSE_DATABASE + + RejectCertificateHandler + + EOL CONFIG_ROOT_OVERRIDES=$CLICKHOUSE_TMP/client_user_pass.xml -cat > $CONFIG_ROOT_OVERRIDES <$CONFIG_ROOT_OVERRIDES < $TEST_HOST $TEST_PORT