(t *testing.T)
| 282 | } |
| 283 | |
| 284 | func 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 | |
| 325 | func TestGetAllCredentialsFileStoreAndCredHelper(t *testing.T) { |
| 326 | const ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…