MCPcopy Create free account
hub / github.com/docker/cli / TestGetAllCredentialsCredHelper

Function TestGetAllCredentialsCredHelper

cli/config/configfile/file_test.go:284–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

282}
283
284func TestGetAllCredentialsCredHelper(t *testing.T) {
285 const (
286 testCredHelperSuffix = "test_cred_helper"
287 testCredHelperRegistryHostname = "credhelper.com"
288 testExtraCredHelperRegistryHostname = "somethingweird.com"
289 )
290
291 unexpectedCredHelperAuth := types.AuthConfig{
292 Username: "file_store_user",
293 Password: "file_store_pass",
294 }
295 expectedCredHelperAuth := types.AuthConfig{
296 Username: "cred_helper_user",
297 Password: "cred_helper_pass",
298 }
299
300 configFile := New("filename")
301 configFile.CredentialHelpers = map[string]string{testCredHelperRegistryHostname: testCredHelperSuffix}
302
303 testCredHelper := NewMockNativeStore(map[string]types.AuthConfig{
304 testCredHelperRegistryHostname: expectedCredHelperAuth,
305 // Add in an extra auth entry which doesn't appear in CredentialHelpers section of the configFile.
306 // This verifies that only explicitly configured registries are being requested from the cred helpers.
307 testExtraCredHelperRegistryHostname: unexpectedCredHelperAuth,
308 }, nil)
309
310 tmpNewNativeStore := newNativeStore
311 defer func() { newNativeStore = tmpNewNativeStore }()
312 newNativeStore = func(configFile *ConfigFile, helperSuffix string) credentials.Store {
313 return testCredHelper
314 }
315
316 authConfigs, err := configFile.GetAllCredentials()
317 assert.NilError(t, err)
318
319 expected := make(map[string]types.AuthConfig)
320 expected[testCredHelperRegistryHostname] = expectedCredHelperAuth
321 assert.Check(t, is.DeepEqual(expected, authConfigs))
322 assert.Check(t, is.Equal(0, testCredHelper.(*mockNativeStore).GetAllCallCount))
323}
324
325func TestGetAllCredentialsFileStoreAndCredHelper(t *testing.T) {
326 const (

Callers

nothing calls this directly

Calls 3

NewMockNativeStoreFunction · 0.85
GetAllCredentialsMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…