mirror of
https://github.com/status-im/consul.git
synced 2025-02-18 00:27:04 +00:00
go-sso: remove returnFunc now that freeport handles return
This commit is contained in:
parent
8c7475d95e
commit
56f9238d15
@ -1658,7 +1658,7 @@ func TestACLEndpoint_LoginLogout_jwt(t *testing.T) {
|
|||||||
testrpc.WaitForLeader(t, a.RPC, "dc1")
|
testrpc.WaitForLeader(t, a.RPC, "dc1")
|
||||||
|
|
||||||
// spin up a fake oidc server
|
// spin up a fake oidc server
|
||||||
oidcServer := startSSOTestServer(t)
|
oidcServer := oidcauthtest.Start(t, oidcauthtest.WithPort(freeport.Port(t)))
|
||||||
pubKey, privKey := oidcServer.SigningKeys()
|
pubKey, privKey := oidcServer.SigningKeys()
|
||||||
|
|
||||||
type mConfig = map[string]interface{}
|
type mConfig = map[string]interface{}
|
||||||
@ -2330,14 +2330,6 @@ func upsertTestCustomizedBindingRule(rpc rpcFn, masterToken string, datacenter s
|
|||||||
return &out, nil
|
return &out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startSSOTestServer(t *testing.T) *oidcauthtest.Server {
|
|
||||||
ports := freeport.MustTake(1)
|
|
||||||
return oidcauthtest.Start(t, oidcauthtest.WithPort(
|
|
||||||
ports[0],
|
|
||||||
func() { freeport.Return(ports) },
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestHTTPHandlers_ACLReplicationStatus(t *testing.T) {
|
func TestHTTPHandlers_ACLReplicationStatus(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("too slow for testing.Short")
|
t.Skip("too slow for testing.Short")
|
||||||
|
@ -4868,7 +4868,7 @@ func TestACLEndpoint_Login_jwt(t *testing.T) {
|
|||||||
acl := ACL{srv: srv}
|
acl := ACL{srv: srv}
|
||||||
|
|
||||||
// spin up a fake oidc server
|
// spin up a fake oidc server
|
||||||
oidcServer := startSSOTestServer(t)
|
oidcServer := oidcauthtest.Start(t, oidcauthtest.WithPort(freeport.Port(t)))
|
||||||
pubKey, privKey := oidcServer.SigningKeys()
|
pubKey, privKey := oidcServer.SigningKeys()
|
||||||
|
|
||||||
type mConfig = map[string]interface{}
|
type mConfig = map[string]interface{}
|
||||||
@ -5003,14 +5003,6 @@ func TestACLEndpoint_Login_jwt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startSSOTestServer(t *testing.T) *oidcauthtest.Server {
|
|
||||||
ports := freeport.MustTake(1)
|
|
||||||
return oidcauthtest.Start(t, oidcauthtest.WithPort(
|
|
||||||
ports[0],
|
|
||||||
func() { freeport.Return(ports) },
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestACLEndpoint_Logout(t *testing.T) {
|
func TestACLEndpoint_Logout(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("too slow for testing.Short")
|
t.Skip("too slow for testing.Short")
|
||||||
|
@ -32,7 +32,7 @@ func TestJWT_NewValidator(t *testing.T) {
|
|||||||
return method
|
return method
|
||||||
}
|
}
|
||||||
|
|
||||||
oidcServer := startTestServer(t)
|
oidcServer := oidcauthtest.Start(t, oidcauthtest.WithPort(freeport.Port(t)))
|
||||||
|
|
||||||
// Note that we won't test ALL of the available config variations here.
|
// Note that we won't test ALL of the available config variations here.
|
||||||
// The go-sso library has exhaustive tests.
|
// The go-sso library has exhaustive tests.
|
||||||
@ -110,7 +110,7 @@ func TestJWT_ValidateLogin(t *testing.T) {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
oidcServer := startTestServer(t)
|
oidcServer := oidcauthtest.Start(t, oidcauthtest.WithPort(freeport.Port(t)))
|
||||||
pubKey, privKey := oidcServer.SigningKeys()
|
pubKey, privKey := oidcServer.SigningKeys()
|
||||||
|
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
@ -260,11 +260,3 @@ func kv(a ...string) map[string]string {
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func startTestServer(t *testing.T) *oidcauthtest.Server {
|
|
||||||
ports := freeport.MustTake(1)
|
|
||||||
return oidcauthtest.Start(t, oidcauthtest.WithPort(
|
|
||||||
ports[0],
|
|
||||||
func() { freeport.Return(ports) },
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
@ -352,7 +352,7 @@ func TestLoginCommand_jwt(t *testing.T) {
|
|||||||
bearerTokenFile := filepath.Join(testDir, "bearer.token")
|
bearerTokenFile := filepath.Join(testDir, "bearer.token")
|
||||||
|
|
||||||
// spin up a fake oidc server
|
// spin up a fake oidc server
|
||||||
oidcServer := startSSOTestServer(t)
|
oidcServer := oidcauthtest.Start(t, oidcauthtest.WithPort(freeport.Port(t)))
|
||||||
pubKey, privKey := oidcServer.SigningKeys()
|
pubKey, privKey := oidcServer.SigningKeys()
|
||||||
|
|
||||||
type mConfig = map[string]interface{}
|
type mConfig = map[string]interface{}
|
||||||
@ -470,11 +470,3 @@ func TestLoginCommand_jwt(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startSSOTestServer(t *testing.T) *oidcauthtest.Server {
|
|
||||||
ports := freeport.MustTake(1)
|
|
||||||
return oidcauthtest.Start(t, oidcauthtest.WithPort(
|
|
||||||
ports[0],
|
|
||||||
func() { freeport.Return(ports) },
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
@ -25,7 +25,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/internal/go-sso/oidcauth/internal/strutil"
|
"github.com/hashicorp/consul/internal/go-sso/oidcauth/internal/strutil"
|
||||||
"github.com/mitchellh/go-testing-interface"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/square/go-jose.v2"
|
"gopkg.in/square/go-jose.v2"
|
||||||
"gopkg.in/square/go-jose.v2/jwt"
|
"gopkg.in/square/go-jose.v2/jwt"
|
||||||
@ -55,24 +54,27 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type startOption struct {
|
type startOption struct {
|
||||||
port int
|
port int
|
||||||
returnFunc func()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithPort is a option for Start that lets the caller control the port
|
// WithPort is a option for Start that lets the caller control the port
|
||||||
// allocation. The returnFunc parameter is used when the provider is stopped to
|
// allocation. The returnFunc parameter is used when the provider is stopped to
|
||||||
// return the port in whatever bookkeeping system the caller wants to use.
|
// return the port in whatever bookkeeping system the caller wants to use.
|
||||||
func WithPort(port int, returnFunc func()) startOption {
|
func WithPort(port int) startOption {
|
||||||
return startOption{
|
return startOption{port: port}
|
||||||
port: port,
|
}
|
||||||
returnFunc: returnFunc,
|
|
||||||
}
|
type TestingT interface {
|
||||||
|
require.TestingT
|
||||||
|
Helper()
|
||||||
|
Cleanup(func())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start creates a disposable Server. If the port provided is
|
// Start creates a disposable Server. If the port provided is
|
||||||
// zero it will bind to a random free port, otherwise the provided port is
|
// zero it will bind to a random free port, otherwise the provided port is
|
||||||
// used.
|
// used.
|
||||||
func Start(t testing.T, options ...startOption) *Server {
|
func Start(t TestingT, options ...startOption) *Server {
|
||||||
|
t.Helper()
|
||||||
s := &Server{
|
s := &Server{
|
||||||
allowedRedirectURIs: []string{
|
allowedRedirectURIs: []string{
|
||||||
"https://example.com",
|
"https://example.com",
|
||||||
@ -89,23 +91,16 @@ func Start(t testing.T, options ...startOption) *Server {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
s.jwks = jwks
|
s.jwks = jwks
|
||||||
|
|
||||||
var (
|
var port int
|
||||||
port int
|
|
||||||
returnFunc func()
|
|
||||||
)
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if option.port > 0 {
|
if option.port > 0 {
|
||||||
port = option.port
|
port = option.port
|
||||||
returnFunc = option.returnFunc
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.httpServer = httptestNewUnstartedServerWithPort(s, port)
|
s.httpServer = httptestNewUnstartedServerWithPort(s, port)
|
||||||
s.httpServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
|
s.httpServer.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
|
||||||
s.httpServer.StartTLS()
|
s.httpServer.StartTLS()
|
||||||
if returnFunc != nil {
|
|
||||||
t.Cleanup(returnFunc)
|
|
||||||
}
|
|
||||||
t.Cleanup(s.httpServer.Close)
|
t.Cleanup(s.httpServer.Close)
|
||||||
|
|
||||||
cert := s.httpServer.Certificate()
|
cert := s.httpServer.Certificate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user