GitLabgitlab-org

cli

main
ply8 git calls222 ms103 KiB5 cachedprotocol v2
1108 lines36 KiBRaw
1//go:build !integration
3package status
5import (
6 "bytes"
7 "encoding/json"
8 "errors"
9 "fmt"
10 "net/http"
11 "os"
12 "path/filepath"
13 "testing"
15 "github.com/MakeNowJust/heredoc/v2"
16 "github.com/google/shlex"
17 "github.com/spf13/cobra"
18 "github.com/stretchr/testify/assert"
19 "github.com/stretchr/testify/require"
20 "github.com/zalando/go-keyring"
21 "go.uber.org/mock/gomock"
22 "golang.org/x/oauth2"
24 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
25 gitlabtesting "gitlab.com/gitlab-org/api/client-go/v3/testing"
27 "gitlab.com/gitlab-org/cli/internal/api"
28 "gitlab.com/gitlab-org/cli/internal/cmdutils"
29 "gitlab.com/gitlab-org/cli/internal/config"
30 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
33func Test_NewCmdStatus(t *testing.T) {
34 tests := []struct {
35 name string
36 cli string
37 wants options
38 }{
39 {
40 name: "no arguments",
41 cli: "",
42 wants: options{},
43 },
44 {
45 name: "hostname set",
46 cli: "--hostname gitlab.example.com",
47 wants: options{
48 hostname: "gitlab.example.com",
49 },
50 },
51 {
52 name: "show token",
53 cli: "--show-token",
54 wants: options{
55 showToken: true,
56 },
57 },
58 {
59 name: "all flag set",
60 cli: "--all",
61 wants: options{
62 all: true,
63 },
64 },
65 }
67 for _, tt := range tests {
68 t.Run(tt.name, func(t *testing.T) {
69 f := cmdtest.NewTestFactory(nil)
71 argv, err := shlex.Split(tt.cli)
72 require.NoError(t, err)
74 var gotOpts *options
75 cmd := NewCmdStatus(f, func(opts *options) error {
76 gotOpts = opts
77 return nil
78 })
80 // TODO cobra hack-around
81 cmd.Flags().BoolP("help", "x", false, "")
83 cmd.SetArgs(argv)
84 cmd.SetIn(&bytes.Buffer{})
85 cmd.SetOut(&bytes.Buffer{})
86 cmd.SetErr(&bytes.Buffer{})
88 _, err = cmd.ExecuteC()
89 require.NoError(t, err)
91 assert.Equal(t, tt.wants.hostname, gotOpts.hostname)
92 assert.Equal(t, tt.wants.showToken, gotOpts.showToken)
93 assert.Equal(t, tt.wants.all, gotOpts.all)
94 })
95 }
98func Test_statusRun(t *testing.T) {
99 // Force the keyring to be unavailable so the plaintext-migration hint is
100 // not emitted; these fixtures assert the base output.
101 keyring.MockInitWithError(errors.New("keyring unavailable"))
102 t.Cleanup(keyring.MockInit)
103 t.Setenv("SNAP_NAME", "")
105 dir := t.TempDir()
106 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
107hosts:
108 gitlab.example.com:
109 token: xxxxxxxxxxxxxxxxxxxx
110 git_protocol: ssh
111 api_protocol: https
112 gitlab2.example.com:
113 token: glpat-xxxxxxxxxxxxxxxxxxxx
114 git_protocol: ssh
115 api_protocol: https
116 gitlab3.example.com:
117 token: glpat-xxxxxxxxxxxxxxxxxxxx
118 git_protocol: ssh
119 api_protocol: https
120 another.example:
121 token: isinvalid
122 test.example:
123 token:
124`), 0o600))
126 cfgFile := config.ConfigFile()
127 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
128 require.NoError(t, err)
130 tests := []struct {
131 name string
132 opts *options
133 envVar bool
134 wantErr bool
135 stderr string
136 }{
137 {
138 name: "hostname set with old token format",
139 opts: &options{
140 hostname: "gitlab.example.com",
141 },
142 wantErr: false,
143 stderr: fmt.Sprintf(`gitlab.example.com
144 ✓ Logged in to gitlab.example.com as john_smith (%s)
145 ✓ Git operations for gitlab.example.com configured to use ssh protocol.
146 ✓ API calls for gitlab.example.com are made over https protocol.
147 ✓ REST API Endpoint: https://gitlab.example.com/api/v4/
148 ✓ GraphQL Endpoint: https://gitlab.example.com/api/graphql/
149 ✓ Token found in configuration file (plaintext): **************************
150 ! To store this token more securely, run glab auth login --hostname gitlab.example.com to move it into the operating system keyring.
151`, cfgFile),
152 },
153 {
154 name: "hostname set with new token format",
155 opts: &options{
156 hostname: "gitlab2.example.com",
157 },
158 wantErr: false,
159 stderr: fmt.Sprintf(`gitlab2.example.com
160 ✓ Logged in to gitlab2.example.com as john_doe (%s)
161 ✓ Git operations for gitlab2.example.com configured to use ssh protocol.
162 ✓ API calls for gitlab2.example.com are made over https protocol.
163 ✓ REST API Endpoint: https://gitlab2.example.com/api/v4/
164 ✓ GraphQL Endpoint: https://gitlab2.example.com/api/graphql/
165 ✓ Token found in configuration file (plaintext): **************************
166 ! To store this token more securely, run glab auth login --hostname gitlab2.example.com to move it into the operating system keyring.
167`, cfgFile),
168 },
169 {
170 name: "instance not authenticated",
171 opts: &options{
172 hostname: "invalid.example",
173 },
174 wantErr: true,
175 stderr: "x invalid.example has not been authenticated with glab; run `glab auth login --hostname invalid.example` to authenticate",
176 },
177 {
178 name: "with token set in env variable",
179 opts: &options{
180 hostname: "gitlab3.example.com",
181 },
182 envVar: true,
183 wantErr: false,
184 stderr: `gitlab3.example.com
185 ✓ Logged in to gitlab3.example.com as john_doe (GITLAB_TOKEN)
186 ✓ Git operations for gitlab3.example.com configured to use ssh protocol.
187 ✓ API calls for gitlab3.example.com are made over https protocol.
188 ✓ REST API Endpoint: https://gitlab3.example.com/api/v4/
189 ✓ GraphQL Endpoint: https://gitlab3.example.com/api/graphql/
190 ✓ Token found in environment variable GITLAB_TOKEN: **************************
192! Token is from environment variable GITLAB_TOKEN. This takes precedence over tokens stored in config or keyring.
193 Run type glab to find the source: an alias such as 'op plugin run -- glab' means a wrapper (for example, a 1Password shell plugin) is injecting it, which is expected and needs no action.
194 A plain path means it is set in your environment (for example, a shell profile such as ~/.bashrc or ~/.zshrc, or a CI/CD variable); remove it there so glab uses your stored credentials.
195`,
196 },
197 }
199 tc := gitlabtesting.NewTestClient(t)
200 gomock.InOrder(
201 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil),
202 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_doe"}, nil, nil),
203 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_doe"}, nil, nil),
204 )
206 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
207 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
208 }
210 for _, tt := range tests {
211 io, _, stdout, stderr := cmdtest.TestIOStreams()
212 tt.opts.config = func() config.Config {
213 return configs
214 }
215 tt.opts.io = io
216 tt.opts.httpClientOverride = client
217 tt.opts.apiClient = func(repoHost string) (*api.Client, error) {
218 return client("", repoHost)
219 }
220 t.Run(tt.name, func(t *testing.T) {
221 if tt.envVar {
222 t.Setenv("GITLAB_TOKEN", "foo")
223 } else {
224 t.Setenv("GITLAB_TOKEN", "")
225 }
227 err := tt.opts.run(t.Context())
228 if (err != nil) != tt.wantErr {
229 t.Errorf("statusRun() error = %v, wantErr %v", err, tt.wantErr)
230 }
232 assert.Empty(t, stdout.String())
234 if tt.wantErr {
235 require.Error(t, err)
236 assert.Equal(t, tt.stderr, err.Error())
237 } else {
238 require.NoError(t, err)
239 assert.Equal(t, tt.stderr, stderr.String())
240 }
241 })
242 }
245func Test_statusRun_authFailureWithEnvToken(t *testing.T) {
246 keyring.MockInitWithError(errors.New("keyring unavailable"))
247 t.Cleanup(keyring.MockInit)
249 dir := t.TempDir()
250 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
251hosts:
252 gitlab.example.com:
253 token: xxxxxxxxxxxxxxxxxxxx
254 git_protocol: ssh
255 api_protocol: https
256`), 0o600))
258 tc := gitlabtesting.NewTestClient(t)
259 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(nil, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusUnauthorized}}, errors.New("GET https://gitlab.example.com/api/v4/user: 401 {error: invalid_token}"))
261 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
262 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
263 }
265 t.Setenv("GITLAB_TOKEN", "glpat-expired-token")
266 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
267 require.NoError(t, err)
268 io, _, stdout, stderr := cmdtest.TestIOStreams()
270 opts := &options{
271 hostname: "gitlab.example.com",
272 config: func() config.Config {
273 return configs
274 },
275 apiClient: func(repoHost string) (*api.Client, error) {
276 return client("", repoHost)
277 },
278 httpClientOverride: client,
279 io: io,
280 }
282 err = opts.run(t.Context())
283 require.Error(t, err)
284 assert.Empty(t, stdout.String())
285 assert.Contains(t, stderr.String(), "Token is from environment variable GITLAB_TOKEN. A wrapper may be injecting a different or expired token.")
286 assert.Contains(t, stderr.String(), "To investigate, run type glab: an alias such as 'op plugin run -- glab' means a wrapper (for example, a 1Password shell plugin) is injecting the token; a plain path rules that out.")
287 assert.Contains(t, stderr.String(), "To see the token value in use, run: env | grep -E 'GITLAB_TOKEN|GITLAB_ACCESS_TOKEN|OAUTH_TOKEN'")
288 assert.Contains(t, stderr.String(), "Token is from environment variable GITLAB_TOKEN. This takes precedence over tokens stored in config or keyring.")
289 assert.Contains(t, stderr.String(), "Run type glab to find the source: an alias such as 'op plugin run -- glab' means a wrapper (for example, a 1Password shell plugin) is injecting it, which is expected and needs no action.")
290 assert.Contains(t, stderr.String(), "A plain path means it is set in your environment (for example, a shell profile such as ~/.bashrc or ~/.zshrc, or a CI/CD variable); remove it there so glab uses your stored credentials.")
291 // The host is not configured for OAuth, so the scheme hint stays quiet.
292 assert.NotContains(t, stderr.String(), "GLAB_IS_OAUTH2=true")
295// A host configured for OAuth whose token arrives from the environment is
296// authenticated as a PAT. When that 401s, the generic advice about a wrapper
297// injecting a bad token is misleading, so name the scheme mismatch too.
298func Test_statusRun_authFailureWithEnvTokenOnOAuthHost(t *testing.T) {
299 // Runs `status` against an OAuth-configured host whose token comes from
300 // GITLAB_TOKEN and whose CurrentUser call 401s.
301 statusOnOAuthHost := func(t *testing.T) *bytes.Buffer {
302 t.Helper()
304 keyring.MockInitWithError(errors.New("keyring unavailable"))
305 t.Cleanup(keyring.MockInit)
307 dir := t.TempDir()
308 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
309hosts:
310 gitlab.example.com:
311 is_oauth2: "true"
312 git_protocol: ssh
313 api_protocol: https
314`), 0o600))
316 tc := gitlabtesting.NewTestClient(t)
317 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(nil, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusUnauthorized}}, errors.New("GET https://gitlab.example.com/api/v4/user: 401 {error: invalid_token}"))
319 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
320 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
321 }
323 t.Setenv("GITLAB_TOKEN", "an-oauth-access-token")
324 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
325 require.NoError(t, err)
326 io, _, stdout, stderr := cmdtest.TestIOStreams()
328 opts := &options{
329 hostname: "gitlab.example.com",
330 config: func() config.Config {
331 return configs
332 },
333 apiClient: func(repoHost string) (*api.Client, error) {
334 return client("", repoHost)
335 },
336 httpClientOverride: client,
337 io: io,
338 }
340 err = opts.run(t.Context())
341 require.Error(t, err)
342 assert.Empty(t, stdout.String())
343 return stderr
344 }
346 t.Run("names the mismatch when the OAuth flag comes from the configuration file", func(t *testing.T) {
347 t.Setenv("GLAB_IS_OAUTH2", "")
349 stderr := statusOnOAuthHost(t)
351 assert.Contains(t, stderr.String(), "gitlab.example.com is configured for OAuth, but the token from GITLAB_TOKEN is sent as a personal access token.")
352 assert.Contains(t, stderr.String(), "GLAB_IS_OAUTH2=true")
353 })
355 t.Run("stays quiet when the OAuth flag itself comes from the environment", func(t *testing.T) {
356 // GLAB_IS_OAUTH2 makes the environment token authenticate as an OAuth
357 // token, so there is no scheme mismatch to report and no point telling
358 // the user to set a variable they already set.
359 t.Setenv("GLAB_IS_OAUTH2", "true")
361 stderr := statusOnOAuthHost(t)
363 assert.NotContains(t, stderr.String(), "is sent as a personal access token")
364 assert.NotContains(t, stderr.String(), "GLAB_IS_OAUTH2=true")
365 })
368func Test_statusRun_noHostnameSpecified(t *testing.T) {
369 keyring.MockInitWithError(errors.New("keyring unavailable"))
370 t.Cleanup(keyring.MockInit)
371 t.Setenv("SNAP_NAME", "")
373 dir := t.TempDir()
374 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
375hosts:
376 gitlab.example.com:
377 token: xxxxxxxxxxxxxxxxxxxx
378 git_protocol: ssh
379 api_protocol: https
380 another.example:
381 token: isinvalid
382 test.example:
383 token:
384`), 0o600))
386 cfgFile := config.ConfigFile()
388 tc := gitlabtesting.NewTestClient(t)
389 gomock.InOrder(
390 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusOK}}, nil),
391 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(nil, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusUnauthorized}}, errors.New("GET https://another.example/api/v4/user: 401 {message: invalid token}")),
392 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(nil, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusUnauthorized}}, errors.New("GET https://test.example/api/v4/user: 401 {message: no token provided}")),
393 )
395 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
396 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
397 }
399 expectedOutput := fmt.Sprintf(`gitlab.example.com
400 ✓ Logged in to gitlab.example.com as john_smith (%s)
401 ✓ Git operations for gitlab.example.com configured to use ssh protocol.
402 ✓ API calls for gitlab.example.com are made over https protocol.
403 ✓ REST API Endpoint: https://gitlab.example.com/api/v4/
404 ✓ GraphQL Endpoint: https://gitlab.example.com/api/graphql/
405 ✓ Token found in configuration file (plaintext): **************************
406 ! To store this token more securely, run glab auth login --hostname gitlab.example.com to move it into the operating system keyring.
407another.example
408 x another.example: API call failed: GET https://another.example/api/v4/user: 401 {message: invalid token}
409 ✓ Git operations for another.example configured to use ssh protocol.
410 ✓ API calls for another.example are made over https protocol.
411 ✓ REST API Endpoint: https://another.example/api/v4/
412 ✓ GraphQL Endpoint: https://another.example/api/graphql/
413 ✓ Token found in configuration file (plaintext): **************************
414 ! To store this token more securely, run glab auth login --hostname another.example to move it into the operating system keyring.
415test.example
416 x test.example: API call failed: GET https://test.example/api/v4/user: 401 {message: no token provided}
417 ✓ Git operations for test.example configured to use ssh protocol.
418 ✓ API calls for test.example are made over https protocol.
419 ✓ REST API Endpoint: https://test.example/api/v4/
420 ✓ GraphQL Endpoint: https://test.example/api/graphql/
421 ! No token found (checked config file, keyring, and environment variables).
422`, cfgFile)
424 t.Setenv("GITLAB_TOKEN", "")
425 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
426 require.NoError(t, err)
427 io, _, stdout, stderr := cmdtest.TestIOStreams()
429 opts := &options{
430 config: func() config.Config {
431 return configs
432 },
433 apiClient: func(repoHost string) (*api.Client, error) {
434 return client("", repoHost)
435 },
436 httpClientOverride: client,
437 io: io,
438 }
440 err = opts.run(t.Context())
441 assert.Equal(t, "\nx could not authenticate to one or more of the configured GitLab instances", err.Error())
442 assert.Empty(t, stdout.String())
443 assert.Equal(t, expectedOutput, stderr.String())
446func Test_statusRun_keyringMigrationHint(t *testing.T) {
447 // The token is stored as plaintext in the config file, so status should
448 // report the storage location and nudge the user to migrate it.
449 keyring.MockInitWithError(errors.New("keyring unavailable"))
450 t.Cleanup(keyring.MockInit)
451 t.Setenv("SNAP_NAME", "")
453 dir := t.TempDir()
454 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
455hosts:
456 gitlab.example.com:
457 token: xxxxxxxxxxxxxxxxxxxx
458 git_protocol: ssh
459 api_protocol: https
460`), 0o600))
462 tc := gitlabtesting.NewTestClient(t)
463 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
464 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
465 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
466 }
468 t.Setenv("GITLAB_TOKEN", "")
469 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
470 require.NoError(t, err)
471 io, _, _, stderr := cmdtest.TestIOStreams()
473 opts := &options{
474 hostname: "gitlab.example.com",
475 config: func() config.Config {
476 return configs
477 },
478 apiClient: func(repoHost string) (*api.Client, error) {
479 return client("", repoHost)
480 },
481 httpClientOverride: client,
482 io: io,
483 }
485 require.NoError(t, opts.run(t.Context()))
486 assert.Contains(t, stderr.String(), "Token found in configuration file (plaintext):")
487 assert.Contains(t, stderr.String(), "To store this token more securely, run glab auth login --hostname gitlab.example.com to move it into the operating system keyring.")
490func Test_statusRun_incompleteOAuth2Warning(t *testing.T) {
491 t.Setenv("GITLAB_TOKEN", "")
492 t.Setenv("GLAB_IS_OAUTH2", "")
494 dir := t.TempDir()
495 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
496hosts:
497 gitlab.example.com:
498 token: xxxxxxxxxxxxxxxxxxxx
499 is_oauth2: "true"
500 api_protocol: https
501`), 0o600))
503 tc := gitlabtesting.NewTestClient(t)
504 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
505 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
506 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
507 }
509 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
510 require.NoError(t, err)
511 io, _, _, stderr := cmdtest.TestIOStreams()
513 opts := &options{
514 hostname: "gitlab.example.com",
515 config: func() config.Config {
516 return configs
517 },
518 apiClient: func(repoHost string) (*api.Client, error) {
519 return client("", repoHost)
520 },
521 httpClientOverride: client,
522 io: io,
523 }
525 require.NoError(t, opts.run(t.Context()))
526 assert.Contains(t, stderr.String(), "Logged in to gitlab.example.com as john_smith")
527 assert.Contains(t, stderr.String(), "gitlab.example.com is configured for OAuth, but no refresh token is stored")
528 assert.Contains(t, stderr.String(), "To clear it, run glab auth login --hostname gitlab.example.com.")
531func Test_statusRun_noIncompleteOAuth2WarningWhenRefreshTokenPresent(t *testing.T) {
532 t.Setenv("GITLAB_TOKEN", "")
533 t.Setenv("GLAB_IS_OAUTH2", "")
535 dir := t.TempDir()
536 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
537hosts:
538 gitlab.example.com:
539 token: xxxxxxxxxxxxxxxxxxxx
540 is_oauth2: "true"
541 oauth2_refresh_token: some-refresh-token
542 api_protocol: https
543`), 0o600))
545 tc := gitlabtesting.NewTestClient(t)
546 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
547 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
548 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
549 }
551 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
552 require.NoError(t, err)
553 io, _, _, stderr := cmdtest.TestIOStreams()
555 opts := &options{
556 hostname: "gitlab.example.com",
557 config: func() config.Config {
558 return configs
559 },
560 apiClient: func(repoHost string) (*api.Client, error) {
561 return client("", repoHost)
562 },
563 httpClientOverride: client,
564 io: io,
565 }
567 require.NoError(t, opts.run(t.Context()))
568 assert.NotContains(t, stderr.String(), "no refresh token is stored")
571func Test_statusRun_noIncompleteOAuth2WarningWithoutToken(t *testing.T) {
572 t.Setenv("GITLAB_TOKEN", "")
573 t.Setenv("GLAB_IS_OAUTH2", "")
575 dir := t.TempDir()
576 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
577hosts:
578 gitlab.example.com:
579 is_oauth2: "true"
580 api_protocol: https
581`), 0o600))
583 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
584 require.NoError(t, err)
585 io, _, _, stderr := cmdtest.TestIOStreams()
587 opts := &options{
588 hostname: "gitlab.example.com",
589 config: func() config.Config {
590 return configs
591 },
592 apiClient: func(repoHost string) (*api.Client, error) {
593 return nil, errors.New("no access or refresh token was found")
594 },
595 io: io,
596 }
598 require.Error(t, opts.run(t.Context()))
599 assert.Contains(t, stderr.String(), "No token found")
600 assert.NotContains(t, stderr.String(), "no refresh token is stored")
603func Test_statusRun_noIncompleteOAuth2WarningForEnvIsOAuth2(t *testing.T) {
604 t.Setenv("GITLAB_TOKEN", "")
605 t.Setenv("GLAB_IS_OAUTH2", "true")
607 dir := t.TempDir()
608 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
609hosts:
610 gitlab.example.com:
611 token: xxxxxxxxxxxxxxxxxxxx
612 api_protocol: https
613`), 0o600))
615 tc := gitlabtesting.NewTestClient(t)
616 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
617 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
618 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
619 }
621 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
622 require.NoError(t, err)
623 io, _, _, stderr := cmdtest.TestIOStreams()
625 opts := &options{
626 hostname: "gitlab.example.com",
627 config: func() config.Config {
628 return configs
629 },
630 apiClient: func(repoHost string) (*api.Client, error) {
631 return client("", repoHost)
632 },
633 httpClientOverride: client,
634 io: io,
635 }
637 require.NoError(t, opts.run(t.Context()))
638 assert.NotContains(t, stderr.String(), "no refresh token is stored")
641func Test_statusRun_keyringMigrationHint_snapConfined(t *testing.T) {
642 keyring.MockInitWithError(errors.New("keyring unavailable"))
643 t.Cleanup(keyring.MockInit)
644 t.Setenv("SNAP_NAME", "glab")
646 dir := t.TempDir()
647 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
648hosts:
649 gitlab.example.com:
650 token: xxxxxxxxxxxxxxxxxxxx
651 git_protocol: ssh
652 api_protocol: https
653`), 0o600))
655 tc := gitlabtesting.NewTestClient(t)
656 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
657 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
658 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
659 }
661 t.Setenv("GITLAB_TOKEN", "")
662 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
663 require.NoError(t, err)
664 io, _, _, stderr := cmdtest.TestIOStreams()
666 opts := &options{
667 hostname: "gitlab.example.com",
668 config: func() config.Config {
669 return configs
670 },
671 apiClient: func(repoHost string) (*api.Client, error) {
672 return client("", repoHost)
673 },
674 httpClientOverride: client,
675 io: io,
676 }
678 require.NoError(t, opts.run(t.Context()))
679 assert.Contains(t, stderr.String(), "To store this token more securely, run glab auth login --hostname gitlab.example.com")
680 assert.Contains(t, stderr.String(), "sudo snap connect glab:password-manager-service")
683func Test_statusRun_surfacesKeyringReadError(t *testing.T) {
684 // use_keyring is enabled but the keyring read fails (locked/denied). Status
685 // should report that error rather than silently showing "No token found".
686 keyring.MockInitWithError(errors.New("keyring locked"))
687 t.Cleanup(keyring.MockInit)
689 dir := t.TempDir()
690 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
691hosts:
692 gitlab.example.com:
693 use_keyring: "true"
694 git_protocol: ssh
695 api_protocol: https
696`), 0o600))
698 t.Setenv("GITLAB_TOKEN", "")
699 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
700 require.NoError(t, err)
701 io, _, stdout, stderr := cmdtest.TestIOStreams()
703 opts := &options{
704 hostname: "gitlab.example.com",
705 config: func() config.Config {
706 return configs
707 },
708 apiClient: func(repoHost string) (*api.Client, error) {
709 return nil, nil
710 },
711 io: io,
712 }
714 err = opts.run(t.Context())
715 require.Error(t, err)
716 assert.Empty(t, stdout.String())
717 assert.Contains(t, stderr.String(), "could not read the token")
718 assert.Contains(t, stderr.String(), "keyring locked")
721func Test_statusRun_noInstance(t *testing.T) {
722 dir := t.TempDir()
723 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
724git_protocol: ssh
725`), 0o600))
727 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
728 require.NoError(t, err)
729 io, _, stdout, _ := cmdtest.TestIOStreams()
731 opts := &options{
732 config: func() config.Config {
733 return configs
734 },
735 apiClient: func(repoHost string) (*api.Client, error) {
736 return nil, nil
737 },
738 io: io,
739 }
740 t.Run("no instance authenticated", func(t *testing.T) {
741 err := opts.run(t.Context())
742 assert.Equal(t, "no GitLab instances have been authenticated with glab; run `glab auth login` to authenticate", err.Error())
743 assert.Empty(t, stdout.String())
744 })
747func Test_statusRun_flagValidation(t *testing.T) {
748 exec := cmdtest.SetupCmdForTest(
749 t,
750 func(f cmdutils.Factory) *cobra.Command { return NewCmdStatus(f, nil) },
751 false,
752 cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
753 hosts:
754 gitlab.example.com:
755 token: glpat-xxxxxxxxxxxxxxxxxxxx
756 git_protocol: ssh
757 api_protocol: https
758 `,
759 ))),
760 )
762 _, err := exec("--all --hostname gitlab.example.com")
764 require.Error(t, err)
765 assert.Contains(t, err.Error(), "if any flags in the group [all hostname] are set none of the others can be")
768func Test_statusRun_jsonOutput(t *testing.T) {
769 keyring.MockInitWithError(errors.New("keyring unavailable"))
770 t.Cleanup(keyring.MockInit)
771 t.Setenv("GITLAB_TOKEN", "")
773 dir := t.TempDir()
774 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
775hosts:
776 gitlab.example.com:
777 token: fake-token-one
778 git_protocol: ssh
779 api_protocol: https
780 ssh_host: ssh.gitlab.example.com
781 another.example:
782 token: fake-token-two
783 api_protocol: http
784 subfolder: gitlab
785`), 0o600))
787 tc := gitlabtesting.NewTestClient(t)
788 gomock.InOrder(
789 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil),
790 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(nil, &gitlab.Response{Response: &http.Response{StatusCode: http.StatusUnauthorized}}, errors.New("GET http://another.example/gitlab/api/v4/user: 401 {message: 401 Unauthorized}")),
791 )
792 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
793 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
794 }
796 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
797 require.NoError(t, err)
798 io, _, stdout, stderr := cmdtest.TestIOStreams()
800 opts := &options{
801 outputFormat: "json",
802 config: func() config.Config {
803 return configs
804 },
805 apiClient: func(repoHost string) (*api.Client, error) {
806 return client("", repoHost)
807 },
808 httpClientOverride: client,
809 io: io,
810 }
812 err = opts.run(t.Context())
813 require.ErrorIs(t, err, cmdutils.SilentError)
814 assert.Empty(t, stderr.String())
815 assert.NotContains(t, stdout.String(), "fake-token")
817 var result struct {
818 Hosts []hostStatus `json:"hosts"`
819 }
820 require.NoError(t, json.Unmarshal(stdout.Bytes(), &result))
821 require.Len(t, result.Hosts, 2)
823 assert.Equal(t, hostStatus{
824 Host: "gitlab.example.com",
825 State: "success",
826 User: "john_smith",
827 TokenSource: "config_file",
828 GitProtocol: "ssh",
829 APIProtocol: "https",
830 APIEndpoint: "https://gitlab.example.com/api/v4/",
831 GraphQLEndpoint: "https://gitlab.example.com/api/graphql/",
832 SSHHost: "ssh.gitlab.example.com",
833 }, result.Hosts[0])
834 assert.Equal(t, hostStatus{
835 Host: "another.example",
836 State: "error",
837 Error: "GET http://another.example/gitlab/api/v4/user: 401 {message: 401 Unauthorized}",
838 TokenSource: "config_file",
839 GitProtocol: "ssh",
840 APIProtocol: "http",
841 APIEndpoint: "http://another.example/gitlab/api/v4/",
842 GraphQLEndpoint: "http://another.example/gitlab/api/graphql/",
843 Subfolder: "gitlab",
844 }, result.Hosts[1])
847func Test_statusRun_jsonOutputSucceeds(t *testing.T) {
848 keyring.MockInitWithError(errors.New("keyring unavailable"))
849 t.Cleanup(keyring.MockInit)
850 t.Setenv("GITLAB_TOKEN", "fake-token-env")
852 dir := t.TempDir()
853 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(`---
854hosts:
855 gitlab.example.com:
856 api_protocol: https
857`), 0o600))
859 tc := gitlabtesting.NewTestClient(t)
860 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
861 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
862 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
863 }
865 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
866 require.NoError(t, err)
867 io, _, stdout, stderr := cmdtest.TestIOStreams()
869 opts := &options{
870 hostname: "gitlab.example.com",
871 outputFormat: "json",
872 config: func() config.Config {
873 return configs
874 },
875 apiClient: func(repoHost string) (*api.Client, error) {
876 return client("", repoHost)
877 },
878 httpClientOverride: client,
879 io: io,
880 }
882 require.NoError(t, opts.run(t.Context()))
883 assert.Empty(t, stderr.String())
884 assert.NotContains(t, stdout.String(), "fake-token")
886 var result struct {
887 Hosts []hostStatus `json:"hosts"`
888 }
889 require.NoError(t, json.Unmarshal(stdout.Bytes(), &result))
890 require.Len(t, result.Hosts, 1)
891 assert.Equal(t, "gitlab.example.com", result.Hosts[0].Host)
892 assert.Equal(t, "success", result.Hosts[0].State)
893 assert.Equal(t, "john_smith", result.Hosts[0].User)
894 assert.Equal(t, "environment", result.Hosts[0].TokenSource)
895 assert.Empty(t, result.Hosts[0].Error)
898func Test_statusRun_showTokenWithJSONOutput(t *testing.T) {
899 exec := cmdtest.SetupCmdForTest(
900 t,
901 func(f cmdutils.Factory) *cobra.Command { return NewCmdStatus(f, nil) },
902 false,
903 cmdtest.WithConfig(config.NewFromString(heredoc.Doc(`
904 hosts:
905 gitlab.example.com:
906 token: fake-token
907 `,
908 ))),
909 )
911 _, err := exec("--show-token --output json")
913 require.Error(t, err)
914 assert.Equal(t, "--show-token cannot be used with --output json", err.Error())
917func Test_sanitizeAuthError(t *testing.T) {
918 htmlBody := []byte("<!DOCTYPE html>\n<html><head><title>Action Controller: Exception caught</title></head><body>error</body></html>")
920 tests := []struct {
921 name string
922 err error
923 want string
924 }{
925 {
926 name: "oauth2 retrieve error without structured error code drops the response body",
927 err: &oauth2.RetrieveError{
928 Response: &http.Response{Status: "500 Internal Server Error", StatusCode: http.StatusInternalServerError},
929 Body: htmlBody,
930 },
931 want: "oauth2: cannot fetch token: 500 Internal Server Error",
932 },
933 {
934 name: "wrapped oauth2 retrieve error is sanitized while preserving outer context",
935 err: fmt.Errorf("token refresh: %w", &oauth2.RetrieveError{
936 Response: &http.Response{Status: "500 Internal Server Error", StatusCode: http.StatusInternalServerError},
937 Body: htmlBody,
938 }),
939 want: "token refresh: oauth2: cannot fetch token: 500 Internal Server Error",
940 },
941 {
942 name: "oauth2 retrieve error with nil response falls back to a safe message",
943 err: &oauth2.RetrieveError{Body: htmlBody},
944 want: "oauth2: cannot fetch token: unknown status",
945 },
946 {
947 name: "structured oauth2 error is preserved",
948 err: &oauth2.RetrieveError{
949 Response: &http.Response{Status: "401 Unauthorized", StatusCode: http.StatusUnauthorized},
950 ErrorCode: "invalid_grant",
951 },
952 want: `oauth2: "invalid_grant"`,
953 },
954 {
955 name: "non-oauth2 error is returned unchanged",
956 err: errors.New("GET https://gitlab.example.com/api/v4/user: 401 {message: 401 Unauthorized}"),
957 want: "GET https://gitlab.example.com/api/v4/user: 401 {message: 401 Unauthorized}",
958 },
959 }
961 for _, tt := range tests {
962 t.Run(tt.name, func(t *testing.T) {
963 assert.Equal(t, tt.want, sanitizeAuthError(tt.err))
964 })
965 }
968func runJSONStatus(t *testing.T, cfgYAML string, apiClient func(string) (*api.Client, error), httpClientOverride func(string, string) (*api.Client, error)) ([]hostStatus, error) {
969 t.Helper()
971 dir := t.TempDir()
972 require.NoError(t, os.WriteFile(filepath.Join(dir, "config.yml"), []byte(cfgYAML), 0o600))
973 configs, err := config.ParseConfig(filepath.Join(dir, "config.yml"))
974 require.NoError(t, err)
975 io, _, stdout, stderr := cmdtest.TestIOStreams()
977 opts := &options{
978 hostname: "gitlab.example.com",
979 outputFormat: "json",
980 config: func() config.Config {
981 return configs
982 },
983 apiClient: apiClient,
984 httpClientOverride: httpClientOverride,
985 io: io,
986 }
988 runErr := opts.run(t.Context())
989 assert.Empty(t, stderr.String())
991 var result struct {
992 Hosts []hostStatus `json:"hosts"`
993 }
994 require.NoError(t, json.Unmarshal(stdout.Bytes(), &result))
995 return result.Hosts, runErr
998func Test_statusRun_jsonOutputErrors(t *testing.T) {
999 t.Setenv("GITLAB_TOKEN", "")
1001 tests := []struct {
1002 name string
1003 keyringErr string
1004 cfgYAML string
1005 wantError string
1006 wantTokenSource string
1007 }{
1009 name: "keyring read failure",
1010 keyringErr: "keyring locked",
1011 cfgYAML: `---
1012hosts:
1013 gitlab.example.com:
1014 use_keyring: "true"
1015 api_protocol: https
1017 wantError: "could not read the token: ",
1018 },
1020 name: "API client setup failure",
1021 keyringErr: "keyring unavailable",
1022 cfgYAML: `---
1023hosts:
1024 gitlab.example.com:
1025 token: fake-token-one
1026 api_protocol: https
1028 wantError: "failed to initialize api client: client setup failed",
1029 wantTokenSource: "config_file",
1030 },
1032 name: "no token stored",
1033 keyringErr: "keyring unavailable",
1034 cfgYAML: `---
1035hosts:
1036 gitlab.example.com:
1037 api_protocol: https
1039 wantError: "failed to initialize api client: client setup failed",
1040 wantTokenSource: "none",
1041 },
1044 for _, tt := range tests {
1045 t.Run(tt.name, func(t *testing.T) {
1046 keyring.MockInitWithError(errors.New(tt.keyringErr))
1047 t.Cleanup(keyring.MockInit)
1049 hosts, err := runJSONStatus(t, tt.cfgYAML, func(string) (*api.Client, error) {
1050 return nil, errors.New("client setup failed")
1051 }, nil)
1053 require.ErrorIs(t, err, cmdutils.SilentError)
1054 require.Len(t, hosts, 1)
1055 assert.Equal(t, "error", hosts[0].State)
1056 assert.Contains(t, hosts[0].Error, tt.wantError)
1057 assert.Equal(t, tt.wantTokenSource, hosts[0].TokenSource)
1058 })
1062func Test_statusRun_jsonOutputIncompleteOAuth2Warning(t *testing.T) {
1063 keyring.MockInitWithError(errors.New("keyring unavailable"))
1064 t.Cleanup(keyring.MockInit)
1065 t.Setenv("GITLAB_TOKEN", "")
1066 t.Setenv("GLAB_IS_OAUTH2", "")
1068 tc := gitlabtesting.NewTestClient(t)
1069 tc.MockUsers.EXPECT().CurrentUser(gomock.Any()).Return(&gitlab.User{Username: "john_smith"}, nil, nil)
1070 client := func(token, hostname string) (*api.Client, error) { //nolint:unparam
1071 return cmdtest.NewTestApiClient(t, nil, token, hostname, api.WithGitLabClient(tc.Client)), nil
1074 hosts, err := runJSONStatus(t, `---
1075hosts:
1076 gitlab.example.com:
1077 token: fake-token-one
1078 is_oauth2: "true"
1079 api_protocol: https
1080`, func(repoHost string) (*api.Client, error) { return client("", repoHost) }, client)
1082 require.NoError(t, err)
1083 require.Len(t, hosts, 1)
1084 assert.Equal(t, "success", hosts[0].State)
1085 require.Len(t, hosts[0].Warnings, 1)
1086 assert.Contains(t, hosts[0].Warnings[0], "gitlab.example.com is configured for OAuth, but no refresh token is stored")
1089func Test_tokenSourceKind(t *testing.T) {
1090 tests := []struct {
1091 source string
1092 want tokenKind
1093 }{
1094 {source: "keyring", want: tokenKindKeyring},
1095 {source: "GITLAB_TOKEN", want: tokenKindEnvironment},
1096 {source: "GITLAB_ACCESS_TOKEN", want: tokenKindEnvironment},
1097 {source: "OAUTH_TOKEN", want: tokenKindEnvironment},
1098 {source: "/home/user/.config/glab-cli/config.yml", want: tokenKindConfigFile},
1099 {source: "", want: tokenKindConfigFile},
1102 for _, tt := range tests {
1103 t.Run(tt.source, func(t *testing.T) {
1104 assert.Equal(t, tt.want, tokenSourceKind(tt.source))
1105 assert.Equal(t, tt.want == tokenKindConfigFile, isPlaintextTokenSource(tt.source))
1106 })
Diagnostics8 git calls · 222 ms
CallStatusSizeTime0222 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 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=2
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
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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=3
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:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
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=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200358 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=358
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=5d783fac547a70b19ca138c47d067b44febb52da
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=358
git.pkt.payload.max=331
git.sideband.band1.bytes=331
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=331
git.pack.trailer=22a484e5ecad6d6e62b224e8a7f90cf5ff085938
Open pack map
fetchtree:0200138 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=138
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=b38d427eef3c1bdf03b9bb1ffc35513757d9e4fb
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=138
git.pkt.payload.max=111
git.sideband.band1.bytes=111
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=111
git.pack.trailer=22a22237517c18d88fa31b3ca9eb8b9b5bfc1afa
Open pack map
fetch2005.7 KiB207 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=207
git.response.bytes=5812
git.response.cache=MISS
git.response.duration_ms=207
git.fetch.wants=327db3ca57983550446346cdf5581673cfaaf9e2
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=5812
git.pkt.payload.max=5785
git.sideband.band1.bytes=5785
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
a5e2c1b41ab689da
Request
1a4311cb…
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