|
|
|
@ -5,40 +5,26 @@ import ( |
|
|
|
"crypto/tls" |
|
|
|
"crypto/tls" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/http/httptest" |
|
|
|
"net/http/httptest" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
"path/filepath" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
"github.com/sirupsen/logrus" |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/stretchr/testify/suite" |
|
|
|
"github.com/stretchr/testify/suite" |
|
|
|
"sigs.k8s.io/testing_frameworks/integration" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/dexidp/dex/storage" |
|
|
|
"github.com/dexidp/dex/storage" |
|
|
|
"github.com/dexidp/dex/storage/conformance" |
|
|
|
"github.com/dexidp/dex/storage/conformance" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const kubeconfigTemplate = `apiVersion: v1 |
|
|
|
const kubeconfigPathVariableName = "DEX_KUBERNETES_CONFIG_PATH" |
|
|
|
kind: Config |
|
|
|
|
|
|
|
clusters: |
|
|
|
|
|
|
|
- name: local |
|
|
|
|
|
|
|
cluster: |
|
|
|
|
|
|
|
server: SERVERURL |
|
|
|
|
|
|
|
users: |
|
|
|
|
|
|
|
- name: local |
|
|
|
|
|
|
|
user: |
|
|
|
|
|
|
|
contexts: |
|
|
|
|
|
|
|
- context: |
|
|
|
|
|
|
|
cluster: local |
|
|
|
|
|
|
|
user: local |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestStorage(t *testing.T) { |
|
|
|
func TestStorage(t *testing.T) { |
|
|
|
if os.Getenv("TEST_ASSET_KUBE_APISERVER") == "" || os.Getenv("TEST_ASSET_ETCD") == "" { |
|
|
|
if os.Getenv(kubeconfigPathVariableName) == "" { |
|
|
|
t.Skip("control plane binaries are missing") |
|
|
|
t.Skip(fmt.Sprintf("variable %q not set, skipping kubernetes storage tests\n", kubeconfigPathVariableName)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
suite.Run(t, new(StorageTestSuite)) |
|
|
|
suite.Run(t, new(StorageTestSuite)) |
|
|
|
@ -46,33 +32,24 @@ func TestStorage(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
type StorageTestSuite struct { |
|
|
|
type StorageTestSuite struct { |
|
|
|
suite.Suite |
|
|
|
suite.Suite |
|
|
|
|
|
|
|
|
|
|
|
controlPlane *integration.ControlPlane |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client *client |
|
|
|
client *client |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *StorageTestSuite) SetupSuite() { |
|
|
|
func (s *StorageTestSuite) expandDir(dir string) string { |
|
|
|
s.controlPlane = &integration.ControlPlane{} |
|
|
|
if strings.HasPrefix(dir, "~/") { |
|
|
|
|
|
|
|
homedir, err := os.UserHomeDir() |
|
|
|
err := s.controlPlane.Start() |
|
|
|
s.Require().NoError(err) |
|
|
|
s.Require().NoError(err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *StorageTestSuite) TearDownSuite() { |
|
|
|
dir = filepath.Join(homedir, strings.TrimPrefix(dir, "~/")) |
|
|
|
s.controlPlane.Stop() |
|
|
|
} |
|
|
|
|
|
|
|
return dir |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *StorageTestSuite) SetupTest() { |
|
|
|
func (s *StorageTestSuite) SetupTest() { |
|
|
|
f, err := ioutil.TempFile("", "dex-kubeconfig-*") |
|
|
|
kubeconfigPath := s.expandDir(os.Getenv(kubeconfigPathVariableName)) |
|
|
|
s.Require().NoError(err) |
|
|
|
|
|
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, err = f.WriteString(strings.ReplaceAll(kubeconfigTemplate, "SERVERURL", s.controlPlane.APIURL().String())) |
|
|
|
|
|
|
|
s.Require().NoError(err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config := Config{ |
|
|
|
config := Config{ |
|
|
|
KubeConfigFile: f.Name(), |
|
|
|
KubeConfigFile: kubeconfigPath, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logger := &logrus.Logger{ |
|
|
|
logger := &logrus.Logger{ |
|
|
|
@ -81,10 +58,10 @@ func (s *StorageTestSuite) SetupTest() { |
|
|
|
Level: logrus.DebugLevel, |
|
|
|
Level: logrus.DebugLevel, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
client, err := config.open(logger, true) |
|
|
|
kubeClient, err := config.open(logger, true) |
|
|
|
s.Require().NoError(err) |
|
|
|
s.Require().NoError(err) |
|
|
|
|
|
|
|
|
|
|
|
s.client = client |
|
|
|
s.client = kubeClient |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *StorageTestSuite) TestStorage() { |
|
|
|
func (s *StorageTestSuite) TestStorage() { |
|
|
|
|