Skip to content

Commit

Permalink
fix(secretstores.oauth2): Ensure endpoint params is not nil (#15531)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Jun 19, 2024
1 parent 6fb4276 commit 80e94f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 7 additions & 5 deletions plugins/secretstores/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "embed"
"errors"
"fmt"
"net/url"
"strings"
"time"

Expand Down Expand Up @@ -126,11 +127,12 @@ func (o *OAuth2) Init() error {

// Setup the configuration
cfg := &clientcredentials.Config{
ClientID: cid.String(),
ClientSecret: csecret.String(),
TokenURL: endpoint.TokenURL,
Scopes: c.Scopes,
AuthStyle: endpoint.AuthStyle,
ClientID: cid.String(),
ClientSecret: csecret.String(),
TokenURL: endpoint.TokenURL,
Scopes: c.Scopes,
AuthStyle: endpoint.AuthStyle,
EndpointParams: url.Values{},
}
cid.Destroy()
csecret.Destroy()
Expand Down
21 changes: 21 additions & 0 deletions plugins/secretstores/oauth2/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,34 @@ import (
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/testutil"
)

func TestSampleConfig(t *testing.T) {
plugin := &OAuth2{}
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) {
tests := []struct {
name string
Expand Down

0 comments on commit 80e94f7

Please sign in to comment.