forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Be more strict when handling the access token (elastic#9624)
Add validations for the Kibana response with the access token, and enforce that the access token is not empty when unpacking the configuration. Since the access token in the keystore could be edited. Fixes: elastic#9621
- Loading branch information
Showing
5 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package management | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
) | ||
|
||
func TestConfigValidate(t *testing.T) { | ||
tests := map[string]struct { | ||
config *common.Config | ||
err bool | ||
}{ | ||
"missing access_token": { | ||
config: common.MustNewConfigFrom(map[string]interface{}{}), | ||
err: true, | ||
}, | ||
"access_token is present": { | ||
config: common.MustNewConfigFrom(map[string]interface{}{"access_token": "abc1234"}), | ||
err: false, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
c := defaultConfig() | ||
err := test.config.Unpack(c) | ||
if test.err { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |