Show exit code in Bootstrap Password packaging tests

Also cleans up some files before the test is executed,
and explicitly binds to 127.0.0.1/9200.

Original commit: elastic/x-pack-elasticsearch@778584ea78
This commit is contained in:
Tanguy Leroux 2017-10-10 09:51:22 +02:00
parent 80593fb23c
commit 1ed4be1471
1 changed files with 23 additions and 7 deletions

View File

@ -44,39 +44,55 @@ else
fi
@test "[$GROUP] add bootstrap.password setting" {
if [[ -f /tmp/bootstrap.password ]]; then
sudo rm -f /tmp/bootstrap.password
fi
run sudo -E -u $ESPLUGIN_COMMAND_USER sh <<"NEW_PASS"
cat /dev/urandom | tr -dc "[a-zA-Z0-9]" | fold -w 20 | head -n 1 > /tmp/bootstrap.password
cat /tmp/bootstrap.password | $ESHOME/bin/elasticsearch-keystore add --stdin bootstrap.password
NEW_PASS
[ "$status" -eq 0 ] || {
echo "Expected elasticsearch-keystore tool exit code to be zero"
echo "Expected elasticsearch-keystore tool exit code to be zero but got [$status]"
echo "$output"
false
}
assert_file_exist "/tmp/bootstrap.password"
}
@test "[$GROUP] test bootstrap.password is in setting list" {
run sudo -E -u $DATA_USER sh <<"NODE_SETTINGS"
cat >> $ESCONFIG/elasticsearch.yml <<- EOF
network.host: 127.0.0.1
http.port: 9200
EOF
NODE_SETTINGS
run_elasticsearch_service 0
wait_for_xpack
wait_for_xpack 127.0.0.1 9200
sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-keystore" list | grep "bootstrap.password"
password=$(cat /tmp/bootstrap.password)
curl -u "elastic:$password" -XGET localhost:9200 | grep "You Know, for Search"
curl -u "elastic:$password" -XGET 'http://127.0.0.1:9200' | grep "You Know, for Search"
}
@test "[$GROUP] test auto generated passwords with modified bootstrap.password" {
if [[ -f /tmp/setup-passwords-output-with-bootstrap ]]; then
sudo rm -f /tmp/setup-passwords-output-with-bootstrap
fi
run sudo -E -u $ESPLUGIN_COMMAND_USER sh <<"SETUP_OK"
echo 'y' | $ESHOME/bin/x-pack/setup-passwords auto
SETUP_OK
echo "$output" > /tmp/setup-passwords-output-with-bootstrap
[ "$status" -eq 0 ] || {
echo "Expected x-pack setup-passwords tool exit code to be zero"
echo "Expected x-pack setup-passwords tool exit code to be zero but got [$status]"
cat /tmp/setup-passwords-output-with-bootstrap
false
}
curl -s -XGET localhost:9200 | grep "missing authentication token for REST"
curl -s -XGET 'http://127.0.0.1:9200' | grep "missing authentication token for REST"
# Disable bash history expansion because passwords can contain "!"
set +H
@ -90,10 +106,10 @@ SETUP_OK
}
password=$(grep "PASSWORD $user = " /tmp/setup-passwords-output-with-bootstrap | sed "s/PASSWORD $user = //")
curl -u "$user:$password" -XGET localhost:9200 | grep "You Know, for Search"
curl -u "$user:$password" -XGET 'http://127.0.0.1:9200' | grep "You Know, for Search"
basic=$(echo -n "$user:$password" | base64)
curl -H "Authorization: Basic $basic" -XGET localhost:9200 | grep "You Know, for Search"
curl -H "Authorization: Basic $basic" -XGET 'http://127.0.0.1:9200' | grep "You Know, for Search"
done
set -H