From 50218ada96f39d380cac12c69aef8ac90d95674e Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:59:05 +0100 Subject: [PATCH 1/3] registry: authorize with Secrets Engine before reading the Docker Desktop session Docker Desktop can prompt the user before it gives a process access to a realm, and reading the default Docker Hub session reads from two realms, docker/auth/metadata/hub/** and docker/auth/hub/**. The 5 second lookup timeout expired before the user could answer, so the lookup fell back to the Docker CLI credentials. Call Authorize once on docker/auth/**, which covers the production and staging realms, with a one minute timeout, and keep the decision until the expiry Docker Desktop returns. The session reads keep their 5 second timeout. A denied or unanswered authorization falls back to the Docker CLI credentials like any other failed lookup. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- internal/registry/desktop.go | 78 +++++++++++++----- internal/registry/desktop_test.go | 127 +++++++++++++++++++++++++++--- 2 files changed, 176 insertions(+), 29 deletions(-) diff --git a/internal/registry/desktop.go b/internal/registry/desktop.go index 5cd26dfe7f..6a8d396b59 100644 --- a/internal/registry/desktop.go +++ b/internal/registry/desktop.go @@ -26,16 +26,19 @@ import ( clitypes "github.com/docker/cli/cli/config/types" seclient "github.com/docker/secrets-engine/client" + "github.com/docker/secrets-engine/client/api/resolver" "github.com/docker/secrets-engine/client/config" "github.com/docker/secrets-engine/client/dockerhub" + "github.com/docker/secrets-engine/secrets" "github.com/sirupsen/logrus" ) const ( // desktopLookupTimeout limits connection time in case of hanging or // unexpected request delay by the secrets engine. - desktopLookupTimeout = 5 * time.Second - sessionExpirySkew = 30 * time.Second + desktopLookupTimeout = 5 * time.Second + desktopAuthorizeTimeout = time.Minute + sessionExpirySkew = 30 * time.Second // sessionTTL is how long a session without an expiry claim is reused. sessionTTL = time.Minute // retryInterval is how long Desktop is not asked again after a failed lookup. @@ -48,11 +51,23 @@ var ( ) type hubSessions interface { + Authorize(ctx context.Context) (seclient.AuthorizeResponse, error) GetDefaultSession(ctx context.Context) (dockerhub.UserSession, error) GetDefaultProfile(ctx context.Context) (dockerhub.Profile, error) } -var _ hubSessions = dockerhub.ClientAuth(nil) +var dockerAuthRealm = secrets.MustParsePattern("docker/auth/**") + +type desktopHub struct { + dockerhub.ClientAuth + authorizer resolver.Authorizer +} + +func (h desktopHub) Authorize(ctx context.Context) (seclient.AuthorizeResponse, error) { + return h.authorizer.Authorize(ctx, dockerAuthRealm) +} + +var _ hubSessions = desktopHub{} var ( sharedHubSession = newDesktopSession("Docker Hub", IndexServer) @@ -66,8 +81,9 @@ func newDesktopSession(name, serverAddress string, opts ...dockerhub.Option) *de connect: func() (hubSessions, error) { return connectDesktop(opts...) }, - timeout: desktopLookupTimeout, - now: time.Now, + timeout: desktopLookupTimeout, + authorizeTimeout: desktopAuthorizeTimeout, + now: time.Now, } } @@ -82,14 +98,11 @@ func NewDesktopAuthProvider(fallback AuthProvider) AuthProvider { } func connectDesktop(opts ...dockerhub.Option) (hubSessions, error) { - c, err := seclient.New( - seclient.WithSocketPath(config.DesktopSocketPath()), - seclient.WithTimeout(desktopLookupTimeout), - ) + c, err := seclient.New(seclient.WithSocketPath(config.DesktopSocketPath())) if err != nil { return nil, err } - return c.HubAuth(opts...), nil + return desktopHub{ClientAuth: c.HubAuth(opts...), authorizer: c}, nil } type desktopAuthProvider struct { @@ -129,18 +142,39 @@ func registryHost(registryHostname string) string { // desktopSession caches the Desktop session of one Docker Hub environment. type desktopSession struct { - name string - serverAddress string - connect func() (hubSessions, error) - timeout time.Duration - now func() time.Time + name string + serverAddress string + connect func() (hubSessions, error) + timeout time.Duration + authorizeTimeout time.Duration + now func() time.Time // mu serializes lookups so concurrent pulls share one request. - mu sync.Mutex - hub hubSessions - retryAt time.Time - cached *clitypes.AuthConfig - validUntil time.Time + mu sync.Mutex + hub hubSessions + authorized bool + authorizedUntil time.Time + retryAt time.Time + cached *clitypes.AuthConfig + validUntil time.Time +} + +func (s *desktopSession) authorize() error { + if s.authorized && (s.authorizedUntil.IsZero() || s.now().Before(s.authorizedUntil)) { + return nil + } + ctx, cancel := context.WithTimeout(context.Background(), s.authorizeTimeout) + defer cancel() + + resp, err := s.hub.Authorize(ctx) + if err != nil { + return fmt.Errorf("authorizing access to the session: %w", err) + } + if !resp.Allow { + return secrets.ErrAccessDenied + } + s.authorized, s.authorizedUntil = true, resp.Expiry + return nil } func (s *desktopSession) auth() (clitypes.AuthConfig, bool) { @@ -175,6 +209,10 @@ func (s *desktopSession) fetch() (clitypes.AuthConfig, time.Time, error) { s.hub = hub } + if err := s.authorize(); err != nil { + return clitypes.AuthConfig{}, time.Time{}, err + } + ctx, cancel := context.WithTimeout(context.Background(), s.timeout) defer cancel() diff --git a/internal/registry/desktop_test.go b/internal/registry/desktop_test.go index 731ad3643b..0bc3d20fe0 100644 --- a/internal/registry/desktop_test.go +++ b/internal/registry/desktop_test.go @@ -29,6 +29,7 @@ import ( clitypes "github.com/docker/cli/cli/config/types" seclient "github.com/docker/secrets-engine/client" "github.com/docker/secrets-engine/client/dockerhub" + "github.com/docker/secrets-engine/client/realms" "github.com/docker/secrets-engine/secrets" "github.com/moby/moby/api/pkg/authconfig" "gotest.tools/v3/assert" @@ -37,11 +38,23 @@ import ( var testNow = time.Date(2026, 10, 7, 12, 0, 0, 0, time.UTC) type fakeHub struct { - session dockerhub.UserSession - sessionErr error - profile dockerhub.Profile - profileErr error - sessionCalls atomic.Int32 + session dockerhub.UserSession + sessionErr error + profile dockerhub.Profile + profileErr error + denied bool + authorizeErr error + authExpiry time.Time + sessionCalls atomic.Int32 + authorizeCalls atomic.Int32 +} + +func (f *fakeHub) Authorize(context.Context) (seclient.AuthorizeResponse, error) { + f.authorizeCalls.Add(1) + if f.authorizeErr != nil { + return seclient.AuthorizeResponse{}, f.authorizeErr + } + return seclient.AuthorizeResponse{Allow: !f.denied, Expiry: f.authExpiry}, nil } func (f *fakeHub) GetDefaultSession(context.Context) (dockerhub.UserSession, error) { @@ -125,8 +138,9 @@ func newTestProvider(hub hubSessions, connectErr error) *testProvider { } return hub, nil }, - timeout: time.Second, - now: tp.clock.now, + timeout: time.Second, + authorizeTimeout: time.Second, + now: tp.clock.now, }, stagingHub: &desktopSession{ name: "Docker Hub staging", @@ -134,8 +148,9 @@ func newTestProvider(hub hubSessions, connectErr error) *testProvider { connect: func() (hubSessions, error) { return tp.staging, nil }, - timeout: time.Second, - now: tp.clock.now, + timeout: time.Second, + authorizeTimeout: time.Second, + now: tp.clock.now, }, } return tp @@ -411,6 +426,100 @@ func connectError(reason seclient.ConnectReason) error { } } +type recordingAuthorizer struct { + patterns []secrets.Pattern +} + +func (a *recordingAuthorizer) Authorize(_ context.Context, patterns ...secrets.Pattern) (seclient.AuthorizeResponse, error) { + a.patterns = append(a.patterns, patterns...) + return seclient.AuthorizeResponse{Allow: true}, nil +} + +func TestDesktopHub_AuthorizesDockerAuthRealm(t *testing.T) { + a := &recordingAuthorizer{} + resp, err := desktopHub{authorizer: a}.Authorize(t.Context()) + assert.NilError(t, err) + assert.Assert(t, resp.Allow) + assert.Equal(t, len(a.patterns), 1) + assert.Equal(t, a.patterns[0].String(), "docker/auth/**") + for _, realm := range []secrets.Pattern{ + realms.DockerHubAuthentication, + realms.DockerHubAuthenticationMetadata, + realms.DockerHubStagingAuthentication, + realms.DockerHubStagingAuthenticationMetadata, + } { + assert.Assert(t, a.patterns[0].Contains(realm), "docker/auth/** must cover %s", realm) + } +} + +func TestDesktopAuthProvider_AuthorizesOnceBeforeReadingSessions(t *testing.T) { + hub := &fakeHub{session: hubSession("hubuser", time.Time{})} + p := newTestProvider(hub, nil) + + for range 3 { + got, err := p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.DeepEqual(t, got, desktopCredentials()) + p.clock.advance(sessionTTL) + } + assert.Equal(t, hub.sessionCalls.Load(), int32(3)) + assert.Equal(t, hub.authorizeCalls.Load(), int32(1)) +} + +func TestDesktopAuthProvider_AuthorizesAgainAfterDecisionExpires(t *testing.T) { + hub := &fakeHub{ + session: hubSession("hubuser", time.Time{}), + authExpiry: testNow.Add(sessionTTL + time.Second), + } + p := newTestProvider(hub, nil) + + _, err := p.GetAuthConfig("docker.io") + assert.NilError(t, err) + p.clock.advance(sessionTTL) + _, err = p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.Equal(t, hub.authorizeCalls.Load(), int32(1)) + + p.clock.advance(sessionTTL) + _, err = p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.Equal(t, hub.authorizeCalls.Load(), int32(2)) + assert.Equal(t, hub.sessionCalls.Load(), int32(3)) +} + +func TestDesktopAuthProvider_FallsBackWhenNotAuthorized(t *testing.T) { + tests := []struct { + name string + hub *fakeHub + }{ + { + name: "denied", + hub: &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour)), denied: true}, + }, + { + name: "access denied error", + hub: &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour)), authorizeErr: secrets.ErrAccessDenied}, + }, + { + name: "prompt not answered", + hub: &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour)), authorizeErr: context.DeadlineExceeded}, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + p := newTestProvider(tc.hub, nil) + + for range 2 { + got, err := p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.DeepEqual(t, got, cliCredentials("docker.io")) + } + assert.Equal(t, tc.hub.authorizeCalls.Load(), int32(1), "Desktop must not be asked again within retryInterval") + assert.Equal(t, tc.hub.sessionCalls.Load(), int32(0), "the session must not be read without authorization") + }) + } +} + func TestDesktopAuthProvider_ReusesSessionUntilExpiry(t *testing.T) { expiresAt := testNow.Add(10 * time.Minute) hub := &fakeHub{session: hubSession("hubuser", expiresAt)} From 2caab34839c6afc908a5c187894aee7b0ca4a047 Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Mon, 23 Nov 2026 09:03:19 +0100 Subject: [PATCH 2/3] registry: wait for the Docker Desktop prompt only when the secrets engine answers Authorize has a one minute timeout, so the user can answer the Docker Desktop prompt. An engine that accepts the connection but never answers looked the same, and delayed the first Docker Hub lookup by a minute. Ask the engine for its version first, within the 5 second lookup timeout, and only then call Authorize. The secrets engine API has no way to say that it is waiting for the user, but the version request is not gated by a prompt: it answered in about 10 ms from a new process. An engine that does not answer now falls back after 5 seconds, as before. A version request that times out returned only the RPC deadline error, which was logged as a warning. Report it as a ConnectError with ReasonTimeout and the socket path, so it reads as the secrets engine not responding and is logged at debug level, like a socket that is missing or refuses the connection. A timeout on the prompt or on the session reads is still logged as a warning. Clear an expired decision before authorizing again, so a failed authorization does not leave the old one in place. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- internal/registry/desktop.go | 38 ++++++++++-- internal/registry/desktop_test.go | 100 ++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 10 deletions(-) diff --git a/internal/registry/desktop.go b/internal/registry/desktop.go index 6a8d396b59..0d408adbbc 100644 --- a/internal/registry/desktop.go +++ b/internal/registry/desktop.go @@ -51,6 +51,7 @@ var ( ) type hubSessions interface { + Ping(ctx context.Context) error Authorize(ctx context.Context) (seclient.AuthorizeResponse, error) GetDefaultSession(ctx context.Context) (dockerhub.UserSession, error) GetDefaultProfile(ctx context.Context) (dockerhub.Profile, error) @@ -58,13 +59,33 @@ type hubSessions interface { var dockerAuthRealm = secrets.MustParsePattern("docker/auth/**") +type secretsEngine interface { + resolver.Authorizer + Version(ctx context.Context) (seclient.DaemonVersion, error) +} + type desktopHub struct { dockerhub.ClientAuth - authorizer resolver.Authorizer + engine secretsEngine + socketPath string +} + +func (h desktopHub) Ping(ctx context.Context) error { + _, err := h.engine.Version(ctx) + if err == nil { + return nil + } + if _, ok := errors.AsType[*seclient.ConnectError](err); ok { + return err + } + if errors.Is(err, context.DeadlineExceeded) { + return &seclient.ConnectError{Reason: seclient.ReasonTimeout, SocketPath: h.socketPath, Err: err} + } + return err } func (h desktopHub) Authorize(ctx context.Context) (seclient.AuthorizeResponse, error) { - return h.authorizer.Authorize(ctx, dockerAuthRealm) + return h.engine.Authorize(ctx, dockerAuthRealm) } var _ hubSessions = desktopHub{} @@ -98,11 +119,12 @@ func NewDesktopAuthProvider(fallback AuthProvider) AuthProvider { } func connectDesktop(opts ...dockerhub.Option) (hubSessions, error) { - c, err := seclient.New(seclient.WithSocketPath(config.DesktopSocketPath())) + socketPath := config.DesktopSocketPath() + c, err := seclient.New(seclient.WithSocketPath(socketPath)) if err != nil { return nil, err } - return desktopHub{ClientAuth: c.HubAuth(opts...), authorizer: c}, nil + return desktopHub{ClientAuth: c.HubAuth(opts...), engine: c, socketPath: socketPath}, nil } type desktopAuthProvider struct { @@ -163,6 +185,14 @@ func (s *desktopSession) authorize() error { if s.authorized && (s.authorizedUntil.IsZero() || s.now().Before(s.authorizedUntil)) { return nil } + s.authorized, s.authorizedUntil = false, time.Time{} + pingCtx, cancelPing := context.WithTimeout(context.Background(), s.timeout) + err := s.hub.Ping(pingCtx) + cancelPing() + if err != nil { + return fmt.Errorf("checking the secrets engine: %w", err) + } + ctx, cancel := context.WithTimeout(context.Background(), s.authorizeTimeout) defer cancel() diff --git a/internal/registry/desktop_test.go b/internal/registry/desktop_test.go index 0bc3d20fe0..773e6cb9a1 100644 --- a/internal/registry/desktop_test.go +++ b/internal/registry/desktop_test.go @@ -45,12 +45,32 @@ type fakeHub struct { denied bool authorizeErr error authExpiry time.Time + pingErr error sessionCalls atomic.Int32 authorizeCalls atomic.Int32 + pingCalls atomic.Int32 + + pingBudget time.Duration + authorizeBudget time.Duration } -func (f *fakeHub) Authorize(context.Context) (seclient.AuthorizeResponse, error) { +func budget(ctx context.Context) time.Duration { + deadline, ok := ctx.Deadline() + if !ok { + return 0 + } + return time.Until(deadline) +} + +func (f *fakeHub) Ping(ctx context.Context) error { + f.pingCalls.Add(1) + f.pingBudget = budget(ctx) + return f.pingErr +} + +func (f *fakeHub) Authorize(ctx context.Context) (seclient.AuthorizeResponse, error) { f.authorizeCalls.Add(1) + f.authorizeBudget = budget(ctx) if f.authorizeErr != nil { return seclient.AuthorizeResponse{}, f.authorizeErr } @@ -426,18 +446,50 @@ func connectError(reason seclient.ConnectReason) error { } } -type recordingAuthorizer struct { - patterns []secrets.Pattern +type recordingEngine struct { + patterns []secrets.Pattern + versionErr error + versionCall int } -func (a *recordingAuthorizer) Authorize(_ context.Context, patterns ...secrets.Pattern) (seclient.AuthorizeResponse, error) { +func (a *recordingEngine) Authorize(_ context.Context, patterns ...secrets.Pattern) (seclient.AuthorizeResponse, error) { a.patterns = append(a.patterns, patterns...) return seclient.AuthorizeResponse{Allow: true}, nil } +func (a *recordingEngine) Version(context.Context) (seclient.DaemonVersion, error) { + a.versionCall++ + return seclient.DaemonVersion{}, a.versionErr +} + +func TestDesktopHub_PingAsksForTheVersion(t *testing.T) { + e := &recordingEngine{} + assert.NilError(t, desktopHub{engine: e}.Ping(t.Context())) + assert.Equal(t, e.versionCall, 1) + + e.versionErr = connectError(seclient.ReasonNotRunning) + assert.ErrorIs(t, desktopHub{engine: e}.Ping(t.Context()), seclient.ErrSecretsEngineNotRunning) +} + +func TestDesktopHub_PingReportsATimeoutAsTheEngineNotResponding(t *testing.T) { + e := &recordingEngine{versionErr: fmt.Errorf("deadline_exceeded: %w", context.DeadlineExceeded)} + err := desktopHub{engine: e, socketPath: "/run/engine.sock"}.Ping(t.Context()) + + assert.ErrorIs(t, err, seclient.ErrSecretsEngineTimeout) + assert.ErrorIs(t, err, context.DeadlineExceeded) + assert.ErrorContains(t, err, "secrets engine did not respond in time at /run/engine.sock") + assert.Assert(t, isSessionUnavailable(err), err) +} + +func TestDesktopHub_PingKeepsOtherErrors(t *testing.T) { + boom := errors.New("boom") + e := &recordingEngine{versionErr: boom} + assert.Equal(t, desktopHub{engine: e}.Ping(t.Context()), boom) +} + func TestDesktopHub_AuthorizesDockerAuthRealm(t *testing.T) { - a := &recordingAuthorizer{} - resp, err := desktopHub{authorizer: a}.Authorize(t.Context()) + a := &recordingEngine{} + resp, err := desktopHub{engine: a}.Authorize(t.Context()) assert.NilError(t, err) assert.Assert(t, resp.Allow) assert.Equal(t, len(a.patterns), 1) @@ -464,6 +516,41 @@ func TestDesktopAuthProvider_AuthorizesOnceBeforeReadingSessions(t *testing.T) { } assert.Equal(t, hub.sessionCalls.Load(), int32(3)) assert.Equal(t, hub.authorizeCalls.Load(), int32(1)) + assert.Equal(t, hub.pingCalls.Load(), int32(1)) +} + +func TestDesktopAuthProvider_WaitsForThePromptOnlyAfterTheEngineAnswers(t *testing.T) { + hub := &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour))} + p := newTestProvider(hub, nil) + p.hub.timeout = 5 * time.Second + p.hub.authorizeTimeout = time.Minute + + got, err := p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.DeepEqual(t, got, desktopCredentials()) + assert.Assert(t, hub.pingBudget > 0 && hub.pingBudget <= 5*time.Second, "ping budget %s", hub.pingBudget) + assert.Assert(t, hub.authorizeBudget > 5*time.Second, "authorize budget %s", hub.authorizeBudget) +} + +func TestDesktopAuthProvider_FallsBackWhenTheEngineDoesNotAnswer(t *testing.T) { + for name, pingErr := range map[string]error{ + "not running": connectError(seclient.ReasonNotRunning), + "does not answer": connectError(seclient.ReasonTimeout), + } { + t.Run(name, func(t *testing.T) { + hub := &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour)), pingErr: pingErr} + p := newTestProvider(hub, nil) + + for range 2 { + got, err := p.GetAuthConfig("docker.io") + assert.NilError(t, err) + assert.DeepEqual(t, got, cliCredentials("docker.io")) + } + assert.Equal(t, hub.pingCalls.Load(), int32(1), "Desktop must not be asked again within retryInterval") + assert.Equal(t, hub.authorizeCalls.Load(), int32(0), "authorization must not wait on an engine that does not answer") + assert.Equal(t, hub.sessionCalls.Load(), int32(0)) + }) + } } func TestDesktopAuthProvider_AuthorizesAgainAfterDecisionExpires(t *testing.T) { @@ -514,6 +601,7 @@ func TestDesktopAuthProvider_FallsBackWhenNotAuthorized(t *testing.T) { assert.NilError(t, err) assert.DeepEqual(t, got, cliCredentials("docker.io")) } + assert.Equal(t, tc.hub.pingCalls.Load(), int32(1), "Desktop must not be asked again within retryInterval") assert.Equal(t, tc.hub.authorizeCalls.Load(), int32(1), "Desktop must not be asked again within retryInterval") assert.Equal(t, tc.hub.sessionCalls.Load(), int32(0), "the session must not be read without authorization") }) From c5d33a9d1208d11c8d510faf17babe61a304c409 Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Mon, 23 Nov 2026 09:07:54 +0100 Subject: [PATCH 3/3] registry: give the secrets engine version check 1 second The version request that comes before Authorize is not gated by a prompt and answered in about 10 ms from Docker Desktop, so it does not need the 5 second lookup timeout. With 1 second, an engine that accepts the connection but does not answer falls back to the Docker CLI credentials after 1 second instead of 5. The session reads keep 5 seconds and Authorize keeps 1 minute. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- internal/registry/desktop.go | 5 ++++- internal/registry/desktop_test.go | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/registry/desktop.go b/internal/registry/desktop.go index 0d408adbbc..e7d90b78e5 100644 --- a/internal/registry/desktop.go +++ b/internal/registry/desktop.go @@ -37,6 +37,7 @@ const ( // desktopLookupTimeout limits connection time in case of hanging or // unexpected request delay by the secrets engine. desktopLookupTimeout = 5 * time.Second + desktopPingTimeout = time.Second desktopAuthorizeTimeout = time.Minute sessionExpirySkew = 30 * time.Second // sessionTTL is how long a session without an expiry claim is reused. @@ -103,6 +104,7 @@ func newDesktopSession(name, serverAddress string, opts ...dockerhub.Option) *de return connectDesktop(opts...) }, timeout: desktopLookupTimeout, + pingTimeout: desktopPingTimeout, authorizeTimeout: desktopAuthorizeTimeout, now: time.Now, } @@ -168,6 +170,7 @@ type desktopSession struct { serverAddress string connect func() (hubSessions, error) timeout time.Duration + pingTimeout time.Duration authorizeTimeout time.Duration now func() time.Time @@ -186,7 +189,7 @@ func (s *desktopSession) authorize() error { return nil } s.authorized, s.authorizedUntil = false, time.Time{} - pingCtx, cancelPing := context.WithTimeout(context.Background(), s.timeout) + pingCtx, cancelPing := context.WithTimeout(context.Background(), s.pingTimeout) err := s.hub.Ping(pingCtx) cancelPing() if err != nil { diff --git a/internal/registry/desktop_test.go b/internal/registry/desktop_test.go index 773e6cb9a1..8adfbf1a6d 100644 --- a/internal/registry/desktop_test.go +++ b/internal/registry/desktop_test.go @@ -159,6 +159,7 @@ func newTestProvider(hub hubSessions, connectErr error) *testProvider { return hub, nil }, timeout: time.Second, + pingTimeout: time.Second, authorizeTimeout: time.Second, now: tp.clock.now, }, @@ -169,6 +170,7 @@ func newTestProvider(hub hubSessions, connectErr error) *testProvider { return tp.staging, nil }, timeout: time.Second, + pingTimeout: time.Second, authorizeTimeout: time.Second, now: tp.clock.now, }, @@ -196,6 +198,11 @@ func TestNewDesktopAuthProvider_SharesOneSessionPerEnvironment(t *testing.T) { assert.Assert(t, a.hub != a.stagingHub, "production and staging sessions must be separate") assert.Equal(t, a.hub.serverAddress, IndexServer) assert.Equal(t, a.stagingHub.serverAddress, StagingIndexServer) + for _, s := range []*desktopSession{a.hub, a.stagingHub} { + assert.Equal(t, s.pingTimeout, time.Second) + assert.Equal(t, s.timeout, 5*time.Second) + assert.Equal(t, s.authorizeTimeout, time.Minute) + } } func TestDesktopAuthProvider_ProvidersOnOneSessionFetchOnce(t *testing.T) { @@ -523,12 +530,13 @@ func TestDesktopAuthProvider_WaitsForThePromptOnlyAfterTheEngineAnswers(t *testi hub := &fakeHub{session: hubSession("hubuser", testNow.Add(time.Hour))} p := newTestProvider(hub, nil) p.hub.timeout = 5 * time.Second + p.hub.pingTimeout = time.Second p.hub.authorizeTimeout = time.Minute got, err := p.GetAuthConfig("docker.io") assert.NilError(t, err) assert.DeepEqual(t, got, desktopCredentials()) - assert.Assert(t, hub.pingBudget > 0 && hub.pingBudget <= 5*time.Second, "ping budget %s", hub.pingBudget) + assert.Assert(t, hub.pingBudget > 0 && hub.pingBudget <= time.Second, "ping budget %s", hub.pingBudget) assert.Assert(t, hub.authorizeBudget > 5*time.Second, "authorize budget %s", hub.authorizeBudget) }