Skip to content

Commit ee58e6b

Browse files
authored
Merge pull request #480 from docker/plugins/credentialhelper/context
chore: return context error on credential helper plugin
2 parents 65f48bf + 04214e8 commit ee58e6b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

plugins/credentialhelper/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (s *credentialHelperStore) GetSecrets(_ context.Context, pattern plugin.Pat
129129

130130
func (s *credentialHelperStore) Run(ctx context.Context) error {
131131
<-ctx.Done()
132-
return nil
132+
return ctx.Err()
133133
}
134134

135135
var _ plugin.Plugin = &credentialHelperStore{}

plugins/credentialhelper/store_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package credentialhelper
1616

1717
import (
18+
"context"
1819
"encoding/json"
1920
"errors"
2021
"fmt"
@@ -219,6 +220,32 @@ func TestCredentialHelper(t *testing.T) {
219220
})
220221
}
221222

223+
func TestRun(t *testing.T) {
224+
t.Run("returns context cancelled when context is cancelled", func(t *testing.T) {
225+
c, err := New(testhelper.TestLogger(t),
226+
WithShellProgramFunc(func(args ...string) client.Program {
227+
return &mockCredentialHelper{
228+
t: t,
229+
operation: args[0],
230+
store: map[string]credentials.Credentials{},
231+
}
232+
}),
233+
)
234+
require.NoError(t, err)
235+
236+
ctx, cancel := context.WithCancel(t.Context())
237+
238+
done := make(chan error, 1)
239+
go func() {
240+
done <- c.Run(ctx)
241+
}()
242+
243+
cancel()
244+
245+
require.ErrorIs(t, <-done, context.Canceled)
246+
})
247+
}
248+
222249
func TestDefaultKeyRewriter(t *testing.T) {
223250
for _, tc := range []struct {
224251
desc string

0 commit comments

Comments
 (0)