From 5253eea284c7e21f31b4f5cd2713d17ad7e46dab Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:17:28 +0930 Subject: [PATCH] [7.15](backport #27178) libbeat/cmd/instance: ensure test config file has appropriate permissions (#27797) * libbeat/cmd/instance: ensure test config file has appropriate permissions (#27178) Git does not store r/w permissions, instead depending on the host system's umask. On some systems the default umask is 0o002, meaning that the test config file is checked out with g+w permission, causing the test to fail. This change ensures that the test config is owner-exclusive write before running the test. It also adds checks to currently ineffective error assignments. (cherry picked from commit 627b7a8b3ac48e0fb19b4788e5fa11f67c52d088) # Conflicts: # libbeat/cmd/instance/beat_test.go * libbeat/cmd/instance: resolve backport conflict Co-authored-by: Dan Kortschak Co-authored-by: Dan Kortschak --- libbeat/cmd/instance/beat_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index 8ceb79700d1c..58e32103c568 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -78,16 +78,30 @@ func TestInitKibanaConfig(t *testing.T) { assert.Equal(t, "testidx", b.Info.IndexPrefix) assert.Equal(t, "0.9", b.Info.Version) - cfg, err := cfgfile.Load("../test/filebeat_test.yml", nil) + const configPath = "../test/filebeat_test.yml" + + // Ensure that the config has owner-exclusive write permissions. + // This is necessary on some systems which have a default umask + // of 0o002, meaning that files are checked out by git with mode + // 0o664. This would cause cfgfile.Load to fail. + err = os.Chmod(configPath, 0o644) + assert.NoError(t, err) + + cfg, err := cfgfile.Load(configPath, nil) + assert.NoError(t, err) err = cfg.Unpack(&b.Config) assert.NoError(t, err) kibanaConfig, err := initKibanaConfig(b.Config) assert.NoError(t, err) username, err := kibanaConfig.String("username", -1) + assert.NoError(t, err) password, err := kibanaConfig.String("password", -1) + assert.NoError(t, err) protocol, err := kibanaConfig.String("protocol", -1) + assert.NoError(t, err) host, err := kibanaConfig.String("host", -1) + assert.NoError(t, err) assert.Equal(t, "elastic-test-username", username) assert.Equal(t, "elastic-test-password", password)