Skip to content

Commit

Permalink
[7.15](backport #27178) libbeat/cmd/instance: ensure test config file…
Browse files Browse the repository at this point in the history
… 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 627b7a8)

# Conflicts:
#	libbeat/cmd/instance/beat_test.go

* libbeat/cmd/instance: resolve backport conflict

Co-authored-by: Dan Kortschak <[email protected]>
Co-authored-by: Dan Kortschak <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2021
1 parent 16e7cb3 commit 5253eea
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5253eea

Please sign in to comment.