Skip to content

Commit

Permalink
fix: Update types for TestAuthServerConfig (#49425)
Browse files Browse the repository at this point in the history
* Allow accepting a RealClock instead of only a FakeClock.
  • Loading branch information
kiosion authored Nov 26, 2024
1 parent 9b6e82a commit bbc5cfb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/auth/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type TestAuthServerConfig struct {
// CipherSuites is the list of ciphers that the server supports.
CipherSuites []uint16
// Clock is used to control time in tests.
Clock clockwork.FakeClock
Clock clockwork.Clock
// ClusterNetworkingConfig allows a test to change the default
// networking configuration.
ClusterNetworkingConfig types.ClusterNetworkingConfig
Expand Down
21 changes: 16 additions & 5 deletions lib/auth/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,9 @@ func TestAutoRotation(t *testing.T) {
t.Parallel()

ctx := context.Background()
testSrv := newTestTLSServer(t)
clock := testSrv.AuthServer.TestAuthServerConfig.Clock
clock := clockwork.NewFakeClock()
testSrv := newTestTLSServer(t, withClock(clock))

var ok bool

// create proxy client
Expand Down Expand Up @@ -514,8 +515,8 @@ func TestAutoFallback(t *testing.T) {
t.Parallel()

ctx := context.Background()
testSrv := newTestTLSServer(t)
clock := testSrv.AuthServer.TestAuthServerConfig.Clock
clock := clockwork.NewFakeClock()
testSrv := newTestTLSServer(t, withClock(clock))

var ok bool

Expand Down Expand Up @@ -5001,6 +5002,7 @@ func verifyJWTAWSOIDC(clock clockwork.Clock, clusterName string, pairs []*types.
type testTLSServerOptions struct {
cacheEnabled bool
accessGraph *AccessGraphConfig
clock clockwork.Clock
}

type testTLSServerOption func(*testTLSServerOptions)
Expand All @@ -5017,6 +5019,12 @@ func withAccessGraphConfig(cfg AccessGraphConfig) testTLSServerOption {
}
}

func withClock(clock clockwork.Clock) testTLSServerOption {
return func(options *testTLSServerOptions) {
options.clock = clock
}
}

// newTestTLSServer is a helper that returns a *TestTLSServer with sensible
// defaults for most tests that are exercising Auth Service RPCs.
//
Expand All @@ -5027,9 +5035,12 @@ func newTestTLSServer(t testing.TB, opts ...testTLSServerOption) *TestTLSServer
for _, opt := range opts {
opt(&options)
}
if options.clock == nil {
options.clock = clockwork.NewFakeClockAt(time.Now().Round(time.Second).UTC())
}
as, err := NewTestAuthServer(TestAuthServerConfig{
Dir: t.TempDir(),
Clock: clockwork.NewFakeClockAt(time.Now().Round(time.Second).UTC()),
Clock: options.clock,
CacheEnabled: options.cacheEnabled,
})
require.NoError(t, err)
Expand Down

0 comments on commit bbc5cfb

Please sign in to comment.