Skip to content

Commit

Permalink
libbeat/cmd/instance: ensure test config file has appropriate permiss…
Browse files Browse the repository at this point in the history
…ions

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.
  • Loading branch information
kortschak committed Sep 7, 2021
1 parent 5113d4d commit cd1d8c0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,31 @@ 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 := InitKibanaConfig(b.Config)
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)
Expand Down

0 comments on commit cd1d8c0

Please sign in to comment.