Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbeat/cmd/instance: ensure test config file has appropriate permissions #27178

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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