GitLabgitlab-org

cli

main
ply6 git calls325 ms101 KiB4 cachedprotocol v2
636 lines23 KiBRaw
1//go:build !integration
3package dockercredhelper
5import (
6 "encoding/json"
7 "errors"
8 "fmt"
9 "io/fs"
10 "os"
11 "path/filepath"
12 "runtime"
13 "slices"
14 "strings"
15 "syscall"
16 "testing"
18 "github.com/stretchr/testify/assert"
19 "github.com/stretchr/testify/require"
22// writeFakeGlab drops an executable file named "glab" (or "glab.exe" on
23// Windows) into dir, so exec.LookPath("glab") succeeds against a PATH
24// containing dir, without depending on a real glab build.
25func writeFakeGlab(t *testing.T, dir string) {
26 t.Helper()
28 name := "glab"
29 if runtime.GOOS == "windows" {
30 name = "glab.exe"
31 }
32 require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte("#!/bin/sh\n"), 0o755))
35// unwritableGlabDir returns a directory holding a fake glab that the test user
36// cannot write to, standing in for the /usr/bin a .deb or .rpm package
37// installs glab into, and for a read-only store such as Nix's.
38//
39// It skips rather than fakes when the mode cannot be enforced: Windows does
40// not apply POSIX modes, and root bypasses them.
41func unwritableGlabDir(t *testing.T) string {
42 t.Helper()
44 if runtime.GOOS == "windows" {
45 t.Skip("POSIX directory modes not enforced on Windows")
46 }
47 if os.Geteuid() == 0 {
48 t.Skip("root bypasses the directory mode this test relies on")
49 }
51 dir := t.TempDir()
52 writeFakeGlab(t, dir)
53 require.NoError(t, os.Chmod(dir, 0o555))
54 // t.TempDir's own cleanup needs the write bit back to remove the contents.
55 t.Cleanup(func() { _ = os.Chmod(dir, 0o755) })
57 return dir
60// sandboxHome points $HOME at a scratch directory and returns the
61// ~/.local/bin path under it. The directory is deliberately not created:
62// which candidate Install picks must not depend on ~/.local/bin already
63// existing, and one test asserts Install creates it.
64func sandboxHome(t *testing.T) string {
65 t.Helper()
67 home := t.TempDir()
68 t.Setenv("HOME", home)
69 t.Setenv("USERPROFILE", home)
71 return filepath.Join(home, ".local", "bin")
74func TestInstall_WritesExecutableShimNextToGlab(t *testing.T) {
75 binDir := t.TempDir()
76 writeFakeGlab(t, binDir)
77 t.Setenv("PATH", binDir)
79 installed, err := Install()
80 require.NoError(t, err)
81 assert.Equal(t, filepath.Join(binDir, FullName), installed.Path)
82 assert.True(t, installed.OnPath)
84 content, err := os.ReadFile(installed.Path)
85 require.NoError(t, err)
86 assert.Equal(t, "#!/bin/sh -eu\nexec glab auth docker-helper \"$@\"\n", string(content))
88 if runtime.GOOS == "windows" {
89 t.Skip("POSIX file modes not enforced on Windows")
90 }
91 info, err := os.Stat(installed.Path)
92 require.NoError(t, err)
93 assert.Equal(t, os.FileMode(0o700), info.Mode().Perm())
96// TestInstall_ForcesModeOnPreExistingShim covers that re-running Install
97// always brings a stale shim's mode back to 0o700, regardless of whatever
98// mode a previous version of the file was left at.
99func TestInstall_ForcesModeOnPreExistingShim(t *testing.T) {
100 if runtime.GOOS == "windows" {
101 t.Skip("POSIX file modes not enforced on Windows")
102 }
103 binDir := t.TempDir()
104 writeFakeGlab(t, binDir)
105 t.Setenv("PATH", binDir)
107 shimPath := filepath.Join(binDir, FullName)
108 require.NoError(t, os.WriteFile(shimPath, []byte("stale\n"), 0o644))
110 _, err := Install()
111 require.NoError(t, err)
113 info, err := os.Stat(shimPath)
114 require.NoError(t, err)
115 assert.Equal(t, os.FileMode(0o700), info.Mode().Perm())
118// The precedence tests below drive candidates and unusable directly rather
119// than going through Install. Both are pure, so unlike the chmod-based tests
120// further down they run everywhere, including the root CI container where a
121// directory mode cannot make a write fail.
123func TestCandidates_PrefersGlabsDirectoryThenLocalBin(t *testing.T) {
124 localBin := sandboxHome(t)
125 t.Setenv("PATH", "/opt/tools/bin"+string(os.PathListSeparator)+"/usr/bin")
127 got, err := candidates("/usr/bin")
128 require.NoError(t, err)
130 assert.Equal(t, []candidate{
131 {dir: "/usr/bin", onPath: true},
132 {dir: localBin, create: true},
133 {dir: "/opt/tools/bin", onPath: true},
134 }, got)
137// TestCandidates_RanksLocalBinAheadOfMachineWideEntries is the ordering that
138// keeps two users on a shared host from breaking each other: the 0700 shim in
139// a group-writable /usr/local/bin is unusable by everyone but its installer,
140// so an off-PATH ~/.local/bin and a warning is the better outcome.
141func TestCandidates_RanksLocalBinAheadOfMachineWideEntries(t *testing.T) {
142 localBin := sandboxHome(t)
143 t.Setenv("PATH", "/usr/bin"+string(os.PathListSeparator)+"/usr/local/bin")
145 got, err := candidates("/usr/bin")
146 require.NoError(t, err)
148 require.Len(t, got, 3)
149 assert.Equal(t, candidate{dir: localBin, create: true}, got[1])
150 assert.Equal(t, candidate{dir: "/usr/local/bin", onPath: true}, got[2],
151 "a machine-wide PATH entry must rank below the user's own directory")
154// TestCandidates_MarksLocalBinOnPath covers the flag that decides whether the
155// caller warns: the same directory, reachable by Docker, must not warn.
156func TestCandidates_MarksLocalBinOnPath(t *testing.T) {
157 localBin := sandboxHome(t)
158 t.Setenv("PATH", "/usr/bin"+string(os.PathListSeparator)+localBin)
160 got, err := candidates("/usr/bin")
161 require.NoError(t, err)
163 require.Len(t, got, 2)
164 assert.Equal(t, candidate{dir: localBin, onPath: true, create: true}, got[1])
167// TestCandidates_DedupesOnCleanedPaths pins that dedup keys on the cleaned
168// path: a PATH carrying both spellings of one directory must not attempt the
169// same write twice, nor name it twice in the failure.
170func TestCandidates_DedupesOnCleanedPaths(t *testing.T) {
171 sandboxHome(t)
172 t.Setenv("PATH", strings.Join([]string{"/usr/bin", "/usr/bin/", "/usr/./bin"}, string(os.PathListSeparator)))
174 got, err := candidates("/usr/bin")
175 require.NoError(t, err)
177 dirs := make([]string, 0, len(got))
178 for _, c := range got {
179 dirs = append(dirs, c.dir)
180 }
181 assert.Equal(t, 1, slices.Index(dirs, "/usr/bin")+1, "/usr/bin should appear once, first")
182 assert.NotContains(t, dirs, "/usr/bin/")
185// TestCandidates_SkipsRelativePathEntries covers the empty PATH segment, which
186// means the working directory: honoring it would put the shim wherever glab
187// was run from.
188func TestCandidates_SkipsRelativePathEntries(t *testing.T) {
189 sandboxHome(t)
190 t.Setenv("PATH", strings.Join([]string{"/usr/bin", "", "relative/bin", "."}, string(os.PathListSeparator)))
192 got, err := candidates("/usr/bin")
193 require.NoError(t, err)
195 for _, c := range got {
196 assert.True(t, filepath.IsAbs(c.dir), "candidate %q should be absolute", c.dir)
197 }
200// TestCandidates_ReportsAnUnresolvableHomeDirectory covers dropping the
201// ~/.local/bin candidate: the PATH entries still stand, so it is not fatal,
202// but the reason has to reach the caller.
203func TestCandidates_ReportsAnUnresolvableHomeDirectory(t *testing.T) {
204 t.Setenv("HOME", "")
205 t.Setenv("USERPROFILE", "")
206 t.Setenv("PATH", "/usr/bin")
208 got, err := candidates("/usr/bin")
209 require.ErrorContains(t, err, "home directory")
210 assert.Equal(t, []candidate{{dir: "/usr/bin", onPath: true}}, got,
211 "the PATH entry must survive a home-directory failure")
214// TestUnusable_ClassifiesDirectoryFailures guards the fail-fast branch in
215// Install: only an error meaning "this directory will not do" moves on to the
216// next candidate. A full disk would fail identically everywhere, so retrying
217// it down the whole of PATH would bury the real cause.
218func TestUnusable_ClassifiesDirectoryFailures(t *testing.T) {
219 assert.True(t, unusable(fs.ErrPermission))
220 assert.True(t, unusable(syscall.EROFS))
221 assert.True(t, unusable(syscall.ENOTDIR))
222 assert.True(t, unusable(fs.ErrNotExist))
223 assert.True(t, unusable(fmt.Errorf("wrapped: %w", syscall.EACCES)))
225 assert.False(t, unusable(syscall.ENOSPC), "a full disk must fail the install, not skip the directory")
226 assert.False(t, unusable(errors.New("some other failure")))
229// TestPathWarning_NamesTheDirectoryToAdd covers the message both callers
230// print verbatim: it is the user's only pointer to a shim Docker cannot
231// resolve, so it has to name the directory rather than the script's full path.
232func TestPathWarning_NamesTheDirectoryToAdd(t *testing.T) {
233 warning := Installation{Path: "/home/u/.local/bin/" + FullName}.PathWarning()
235 assert.Contains(t, warning, "/home/u/.local/bin")
236 assert.Contains(t, warning, "not on your PATH")
237 assert.NotContains(t, warning, "/home/u/.local/bin/"+FullName,
238 "the directory to add is the remedy, not the file's own path")
241// TestWriteShim_ReportsAnUnusableParent uses the blocker-file trick from
242// internal/oauth2's unwritableDir: a regular file where a parent directory
243// should be makes MkdirAll fail with ENOTDIR, which root cannot bypass, so
244// the create path and its error classification are exercised in CI too.
245func TestWriteShim_ReportsAnUnusableParent(t *testing.T) {
246 blocker := filepath.Join(t.TempDir(), "blocker")
247 require.NoError(t, os.WriteFile(blocker, nil, 0o600))
249 err := writeShim(filepath.Join(blocker, "bin", FullName), true)
250 require.Error(t, err)
251 assert.True(t, unusable(err), "an unusable parent must let Install try the next candidate, got %v", err)
254// assertShim checks that path holds the shim script at an executable mode,
255// so the fallback tests below assert the shim is usable where it landed and
256// not merely that a file exists there.
257func assertShim(t *testing.T, path string) {
258 t.Helper()
260 content, err := os.ReadFile(path)
261 require.NoError(t, err)
262 assert.Equal(t, string(script), string(content))
264 info, err := os.Stat(path)
265 require.NoError(t, err)
266 assert.Equal(t, os.FileMode(0o700), info.Mode().Perm())
269// TestInstall_FallsBackToLocalBinOnPath is the case reported in #8541: glab
270// comes from a package that put it in a root-owned directory, so the shim
271// cannot go next to it and has to land in the user's own bin directory.
272func TestInstall_FallsBackToLocalBinOnPath(t *testing.T) {
273 glabDir := unwritableGlabDir(t)
274 localBin := sandboxHome(t)
275 t.Setenv("PATH", glabDir+string(os.PathListSeparator)+localBin)
277 installed, err := Install()
278 require.NoError(t, err)
279 assert.Equal(t, filepath.Join(localBin, FullName), installed.Path)
280 assert.True(t, installed.OnPath, "~/.local/bin is on PATH here, so no warning is warranted")
281 assertShim(t, installed.Path)
284// TestInstall_PrefersLocalBinOverAnotherWritablePathEntry is the whole
285// install exercising the ordering TestCandidates_RanksLocalBinAheadOfMachineWideEntries
286// pins: a writable PATH entry would work without a warning, and is still not
287// taken, because a 0700 shim in a directory shared with other users breaks
288// both of them.
289func TestInstall_PrefersLocalBinOverAnotherWritablePathEntry(t *testing.T) {
290 glabDir := unwritableGlabDir(t)
291 writableDir := t.TempDir()
292 localBin := sandboxHome(t)
293 t.Setenv("PATH", glabDir+string(os.PathListSeparator)+writableDir)
295 installed, err := Install()
296 require.NoError(t, err)
297 assert.Equal(t, filepath.Join(localBin, FullName), installed.Path)
298 assert.False(t, installed.OnPath, "~/.local/bin is off PATH here, so the caller must warn")
299 assertShim(t, installed.Path)
301 _, statErr := os.Stat(filepath.Join(writableDir, FullName))
302 assert.True(t, os.IsNotExist(statErr), "the shared PATH entry must be left alone")
305// TestInstall_UsesAPathEntryWhenLocalBinIsUnavailable covers the remaining
306// use for the other PATH entries: with no home directory to resolve, a
307// writable PATH entry is all that is left.
308func TestInstall_UsesAPathEntryWhenLocalBinIsUnavailable(t *testing.T) {
309 glabDir := unwritableGlabDir(t)
310 writableDir := t.TempDir()
311 t.Setenv("HOME", "")
312 t.Setenv("USERPROFILE", "")
313 t.Setenv("PATH", glabDir+string(os.PathListSeparator)+writableDir)
315 installed, err := Install()
316 require.NoError(t, err)
317 assert.Equal(t, filepath.Join(writableDir, FullName), installed.Path)
318 assert.True(t, installed.OnPath)
319 assertShim(t, installed.Path)
322// TestInstall_CreatesLocalBinWhenNothingOnPathIsWritable is the last resort:
323// PATH holds nothing this user can write, so the shim goes to the
324// conventional per-user bin directory even though Docker cannot resolve it
325// until the user adds that directory to PATH.
326func TestInstall_CreatesLocalBinWhenNothingOnPathIsWritable(t *testing.T) {
327 glabDir := unwritableGlabDir(t)
328 localBin := sandboxHome(t)
329 t.Setenv("PATH", glabDir)
331 installed, err := Install()
332 require.NoError(t, err)
333 assert.Equal(t, filepath.Join(localBin, FullName), installed.Path)
334 assert.False(t, installed.OnPath, "the caller has to warn: Docker cannot resolve the shim from here")
335 assert.Contains(t, installed.PathWarning(), localBin)
336 assertShim(t, installed.Path)
339// TestInstall_PrefersGlabsDirectoryOverLocalBin pins the precedence that
340// keeps an existing install idempotent: when glab's own directory is
341// writable, a shim already sitting next to it is updated in place rather
342// than orphaned by a second copy appearing in ~/.local/bin.
343func TestInstall_PrefersGlabsDirectoryOverLocalBin(t *testing.T) {
344 glabDir := t.TempDir()
345 writeFakeGlab(t, glabDir)
346 localBin := sandboxHome(t)
347 require.NoError(t, os.MkdirAll(localBin, 0o755))
348 t.Setenv("PATH", glabDir+string(os.PathListSeparator)+localBin)
350 installed, err := Install()
351 require.NoError(t, err)
352 assert.Equal(t, filepath.Join(glabDir, FullName), installed.Path)
354 _, statErr := os.Stat(filepath.Join(localBin, FullName))
355 assert.True(t, os.IsNotExist(statErr), "a second shim must not appear in ~/.local/bin")
358// TestInstall_NoWritableDirectoryAnywhere covers the only remaining failure:
359// the error has to name the directories that refused the write, because the
360// user's remedy is to make one of them writable or to put a writable one on
361// PATH.
362func TestInstall_NoWritableDirectoryAnywhere(t *testing.T) {
363 glabDir := unwritableGlabDir(t)
364 home := unwritableGlabDir(t)
365 t.Setenv("HOME", home)
366 t.Setenv("USERPROFILE", home)
367 t.Setenv("PATH", glabDir)
369 _, err := Install()
370 require.ErrorContains(t, err, glabDir)
371 assert.ErrorContains(t, err, filepath.Join(home, ".local", "bin"))
374// TestInstall_ReportsAnUnresolvableHomeDirectory covers the failure with no
375// home directory to fall back to: dropping ~/.local/bin from the candidates
376// silently would leave the user reading a list of PATH directories with no
377// hint that an unset $HOME is why the usual fallback is missing from it.
378func TestInstall_ReportsAnUnresolvableHomeDirectory(t *testing.T) {
379 glabDir := unwritableGlabDir(t)
380 t.Setenv("HOME", "")
381 t.Setenv("USERPROFILE", "")
382 t.Setenv("PATH", glabDir)
384 _, err := Install()
385 require.ErrorContains(t, err, glabDir)
386 assert.ErrorContains(t, err, "home directory")
389func TestInstall_GlabNotOnPath(t *testing.T) {
390 t.Setenv("PATH", t.TempDir())
392 installed, err := Install()
393 require.Error(t, err)
394 assert.Empty(t, installed.Path)
397func TestInstall_UnsupportedOS(t *testing.T) {
398 if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
399 t.Skip("only exercises the unsupported-OS error path")
400 }
402 _, err := Install()
403 require.ErrorContains(t, err, "is not supported")
404 assert.ErrorContains(t, err, runtime.GOOS, "the error should name the unsupported OS")
407// TestLocate_ResolvesTheDirectoryInstallWritesInto pins what the returned path
408// is for: Install joins FullName onto its directory, so a caller checking
409// Locate up front is checking the same lookup that decides where the shim
410// lands.
411func TestLocate_ResolvesTheDirectoryInstallWritesInto(t *testing.T) {
412 binDir := t.TempDir()
413 writeFakeGlab(t, binDir)
414 t.Setenv("PATH", binDir)
416 path, err := Locate()
417 require.NoError(t, err)
418 assert.Equal(t, binDir, filepath.Dir(path))
421// TestLocate_AgreesWithInstall pins what a caller that checks Locate up front
422// relies on: Install resolves glab through Locate too, so on a supported
423// platform it never fails for a reason Locate would have caught first. The
424// counterpart of TestSupported_AgreesWithInstall for the other precondition.
425func TestLocate_AgreesWithInstall(t *testing.T) {
426 t.Setenv("PATH", t.TempDir())
428 _, locateErr := Locate()
429 require.ErrorContains(t, locateErr, "glab")
431 _, installErr := Install()
432 require.Error(t, installErr)
434 if Supported() != nil {
435 // Install rejects the platform before it ever looks glab up, so the two
436 // errors legitimately differ here.
437 assert.ErrorContains(t, installErr, "is not supported")
438 return
439 }
440 assert.Equal(t, locateErr.Error(), installErr.Error(), "Install must surface Locate's error unchanged")
443// TestSupported_AgreesWithInstall pins that the two never disagree about the
444// platform: callers check Supported up front and then rely on Install not
445// failing for that reason later.
446func TestSupported_AgreesWithInstall(t *testing.T) {
447 // An empty PATH makes a supported platform fail Install for the only other
448 // reason it can, which must not read as an unsupported platform.
449 t.Setenv("PATH", t.TempDir())
450 _, installErr := Install()
451 require.Error(t, installErr)
453 if err := Supported(); err != nil {
454 assert.ErrorContains(t, err, runtime.GOOS)
455 assert.ErrorContains(t, installErr, "is not supported")
456 return
457 }
458 assert.NotContains(t, installErr.Error(), "is not supported")
461// readDockerConfig returns the parsed config.json from dir.
462func readDockerConfig(t *testing.T, dir string) map[string]any {
463 t.Helper()
465 data, err := os.ReadFile(filepath.Join(dir, "config.json"))
466 require.NoError(t, err)
468 var parsed map[string]any
469 require.NoError(t, json.Unmarshal(data, &parsed))
470 return parsed
473// writeDockerConfig seeds dir with a config.json holding body.
474func writeDockerConfig(t *testing.T, dir, body string) {
475 t.Helper()
476 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.json"), []byte(body), 0o600))
479func credHelpers(t *testing.T, dir string) map[string]any {
480 t.Helper()
482 helpers, ok := readDockerConfig(t, dir)["credHelpers"].(map[string]any)
483 require.True(t, ok, "credHelpers should be present in config.json")
484 return helpers
487func authEntries(t *testing.T, dir string) map[string]any {
488 t.Helper()
490 auths, ok := readDockerConfig(t, dir)["auths"].(map[string]any)
491 require.True(t, ok, "auths should be present in config.json")
492 return auths
495func TestRegister_WritesCredHelpers(t *testing.T) {
496 dir := t.TempDir()
498 got, err := Register(dir, "registry.example.com", "registry.other.example.com")
499 require.NoError(t, err)
501 assert.Equal(t, []Registration{
502 {Domain: "registry.example.com"},
503 {Domain: "registry.other.example.com"},
504 }, got)
506 helpers := credHelpers(t, dir)
507 assert.Equal(t, ShortName, helpers["registry.example.com"])
508 assert.Equal(t, ShortName, helpers["registry.other.example.com"])
511// TestConfigDir_HonorsDockerConfigEnv covers why ConfigDir exists rather than
512// passing "" to dockerconfig.Load: writing to the wrong place fails silently,
513// because Docker reads a config.json with no entry in it.
514func TestConfigDir_HonorsDockerConfigEnv(t *testing.T) {
515 home := t.TempDir()
516 dockerDir := t.TempDir()
517 t.Setenv("HOME", home)
518 t.Setenv("USERPROFILE", home)
519 t.Setenv("DOCKER_CONFIG", dockerDir)
521 dir, err := ConfigDir()
522 require.NoError(t, err)
523 assert.Equal(t, dockerDir, dir)
526// TestConfigDir_FallsBackToDockerHomeDir covers the no-$DOCKER_CONFIG default.
527func TestConfigDir_FallsBackToDockerHomeDir(t *testing.T) {
528 home := t.TempDir()
529 t.Setenv("HOME", home)
530 t.Setenv("USERPROFILE", home)
531 t.Setenv("DOCKER_CONFIG", "")
533 dir, err := ConfigDir()
534 require.NoError(t, err)
535 assert.Equal(t, filepath.Join(home, ".docker"), dir)
538// TestRegister_RefusesToReplaceAnotherHelper is the guard that matters most:
539// credHelpers holds one helper per domain and Docker consults it ahead of every
540// other credential source, so overwriting an entry silently takes a registry
541// away from whichever tool owns it, and Save discards the old value.
542func TestRegister_RefusesToReplaceAnotherHelper(t *testing.T) {
543 dir := t.TempDir()
544 writeDockerConfig(t, dir, `{"credHelpers":{"registry.example.com":"ecr-login"}}`)
546 got, err := Register(dir, "registry.example.com")
547 require.Error(t, err)
548 assert.Nil(t, got)
550 var conflict *ConflictError
551 require.ErrorAs(t, err, &conflict)
552 assert.Equal(t, map[string]string{"registry.example.com": "ecr-login"}, conflict.Helpers)
553 assert.Contains(t, err.Error(), "ecr-login")
554 assert.Contains(t, err.Error(), filepath.Join(dir, "config.json"))
556 assert.Equal(t, "ecr-login", credHelpers(t, dir)["registry.example.com"],
557 "the existing helper must be left untouched")
560// TestRegister_WritesNothingWhenAnyDomainConflicts pins the check-all-first
561// ordering: a conflict on the second domain must not leave the first written.
562func TestRegister_WritesNothingWhenAnyDomainConflicts(t *testing.T) {
563 dir := t.TempDir()
564 writeDockerConfig(t, dir, `{"credHelpers":{"claimed.example.com":"gcloud"}}`)
566 _, err := Register(dir, "free.example.com", "claimed.example.com")
567 require.Error(t, err)
569 helpers := credHelpers(t, dir)
570 assert.NotContains(t, helpers, "free.example.com", "no domain should have been written")
571 assert.Equal(t, "gcloud", helpers["claimed.example.com"])
574// TestRegister_PreservesUnrelatedEntries guards the success path: writing the
575// new domain's entry must not disturb credHelpers or auths entries for
576// domains Register was never asked about.
577func TestRegister_PreservesUnrelatedEntries(t *testing.T) {
578 dir := t.TempDir()
579 writeDockerConfig(t, dir, `{
580 "credHelpers":{"other.example.com":"ecr-login"},
581 "auths":{"another.example.com":{"auth":"dXNlcjpwYXNz"}}
582 }`)
584 got, err := Register(dir, "new.example.com")
585 require.NoError(t, err)
586 assert.Equal(t, []Registration{{Domain: "new.example.com"}}, got)
588 helpers := credHelpers(t, dir)
589 assert.Equal(t, "ecr-login", helpers["other.example.com"], "unrelated helper must survive")
590 assert.Equal(t, ShortName, helpers["new.example.com"])
592 auths := authEntries(t, dir)
593 assert.Contains(t, auths, "another.example.com", "unrelated login must survive")
596// TestRegister_ReRegisteringGlabIsNotAConflict keeps the command idempotent.
597func TestRegister_ReRegisteringGlabIsNotAConflict(t *testing.T) {
598 dir := t.TempDir()
599 writeDockerConfig(t, dir, `{"credHelpers":{"registry.example.com":"glab"}}`)
601 got, err := Register(dir, "registry.example.com")
602 require.NoError(t, err)
603 assert.Equal(t, []Registration{{Domain: "registry.example.com"}}, got)
606// TestRegister_ReportsShadowedLogin covers the softer half: an existing
607// `docker login` is not destroyed, but Docker stops consulting it.
608func TestRegister_ReportsShadowedLogin(t *testing.T) {
609 dir := t.TempDir()
610 writeDockerConfig(t, dir, `{"auths":{"registry.example.com":{"auth":"dXNlcjpwYXNz"}}}`)
612 got, err := Register(dir, "registry.example.com")
613 require.NoError(t, err)
614 assert.Equal(t, []Registration{{Domain: "registry.example.com", ShadowedLogin: true}}, got)
617// TestRegister_ReportsShadowedLoginUnderCredsStore is why the code checks
618// whether the key exists rather than what it holds: with a credsStore
619// configured, `docker login` leaves an empty marker entry and keeps the
620// secret in the OS keychain, while `docker logout` removes the key outright.
621func TestRegister_ReportsShadowedLoginUnderCredsStore(t *testing.T) {
622 dir := t.TempDir()
623 writeDockerConfig(t, dir, `{"credsStore":"desktop","auths":{"registry.example.com":{}}}`)
625 got, err := Register(dir, "registry.example.com")
626 require.NoError(t, err)
627 assert.Equal(t, []Registration{{Domain: "registry.example.com", ShadowedLogin: true}}, got)
630func TestRegister_NoShadowWithoutAnExistingLogin(t *testing.T) {
631 dir := t.TempDir()
633 got, err := Register(dir, "registry.example.com")
634 require.NoError(t, err)
635 assert.Equal(t, []Registration{{Domain: "registry.example.com"}}, got)
Diagnostics6 git calls · 325 ms
CallStatusSizeTime0325 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit9 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=9
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:0200245 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=245
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=aba319365668a8024052e17001ff1ccb32f32ad1
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=245
git.pkt.payload.max=218
git.sideband.band1.bytes=218
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=218
git.pack.trailer=a79e8c6a1fa5857567b424874e4f19628bc00ab3
Open pack map
fetch2006.2 KiB312 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=312
git.response.bytes=6310
git.response.cache=MISS
git.response.duration_ms=312
git.fetch.wants=b850570eefbfb024efa0fb44aca0f34dfbfea703
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=6310
git.pkt.payload.max=6283
git.sideband.band1.bytes=6283
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2cf582bc1efad
Request
effd6aab…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format