From 7e2df3f8cfe2040c95a28581a79cce31642955c4 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Wed, 8 Sep 2021 16:26:54 +0930 Subject: [PATCH] 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) --- libbeat/cmd/instance/beat_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libbeat/cmd/instance/beat_test.go b/libbeat/cmd/instance/beat_test.go index 5d28a02af097..3d8c33b9f4f2 100644 --- a/libbeat/cmd/instance/beat_test.go +++ b/libbeat/cmd/instance/beat_test.go @@ -78,17 +78,32 @@ 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) api_key, err := kibanaConfig.String("api_key", -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)