[Tests] Do not pass all env vars to sudo (#21562)

In #21348 the command executed to run the packaging tests has been changed to "sudo -E bats ...", forcing all environment variables from the vagrant user to be passed to the `sudo` command. This breaks a test on opensuse-13 (the one where it checks that elasticsearch cannot be started when `java` is not found) because all the PATH from the user is passed to the sudo command.

This commit restores the previous behavior while allowing only necessary testing environment variables to be passed using a /etc/sudoers.d file.
This commit is contained in:
Tanguy Leroux 2016-11-15 15:19:34 +01:00 committed by GitHub
parent d6c2b4f7c5
commit aa871f839a
4 changed files with 21 additions and 3 deletions

10
Vagrantfile vendored
View File

@ -280,5 +280,15 @@ export BATS_UTILS=/project/build/bats/utils
export BATS_TESTS=/project/build/bats/tests
export BATS_ARCHIVES=/project/build/bats/archives
VARS
cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars
Defaults env_keep += "ZIP"
Defaults env_keep += "TAR"
Defaults env_keep += "RPM"
Defaults env_keep += "DEB"
Defaults env_keep += "BATS"
Defaults env_keep += "BATS_UTILS"
Defaults env_keep += "BATS_TESTS"
Defaults env_keep += "BATS_ARCHIVES"
SUDOERS_VARS
SHELL
end

View File

@ -40,7 +40,7 @@ class VagrantTestPlugin implements Plugin<Project> {
static List<String> UPGRADE_FROM_ARCHIVES = ['rpm', 'deb']
private static final BATS = 'bats'
private static final String BATS_TEST_COMMAND ="cd \$BATS_ARCHIVES && sudo -E bats --tap \$BATS_TESTS/*.$BATS"
private static final String BATS_TEST_COMMAND ="cd \$BATS_ARCHIVES && sudo bats --tap \$BATS_TESTS/*.$BATS"
@Override
void apply(Project project) {

View File

@ -88,7 +88,11 @@ setup() {
sudo chmod +x $JAVA
[ "$status" -eq 1 ]
[[ "$output" == *"Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"* ]]
local expected="Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
[[ "$output" == *"$expected"* ]] || {
echo "Expected error message [$expected] but found: $output"
false
}
}
##################################

View File

@ -176,7 +176,11 @@ fi
sudo chmod +x $JAVA
[ "$status" -eq 1 ]
[[ "$output" == *"Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"* ]]
local expected="Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
[[ "$output" == *"$expected"* ]] || {
echo "Expected error message [$expected] but found: $output"
false
}
}
# Note that all of the tests from here to the end of the file expect to be run