Skip to content

Commit 3a16520

Browse files
jhrozekclaude
andcommitted
Fix TLS listener tests failing the DCR store check
closeTrackingStorage embedded the storage.Storage interface, which hides the DCR methods. The constructor asserts DCRCredentialStore before it loads the TLS certificate, so the TLS listener tests failed on the DCR check instead of the behavior they cover. Embed *storage.MemoryStorage so the wrapper satisfies the interface. Also assert the certificate load error in the cleanup test, which only checked for any error and passed for the wrong reason. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 8318037 commit 3a16520

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

‎pkg/authserver/runner/embeddedauthserver_test.go‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,8 +1996,8 @@ func TestNewEmbeddedAuthServerWithStorage_RequiredInputs(t *testing.T) {
19961996
t.Run("nil config returns error without panic or cleanup", func(t *testing.T) {
19971997
t.Parallel()
19981998

1999-
tracker := &closeTrackingStorage{Storage: storage.NewMemoryStorage()}
2000-
t.Cleanup(func() { require.NoError(t, tracker.Storage.Close()) })
1999+
tracker := &closeTrackingStorage{MemoryStorage: storage.NewMemoryStorage()}
2000+
t.Cleanup(func() { require.NoError(t, tracker.MemoryStorage.Close()) })
20012001

20022002
server, err := NewEmbeddedAuthServerWithStorage(context.Background(), nil, tracker)
20032003
require.Nil(t, server)
@@ -2712,21 +2712,22 @@ func TestNewEmbeddedAuthServer_DCRBoot(t *testing.T) {
27122712
}
27132713

27142714
// closeTrackingStorage wraps an authserver storage and counts Close calls.
2715-
// It implements storage.Storage by embedding the wrapped value, then
2716-
// overriding Close to record the call before delegating to the inner
2717-
// Storage. Used by TestNewEmbeddedAuthServer_ClosesStorageOnError to
2715+
// It embeds *storage.MemoryStorage (not the storage.Storage interface) so it
2716+
// also satisfies storage.DCRCredentialStore, and overrides Close to record
2717+
// the call before delegating to the inner storage. Used by
2718+
// TestNewEmbeddedAuthServer_ClosesStorageOnError to
27182719
// verify the deferred-cleanup contract on NewEmbeddedAuthServer's error
27192720
// paths without depending on goroutine-count heuristics (which are
27202721
// confounded by HTTP transport keep-alive goroutines this package does
27212722
// not own).
27222723
type closeTrackingStorage struct {
2723-
storage.Storage
2724+
*storage.MemoryStorage
27242725
closeCount atomic.Int32
27252726
}
27262727

27272728
func (s *closeTrackingStorage) Close() error {
27282729
s.closeCount.Add(1)
2729-
return s.Storage.Close()
2730+
return s.MemoryStorage.Close()
27302731
}
27312732

27322733
// TestNewEmbeddedAuthServer_ClosesStorageOnError pins the post-#5185
@@ -2752,7 +2753,7 @@ func (s *closeTrackingStorage) Close() error {
27522753
func TestNewEmbeddedAuthServer_ClosesStorageOnError(t *testing.T) {
27532754
t.Parallel()
27542755

2755-
tracker := &closeTrackingStorage{Storage: storage.NewMemoryStorage()}
2756+
tracker := &closeTrackingStorage{MemoryStorage: storage.NewMemoryStorage()}
27562757

27572758
// Always-500 discovery endpoint forces the DCR resolver to fail
27582759
// during buildUpstreamConfigs — i.e. inside the leak window between
@@ -2804,7 +2805,7 @@ func TestNewEmbeddedAuthServer_ClosesStorageOnError(t *testing.T) {
28042805
func TestNewEmbeddedAuthServer_TLSListenerClosesStorageOnError(t *testing.T) {
28052806
t.Parallel()
28062807

2807-
tracker := &closeTrackingStorage{Storage: storage.NewMemoryStorage()}
2808+
tracker := &closeTrackingStorage{MemoryStorage: storage.NewMemoryStorage()}
28082809

28092810
cfg := &authserver.RunConfig{
28102811
SchemaVersion: authserver.CurrentSchemaVersion,
@@ -2830,6 +2831,7 @@ func TestNewEmbeddedAuthServer_TLSListenerClosesStorageOnError(t *testing.T) {
28302831

28312832
embed, err := NewEmbeddedAuthServerWithStorage(context.Background(), cfg, tracker, WithListenerHost("localhost"))
28322833
require.Error(t, err)
2834+
assert.Contains(t, err.Error(), "load auth server TLS listener certificate")
28332835
assert.Nil(t, embed)
28342836
assert.Equal(t, int32(1), tracker.closeCount.Load(),
28352837
"a TLS listener certificate load failure must Close the storage exactly once via the deferred-cleanup gate")
@@ -2904,7 +2906,7 @@ func TestNewEmbeddedAuthServer_TLSListenerRequiresHost(t *testing.T) {
29042906
if tt.publicConstructor {
29052907
embed, err = NewEmbeddedAuthServer(context.Background(), cfg, opts...)
29062908
} else {
2907-
tracker = &closeTrackingStorage{Storage: storage.NewMemoryStorage()}
2909+
tracker = &closeTrackingStorage{MemoryStorage: storage.NewMemoryStorage()}
29082910
embed, err = NewEmbeddedAuthServerWithStorage(context.Background(), cfg, tracker, opts...)
29092911
}
29102912
assert.Equal(t, 1, optionCalls, "constructor options must be applied once")

0 commit comments

Comments
 (0)