Skip to content
Merged
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
8 changes: 4 additions & 4 deletions start-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ get_os_info() {
# Most modern Linux distributions have this file
. /etc/os-release
echo "Distribution: $NAME"
echo "Version: $VERSION"
echo "Version: ${VERSION:-}"
elif [ -f /etc/lsb-release ]; then
# For older distributions using LSB (Linux Standard Base)
. /etc/lsb-release
Expand Down Expand Up @@ -897,7 +897,7 @@ EOM
test:
[
"CMD-SHELL",
"curl --output /dev/null --silent --head --fail -u elastic:${ES_LOCAL_PASSWORD} http://elasticsearch:9200",
"curl --noproxy '*' --output /dev/null --silent --head --fail -u elastic:${ES_LOCAL_PASSWORD} http://elasticsearch:9200",
]
interval: 10s
timeout: 10s
Expand All @@ -919,7 +919,7 @@ if [ "$esonly" = "false" ]; then
echo "Setup the kibana_system password";
start_time=$$(date +%s);
timeout=60;
until curl -s -u "elastic:${ES_LOCAL_PASSWORD}" -X POST http://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_LOCAL_PASSWORD}\"}" -H "Content-Type: application/json" | grep -q "^{}"; do
until curl --noproxy "*" -s -u "elastic:${ES_LOCAL_PASSWORD}" -X POST http://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_LOCAL_PASSWORD}\"}" -H "Content-Type: application/json" | grep -q "^{}"; do
if [ $$(($$(date +%s) - $$start_time)) -ge $$timeout ]; then
echo "Error: Elasticsearch timeout";
exit 1;
Expand Down Expand Up @@ -968,7 +968,7 @@ fi
test:
[
"CMD-SHELL",
"curl -s -I http://kibana:5601 | grep -q 'HTTP/1.1 302 Found'",
"curl --noproxy '*' -s -I http://kibana:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
Expand Down
79 changes: 79 additions & 0 deletions tests/docker/proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Regression test for https://github.com/elastic/start-local/issues/79 (Bug 1):
# When Docker client proxy config injects HTTP_PROXY into containers, curl health
# checks route internal Docker network requests through the proxy and fail.
# The fix adds --noproxy '*' to all health check curl commands.

CURRENT_DIR=$(pwd)
DEFAULT_DIR="${CURRENT_DIR}/elastic-start-local"
ENV_PATH="${DEFAULT_DIR}/.env"
UNINSTALL_FILE="${DEFAULT_DIR}/uninstall.sh"
DOCKER_CONFIG_FILE="${HOME}/.docker/config.json"
DOCKER_CONFIG_BACKUP=""

# include external scripts
source "${CURRENT_DIR}/tests/utility.sh"

function set_up_before_script() {
# Back up existing Docker client config (it may contain auth credentials)
if [ -f "${DOCKER_CONFIG_FILE}" ]; then
DOCKER_CONFIG_BACKUP=$(mktemp)
cp "${DOCKER_CONFIG_FILE}" "${DOCKER_CONFIG_BACKUP}"
fi

# Inject a proxy pointing to a port where nothing listens (127.0.0.1:19999).
# Docker propagates this as HTTP_PROXY/HTTPS_PROXY into every container.
# Without --noproxy '*', curl health checks would fail (connection refused).
# We preserve any existing config keys (e.g. auth) via jq merge.
mkdir -p "${HOME}/.docker"
local proxy_snippet='{"proxies":{"default":{"httpProxy":"http://127.0.0.1:19999","httpsProxy":"http://127.0.0.1:19999"}}}'
if [ -n "${DOCKER_CONFIG_BACKUP}" ] && command -v jq > /dev/null 2>&1; then
jq ". + ${proxy_snippet}" "${DOCKER_CONFIG_BACKUP}" > "${DOCKER_CONFIG_FILE}"
else
printf '%s\n' "${proxy_snippet}" > "${DOCKER_CONFIG_FILE}"
fi

# shellcheck disable=SC2086
sh "${CURRENT_DIR}/${SCRIPT_FILE}"${SCRIPT_EXTRA_ARGS}
# shellcheck disable=SC1090
source "${ENV_PATH}"
}

function tear_down_after_script() {
printf "yes\nno\n" | "${UNINSTALL_FILE}"
rm -rf "${DEFAULT_DIR}"

# Restore the original Docker client config
if [ -n "${DOCKER_CONFIG_BACKUP}" ] && [ -f "${DOCKER_CONFIG_BACKUP}" ]; then
mv "${DOCKER_CONFIG_BACKUP}" "${DOCKER_CONFIG_FILE}"
else
rm -f "${DOCKER_CONFIG_FILE}"
fi
}

function test_elasticsearch_accessible_with_proxy_configured() {
result=$(get_http_response_code "http://localhost:9200" "elastic" "${ES_LOCAL_PASSWORD}")
assert_equals "200" "${result}"
}

function test_kibana_accessible_with_proxy_configured() {
result=$(get_http_response_code "http://localhost:5601")
assert_equals "200" "${result}"
}
65 changes: 65 additions & 0 deletions tests/get_os_info_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Regression test for https://github.com/elastic/start-local/issues/79 (Bug 2):
# On rolling-release distros like Arch Linux, /etc/os-release does not define VERSION.
# With `set -eu`, bare $VERSION causes an "unbound variable" crash.
# The fix uses ${VERSION:-} to default to an empty string.

# Test that the fixed code pattern does not crash when VERSION is absent from os-release
function test_get_os_info_succeeds_when_VERSION_is_not_defined() {
tmpdir=$(mktemp -d)
cat > "${tmpdir}/os-release" << 'EOF'
NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
HOME_URL="https://archlinux.org/"
EOF

# Run the exact code path from get_os_info() under set -eu.
# ${VERSION:-} should safely default to "" when VERSION is not exported.
output=$(bash -euc "
. '${tmpdir}/os-release'
echo \"Distribution: \$NAME\"
echo \"Version: \${VERSION:-}\"
" 2>&1)
exit_code=$?
rm -rf "${tmpdir}"

assert_equals "0" "${exit_code}"
assert_contains "Arch Linux" "${output}"
}

# Confirm that the unfixed pattern ($VERSION without :-) would have crashed,
# making the above test meaningful.
function test_bare_VERSION_crashes_under_set_eu_when_not_defined() {
tmpdir=$(mktemp -d)
cat > "${tmpdir}/os-release" << 'EOF'
NAME="Arch Linux"
ID=arch
EOF

bash -euc "
. '${tmpdir}/os-release'
echo \"\$VERSION\"
" > /dev/null 2>&1
exit_code=$?
rm -rf "${tmpdir}"

assert_not_equals "0" "${exit_code}"
}