From 9653551072730f8dec3cd809b5b41ad574a62cad Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 17 Apr 2017 16:36:32 -0400 Subject: Add package test to catch leaking default.data.path setting (#24029) Adds a packaging test that would have detected #23981. The test configures path.data and validates that nothing ends up in default.path.data. --- TESTING.asciidoc | 7 +- .../packaging/tests/75_bad_data_paths.bats | 77 ++++++++++++++++++++++ .../src/test/resources/packaging/utils/utils.bash | 3 +- 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 qa/vagrant/src/test/resources/packaging/tests/75_bad_data_paths.bats diff --git a/TESTING.asciidoc b/TESTING.asciidoc index a1a01a8f23..43b53fd360 100644 --- a/TESTING.asciidoc +++ b/TESTING.asciidoc @@ -362,7 +362,7 @@ quality boxes available in vagrant atlas: * sles-11 -We're missing the follow because our tests are very linux/bash centric: +We're missing the following because our tests are very linux/bash centric: * Windows Server 2012 @@ -418,8 +418,8 @@ sudo -E bats $BATS_TESTS/*rpm*.bats If you wanted to retest all the release artifacts on a single VM you could: ------------------------------------------------- -gradle vagrantSetUp -vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404 +gradle setupBats +cd qa/vagrant; vagrant up ubuntu-1404 --provider virtualbox && vagrant ssh ubuntu-1404 cd $BATS_ARCHIVES sudo -E bats $BATS_TESTS/*.bats ------------------------------------------------- @@ -505,4 +505,3 @@ included as part of the build by checking the projects of the build. --------------------------------------------------------------------------- gradle projects --------------------------------------------------------------------------- - diff --git a/qa/vagrant/src/test/resources/packaging/tests/75_bad_data_paths.bats b/qa/vagrant/src/test/resources/packaging/tests/75_bad_data_paths.bats new file mode 100644 index 0000000000..0f802a439b --- /dev/null +++ b/qa/vagrant/src/test/resources/packaging/tests/75_bad_data_paths.bats @@ -0,0 +1,77 @@ +#!/usr/bin/env bats + +# Tests data.path settings which in the past have misbehaving, leaking the +# default.data.path setting into the data.path even when it doesn't belong. + +# WARNING: This testing file must be executed as root and can +# dramatically change your system. It removes the 'elasticsearch' +# user/group and also many directories. Do not execute this file +# unless you know exactly what you are doing. + +# The test case can be executed with the Bash Automated +# Testing System tool available at https://github.com/sstephenson/bats +# Thanks to Sam Stephenson! + +# Licensed to Elasticsearch under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch 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. + +# Load test utilities +load $BATS_UTILS/packages.bash +load $BATS_UTILS/tar.bash +load $BATS_UTILS/utils.bash + +@test "[BAD data.path] install package" { + clean_before_test + skip_not_dpkg_or_rpm + install_package +} + +@test "[BAD data.path] setup funny path.data in package install" { + skip_not_dpkg_or_rpm + local temp=`mktemp -d` + chown elasticsearch:elasticsearch "$temp" + echo "path.data: [$temp]" > "/etc/elasticsearch/elasticsearch.yml" +} + +@test "[BAD data.path] start installed from package" { + skip_not_dpkg_or_rpm + start_elasticsearch_service green +} + +@test "[BAD data.path] check for bad dir after starting from package" { + skip_not_dpkg_or_rpm + assert_file_not_exist /var/lib/elasticsearch/nodes +} + +@test "[BAD data.path] install tar" { + clean_before_test + install_archive +} + +@test "[BAD data.path] setup funny path.data in tar install" { + local temp=`mktemp -d` + chown elasticsearch:elasticsearch "$temp" + echo "path.data: [$temp]" > "/tmp/elasticsearch/config/elasticsearch.yml" +} + +@test "[BAD data.path] start installed from tar" { + start_elasticsearch_service green "" "-Edefault.path.data=/tmp/elasticsearch/data" +} + +@test "[BAD data.path] check for bad dir after starting from tar" { + assert_file_not_exist "/tmp/elasticsearch/data/nodes" +} diff --git a/qa/vagrant/src/test/resources/packaging/utils/utils.bash b/qa/vagrant/src/test/resources/packaging/utils/utils.bash index 0272dc8faf..877f49b576 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/utils.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/utils.bash @@ -297,8 +297,9 @@ purge_elasticsearch() { start_elasticsearch_service() { local desiredStatus=${1:-green} local index=$2 + local commandLineArgs=$3 - run_elasticsearch_service 0 + run_elasticsearch_service 0 $commandLineArgs wait_for_elasticsearch_status $desiredStatus $index -- cgit v1.2.3