fix(secretstores.oauth2): Ensure endpoint params is not nil (#15531)

This commit is contained in:
Joshua Powers 2024-06-19 01:42:02 -06:00 committed by GitHub
parent 6fb42764e1
commit 80e94f7043
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
_ "embed" _ "embed"
"errors" "errors"
"fmt" "fmt"
"net/url"
"strings" "strings"
"time" "time"
@ -126,11 +127,12 @@ func (o *OAuth2) Init() error {
// Setup the configuration // Setup the configuration
cfg := &clientcredentials.Config{ cfg := &clientcredentials.Config{
ClientID: cid.String(), ClientID: cid.String(),
ClientSecret: csecret.String(), ClientSecret: csecret.String(),
TokenURL: endpoint.TokenURL, TokenURL: endpoint.TokenURL,
Scopes: c.Scopes, Scopes: c.Scopes,
AuthStyle: endpoint.AuthStyle, AuthStyle: endpoint.AuthStyle,
EndpointParams: url.Values{},
} }
cid.Destroy() cid.Destroy()
csecret.Destroy() csecret.Destroy()

View File

@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/influxdata/telegraf/config" "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/testutil"
) )
func TestSampleConfig(t *testing.T) { func TestSampleConfig(t *testing.T) {
@ -19,6 +20,26 @@ func TestSampleConfig(t *testing.T) {
require.NotEmpty(t, plugin.SampleConfig()) require.NotEmpty(t, plugin.SampleConfig())
} }
func TestEndpointParams(t *testing.T) {
plugin := &OAuth2{
Endpoint: "http://localhost:8080/token",
Tenant: "tenantID",
TokenConfigs: []TokenConfig{
{
ClientID: config.NewSecret([]byte("clientID")),
ClientSecret: config.NewSecret([]byte("clientSecret")),
Key: "test",
Params: map[string]string{
"foo": "bar",
},
},
},
Log: testutil.Logger{},
}
require.NoError(t, plugin.Init())
}
func TestInitFail(t *testing.T) { func TestInitFail(t *testing.T) {
tests := []struct { tests := []struct {
name string name string