2023-04-19 21:54:14 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2023-07-04 13:53:12 +00:00
|
|
|
"time"
|
2023-04-19 21:54:14 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPI_ConfigEntries_JWTProvider(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
c, s := makeClient(t)
|
|
|
|
defer s.Stop()
|
|
|
|
|
|
|
|
entries := c.ConfigEntries()
|
|
|
|
|
|
|
|
testutil.RunStep(t, "set and get", func(t *testing.T) {
|
2023-07-04 13:53:12 +00:00
|
|
|
connectTimeout := time.Duration(5) * time.Second
|
2023-04-19 21:54:14 +00:00
|
|
|
jwtProvider := &JWTProviderConfigEntry{
|
|
|
|
Name: "okta",
|
|
|
|
Kind: JWTProvider,
|
|
|
|
JSONWebKeySet: &JSONWebKeySet{
|
2023-07-04 13:53:12 +00:00
|
|
|
Remote: &RemoteJWKS{
|
|
|
|
FetchAsynchronously: true,
|
|
|
|
URI: "https://example.com/.well-known/jwks.json",
|
|
|
|
JWKSCluster: &JWKSCluster{
|
|
|
|
DiscoveryType: "STATIC",
|
|
|
|
ConnectTimeout: connectTimeout,
|
|
|
|
TLSCertificates: &JWKSTLSCertificate{
|
|
|
|
TrustedCA: &JWKSTLSCertTrustedCA{
|
|
|
|
Filename: "myfile.cert",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-19 21:54:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Meta: map[string]string{
|
|
|
|
"gir": "zim",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, wm, err := entries.Set(jwtProvider, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, wm)
|
|
|
|
require.NotEqual(t, 0, wm.RequestTime)
|
|
|
|
|
|
|
|
entry, qm, err := entries.Get(JWTProvider, "okta", nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, qm)
|
|
|
|
require.NotEqual(t, 0, qm.RequestTime)
|
|
|
|
|
|
|
|
result, ok := entry.(*JWTProviderConfigEntry)
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
require.Equal(t, jwtProvider.Name, result.Name)
|
|
|
|
require.Equal(t, jwtProvider.JSONWebKeySet, result.JSONWebKeySet)
|
|
|
|
})
|
|
|
|
}
|