GitLabgitlab-org
cli
main
1//go:build !integration
3package login
5import (
6 "bytes"
7 "encoding/json"
8 "fmt"
9 "io"
10 "net/http"
11 "strings"
12 "testing"
13 "time"
15 "github.com/MakeNowJust/heredoc/v2"
16 "github.com/stretchr/testify/assert"
17 "github.com/stretchr/testify/require"
18 "github.com/zalando/go-keyring"
20 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
22 "gitlab.com/gitlab-org/cli/internal/api"
23 "gitlab.com/gitlab-org/cli/internal/cmdutils"
24 "gitlab.com/gitlab-org/cli/internal/config"
25 "gitlab.com/gitlab-org/cli/internal/glinstance"
26 "gitlab.com/gitlab-org/cli/internal/oauth2"
27 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
28)
30type roundTripFunc func(r *http.Request) (*http.Response, error)
32func (s roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) {
33 return s(r)
34}
36func Test_helperRun(t *testing.T) {
37 // NOTE: we have to remove the values for the possible token env variables, because it'll take precedence over the config.
38 // See config.EnvKeyEquivalence function.
39 t.Setenv("GITLAB_TOKEN", "")
40 t.Setenv("GITLAB_ACCESS_TOKEN", "")
41 t.Setenv("OAUTH_TOKEN", "")
42 t.Setenv("USER", "")
44 oauth2SuccessExpiryTime := time.Now().Add(10 * time.Minute)
45 // Expiry time resolution is down to minutes only. Truncate to a minute
46 // boundary without platform-sized integer arithmetic.
47 oauth2SuccessExpiryTime = oauth2SuccessExpiryTime.Truncate(time.Minute)
49 oauth2ApiClient := func(config config.Config, responseFunc roundTripFunc) func(repoHost string) (*api.Client, error) {
50 return func(repoHost string) (*api.Client, error) {
51 tokenSource, _ := oauth2.NewConfigTokenSource(config, &http.Client{}, glinstance.DefaultProtocol, repoHost, true)
52 if responseFunc != nil {
53 return cmdtest.NewTestAuthSourceApiClient(t, &http.Client{Transport: responseFunc}, gitlab.OAuthTokenSource{TokenSource: tokenSource}, repoHost), nil
54 }
55 return cmdtest.NewTestAuthSourceApiClient(t, nil, gitlab.OAuthTokenSource{TokenSource: tokenSource}, repoHost), nil
56 }
57 }
59 tests := []struct {
60 name string
61 opts options
62 input string
63 wantStdout []string
64 wantStderr string
65 wantErr bool
66 wantErrIs error
67 wantErrContains string
68 wantValidateErr bool
69 testOAuth2 bool
70 apiResponse roundTripFunc
71 env map[string]string
72 }{
73 {
74 name: "host only, credentials found",
75 opts: options{
76 operation: "get",
77 config: func() config.Config {
78 return config.NewFromString(heredoc.Doc(`
79 _source: "/Users/monalisa/.config/glab/config.yml"
80 hosts:
81 example.com:
82 user: "monalisa"
83 token: "some-password"
84 `))
85 },
86 },
87 input: heredoc.Doc(`
88 protocol=https
89 host=example.com
90 `),
91 wantErr: false,
92 wantValidateErr: false,
93 wantStdout: []string{
94 "username=monalisa",
95 "password=some-password",
96 },
97 wantStderr: "",
98 },
99 {
100 name: "host plus user",
101 opts: options{
102 operation: "get",
103 config: func() config.Config {
104 return config.NewFromString(heredoc.Doc(`
105 _source: "/Users/monalisa/.config/glab/config.yml"
106 hosts:
107 example.com:
108 user: "monalisa"
109 token: "some-password"
110 `))
111 },
112 },
113 input: heredoc.Doc(`
114 protocol=https
115 host=example.com
116 username=monalisa
117 `),
118 wantErr: false,
119 wantValidateErr: false,
120 wantStdout: []string{
121 "username=monalisa",
122 "password=some-password",
123 },
124 wantStderr: "",
125 },
126 {
127 name: "url input",
128 opts: options{
129 operation: "get",
130 config: func() config.Config {
131 return config.NewFromString(heredoc.Doc(`
132 _source: "/Users/monalisa/.config/glab/config.yml"
133 hosts:
134 example.com:
135 user: "monalisa"
136 token: "some-password"
137 `))
138 },
139 },
140 input: heredoc.Doc(`
141 url=https://monalisa@example.com
142 `),
143 wantErr: false,
144 wantValidateErr: false,
145 wantStdout: []string{
146 "username=monalisa",
147 "password=some-password",
148 },
149 wantStderr: "",
150 },
151 {
152 name: "host only, no credentials found",
153 opts: options{
154 operation: "get",
155 config: func() config.Config {
156 return config.NewFromString(heredoc.Doc(`
157 _source: "/Users/monalisa/.config/glab/config.yml"
158 hosts:
159 example.com:
160 user: "monalisa"
161 `))
162 },
163 },
164 input: heredoc.Doc(`
165 protocol=https
166 host=example.com
167 `),
168 wantErr: true,
169 wantErrIs: cmdutils.SilentError,
170 wantValidateErr: false,
171 wantStderr: "",
172 },
173 {
174 name: "token from env",
175 opts: options{
176 operation: "get",
177 config: func() config.Config {
178 return config.NewFromString(heredoc.Doc(`
179 _source: "GITLAB_TOKEN"
180 hosts:
181 example.com:
182 user: "clemsbot"
183 token: "some-password"
184 `))
185 },
186 },
187 input: heredoc.Doc(`
188 protocol=https
189 host=example.com
190 username=clemsbot
191 `),
192 wantErr: false,
193 wantValidateErr: false,
194 wantStdout: []string{
195 "username=clemsbot",
196 "password=some-password",
197 },
198 wantStderr: "",
199 },
200 {
201 // https://gitlab.com/gitlab-org/cli/-/issues/8044
202 name: "token only, no user on record falls back to a placeholder username",
203 opts: options{
204 operation: "get",
205 config: func() config.Config {
206 return config.NewFromString(heredoc.Doc(`
207 _source: "/Users/monalisa/.config/glab/config.yml"
208 hosts:
209 example.com:
210 token: "some-password"
211 `))
212 },
213 },
214 input: heredoc.Doc(`
215 protocol=https
216 host=example.com
217 `),
218 wantErr: false,
219 wantValidateErr: false,
220 wantStdout: []string{
221 "username=glab",
222 "password=some-password",
223 },
224 wantStderr: "",
225 },
226 {
227 name: "support OAuth2",
228 opts: options{
229 operation: "get",
230 config: func() config.Config {
231 configTemplate := heredoc.Doc(`
232 _source: "/Users/monalisa/.config/glab/config.yml"
233 hosts:
234 example.com:
235 user: "monalisa"
236 is_oauth2: "true"
237 oauth2_refresh_token: "some-refresh-token"
238 oauth2_expiry_date: %s
239 token: "some-access-token"
240 client_id: "1234567890abcdef1234567890abcdef"
241 `)
242 return config.NewFromString(fmt.Sprintf(
243 configTemplate,
244 oauth2SuccessExpiryTime.Format(time.RFC822),
245 ))
246 },
247 },
248 input: heredoc.Doc(`
249 protocol=https
250 host=example.com
251 `),
252 wantErr: false,
253 wantValidateErr: false,
254 wantStdout: []string{
255 "username=oauth2",
256 "password=some-access-token",
257 fmt.Sprintf("password_expiry_utc=%d", oauth2SuccessExpiryTime.UTC().Unix()),
258 "oauth_refresh_token=some-refresh-token",
259 },
260 wantStderr: "",
261 testOAuth2: true,
262 },
263 {
264 name: "failed to refresh",
265 opts: options{
266 operation: "get",
267 config: func() config.Config {
268 configTemplate := heredoc.Doc(`
269 _source: "/Users/monalisa/.config/glab/config.yml"
270 hosts:
271 gitlab.example.com:
272 user: "monalisa"
273 is_oauth2: "true"
274 oauth2_refresh_token: "some-refresh-token"
275 oauth2_expiry_date: %s
276 token: "some-access-token"
277 client_id: "1234567890abcdef1234567890abcdef"
278 `)
279 return config.NewFromString(fmt.Sprintf(
280 configTemplate,
281 time.Now().Add(-10*time.Minute).Format(time.RFC822),
282 ))
283 },
284 },
285 input: heredoc.Doc(`
286 protocol=https
287 host=gitlab.example.com
288 `),
289 wantErr: true,
290 wantErrContains: "failed to resolve the credentials",
291 wantValidateErr: false,
292 wantStdout: nil,
293 wantStderr: "",
294 testOAuth2: true,
295 apiResponse: func(req *http.Request) (*http.Response, error) {
296 return nil, fmt.Errorf("connection refused")
297 },
298 },
299 {
300 // Additional test case for gitlab.com, as it does not require
301 // client_id.
302 name: "failed to refresh official gitlab",
303 opts: options{
304 operation: "get",
305 config: func() config.Config {
306 configTemplate := heredoc.Doc(`
307 _source: "/Users/monalisa/.config/glab/config.yml"
308 hosts:
309 gitlab.com:
310 user: "monalisa"
311 is_oauth2: "true"
312 oauth2_refresh_token: "some-refresh-token"
313 oauth2_expiry_date: %s
314 token: "some-access-token"
315 `)
316 return config.NewFromString(fmt.Sprintf(
317 configTemplate,
318 time.Now().Add(-10*time.Minute).Format(time.RFC822),
319 ))
320 },
321 },
322 input: heredoc.Doc(`
323 protocol=https
324 host=gitlab.com
325 `),
326 wantErr: true,
327 wantErrContains: "failed to resolve the credentials",
328 wantValidateErr: false,
329 wantStdout: nil,
330 wantStderr: "",
331 testOAuth2: true,
332 apiResponse: func(req *http.Request) (*http.Response, error) {
333 type RefreshErrorResponse struct {
334 Error string `json:"error"`
335 ErrorDescription string `json:"error_description,omitempty"`
336 ErrorUri string `json:"error_uri,omitempty"`
337 }
339 responseBody, _ := json.Marshal(&RefreshErrorResponse{
340 Error: "invalid_client",
341 ErrorDescription: "Not a valid client_id",
342 })
344 response := &http.Response{
345 Proto: "HTTP/1.1",
346 Status: "400 Bad Request",
347 StatusCode: http.StatusBadRequest,
348 Body: io.NopCloser(bytes.NewBuffer(responseBody)),
349 }
350 return response, nil
351 },
352 },
353 {
354 name: "support Job Token",
355 opts: options{
356 operation: "get",
357 config: func() config.Config {
358 return config.NewFromString(heredoc.Doc(`
359 _source: "/Users/monalisa/.config/glab/config.yml"
360 hosts:
361 example.com:
362 user: "monalisa"
363 job_token: "some-job-token"
364 `))
365 },
366 },
367 input: heredoc.Doc(`
368 protocol=https
369 host=example.com
370 `),
371 wantErr: false,
372 wantValidateErr: false,
373 wantStdout: []string{
374 "username=gitlab-ci-token",
375 "password=some-job-token",
376 },
377 wantStderr: "",
378 },
379 {
380 name: "token and job token stored, token wins",
381 opts: options{
382 operation: "get",
383 config: func() config.Config {
384 return config.NewFromString(heredoc.Doc(`
385 _source: "/Users/monalisa/.config/glab/config.yml"
386 hosts:
387 example.com:
388 user: "monalisa"
389 token: "some-password"
390 job_token: "some-job-token"
391 `))
392 },
393 },
394 input: heredoc.Doc(`
395 protocol=https
396 host=example.com
397 `),
398 wantStdout: []string{
399 "username=monalisa",
400 "password=some-password",
401 },
402 },
403 {
404 name: "stored OAuth2 overridden by GITLAB_TOKEN",
405 opts: options{
406 operation: "get",
407 config: func() config.Config {
408 return config.NewFromString(heredoc.Doc(`
409 _source: "/Users/monalisa/.config/glab/config.yml"
410 hosts:
411 example.com:
412 user: "monalisa"
413 is_oauth2: "true"
414 oauth2_refresh_token: "some-refresh-token"
415 token: "some-access-token"
416 `))
417 },
418 },
419 env: map[string]string{"GITLAB_TOKEN": "env-pat"},
420 input: heredoc.Doc(`
421 protocol=https
422 host=example.com
423 `),
424 wantStdout: []string{
425 "username=monalisa",
426 "password=env-pat",
427 },
428 },
429 {
430 name: "store command",
431 opts: options{
432 operation: "store",
433 config: func() config.Config {
434 return config.NewFromString(heredoc.Doc(`
435 _source: "/Users/monalisa/.config/glab/config.yml"
436 hosts:
437 example.com:
438 user: "monalisa"
439 token: "some-password"
440 `))
441 },
442 },
443 input: heredoc.Doc(`
444 protocol=https
445 host=example.com
446 `),
447 wantErr: false,
448 wantValidateErr: true,
449 wantStdout: nil,
450 wantStderr: "",
451 },
452 {
453 name: "erase command",
454 opts: options{
455 operation: "erase",
456 config: func() config.Config {
457 return config.NewFromString(heredoc.Doc(`
458 _source: "/Users/monalisa/.config/glab/config.yml"
459 hosts:
460 example.com:
461 user: "monalisa"
462 token: "some-password"
463 `))
464 },
465 },
466 input: heredoc.Doc(`
467 protocol=https
468 host=example.com
469 `),
470 wantErr: false,
471 wantValidateErr: true,
472 wantStdout: nil,
473 wantStderr: "",
474 },
475 {
476 name: "invalid command",
477 opts: options{
478 operation: "not-a-valid-command",
479 config: func() config.Config {
480 return config.NewFromString(heredoc.Doc(`
481 _source: "/Users/monalisa/.config/glab/config.yml"
482 hosts:
483 example.com:
484 user: "monalisa"
485 token: "some-password"
486 `))
487 },
488 },
489 input: "",
490 wantErr: false,
491 wantValidateErr: true,
492 wantStdout: nil,
493 wantStderr: "",
494 },
495 }
496 for _, tt := range tests {
497 t.Run(tt.name, func(t *testing.T) {
498 for k, v := range tt.env {
499 t.Setenv(k, v)
500 }
501 if tt.testOAuth2 {
502 tt.opts.apiClient = oauth2ApiClient(tt.opts.config(), tt.apiResponse)
503 }
504 if tt.opts.apiClient == nil {
505 cfg := tt.opts.config()
506 tt.opts.apiClient = func(repoHost string) (*api.Client, error) {
507 return api.NewClientFromConfig(repoHost, cfg, false, "test")
508 }
509 }
511 io, stdin, stdout, stderr := cmdtest.TestIOStreams()
512 fmt.Fprint(stdin, tt.input)
513 opts := &tt.opts
514 opts.io = io
516 validateErr := opts.validate()
517 if tt.wantValidateErr {
518 require.Error(t, validateErr)
519 } else {
520 require.NoError(t, validateErr)
521 }
523 // No need to run if validate error is expected
524 if tt.wantValidateErr {
525 return
526 }
528 runErr := opts.run(t.Context())
529 if tt.wantErr {
530 require.Error(t, runErr)
531 if tt.wantErrIs != nil {
532 require.ErrorIs(t, runErr, tt.wantErrIs)
533 }
534 if tt.wantErrContains != "" {
535 require.ErrorContains(t, runErr, tt.wantErrContains)
536 }
537 } else {
538 require.NoError(t, runErr)
539 }
541 if tt.wantStdout != nil {
542 stdout := stdout.String()
543 assert.Truef(t, strings.HasPrefix(stdout, "capability[]=authtype\n"), "first line of stdout must always be the capability preamble")
544 t.Log(stdout)
545 for _, expectedKV := range tt.wantStdout {
546 assert.Contains(t, stdout, expectedKV)
547 }
548 }
550 if tt.wantStderr != "" {
551 assert.Equal(t, tt.wantStderr, stderr.String())
552 }
553 })
554 }
555}
557func Test_helperRun_ClientBuildErrorIsNotSilent(t *testing.T) {
558 t.Setenv("GITLAB_TOKEN", "")
559 t.Setenv("GITLAB_ACCESS_TOKEN", "")
560 t.Setenv("OAUTH_TOKEN", "")
561 keyring.MockInit()
562 t.Cleanup(keyring.MockInit)
564 // The host keeps its token in the keyring, but the keyring has no entry for it.
565 cfg := config.NewFromString(heredoc.Doc(`
566 hosts:
567 example.com:
568 user: "monalisa"
569 use_keyring: "true"
570 `))
571 io, stdin, stdout, _ := cmdtest.TestIOStreams()
572 fmt.Fprint(stdin, "protocol=https\nhost=example.com\n")
573 opts := &options{
574 io: io,
575 config: func() config.Config { return cfg },
576 operation: "get",
577 apiClient: func(repoHost string) (*api.Client, error) {
578 return api.NewClientFromConfig(repoHost, cfg, false, "test")
579 },
580 }
582 err := opts.run(t.Context())
584 require.Error(t, err)
585 require.NotErrorIs(t, err, cmdutils.SilentError)
586 require.ErrorContains(t, err, `failed to build the API client for "example.com"`)
587 require.ErrorContains(t, err, "keyring")
588 assert.Empty(t, stdout.String())
589}
591func Test_helperRun_OAuth2AccessTokenOnly(t *testing.T) {
592 t.Setenv("GITLAB_TOKEN", "")
593 t.Setenv("GITLAB_ACCESS_TOKEN", "")
594 t.Setenv("OAUTH_TOKEN", "")
596 cfg := config.NewFromString(heredoc.Doc(`
597 _source: "/Users/monalisa/.config/glab/config.yml"
598 hosts:
599 example.com:
600 user: "monalisa"
601 is_oauth2: "true"
602 token: "some-access-token"
603 oauth2_expiry_date: "2099-01-02T03:04:05Z"
604 `))
605 client, err := api.NewClientFromConfig("example.com", cfg, false, "test", api.WithoutTokenFromEnvironment())
606 require.NoError(t, err)
608 exec := cmdtest.SetupCmdForTest(
609 t,
610 NewCmdCredential,
611 false,
612 cmdtest.WithStdin("protocol=https\nhost=example.com\n\n"),
613 cmdtest.WithConfig(cfg),
614 cmdtest.WithApiClient(client),
615 )
617 out, err := exec("get")
618 require.NoError(t, err)
620 stdout := out.String()
621 assert.True(t, strings.HasPrefix(stdout, "capability[]=authtype\n"), "first line of stdout must always be the capability preamble")
622 assert.Contains(t, stdout, "username=oauth2")
623 assert.Contains(t, stdout, "password=some-access-token")
624 assert.Contains(t, stdout, fmt.Sprintf("password_expiry_utc=%d", time.Date(2099, time.January, 2, 3, 4, 5, 0, time.UTC).Unix()))
625 assert.NotContains(t, stdout, "oauth_refresh_token", "there is no refresh token to report")
626}
628func Test_remoteNameScore(t *testing.T) {
629 tests := []struct {
630 name string
631 remoteName string
632 expectedScore int
633 }{
634 {"origin gets highest score", "origin", 3},
635 {"upstream gets second highest", "upstream", 2},
636 {"gitlab gets third", "gitlab", 1},
637 {"other names get zero", "fork", 0},
638 {"case insensitive - ORIGIN", "ORIGIN", 3},
639 {"case insensitive - Upstream", "Upstream", 2},
640 }
642 for _, tt := range tests {
643 t.Run(tt.name, func(t *testing.T) {
644 score := remoteNameScore(tt.remoteName)
645 assert.Equal(t, tt.expectedScore, score)
646 })
647 }
648}
650func Test_calculateHostScore(t *testing.T) {
651 tests := []struct {
652 name string
653 host detectedHost
654 expectedScore int
655 }{
656 {
657 name: "gitlab.com with origin remote",
658 host: detectedHost{
659 hostname: "gitlab.com",
660 remotes: []string{"origin"},
661 authenticated: false,
662 },
663 expectedScore: 8, // gitlab.com bonus (5) + origin (3)
664 },
665 {
666 name: "authenticated self-hosted with origin",
667 host: detectedHost{
668 hostname: "gitlab.company.com",
669 remotes: []string{"origin"},
670 authenticated: true,
671 },
672 expectedScore: 13, // authenticated (10) + origin (3)
673 },
674 {
675 name: "multiple remotes to same host",
676 host: detectedHost{
677 hostname: "gitlab.company.com",
678 remotes: []string{"origin", "upstream"},
679 authenticated: false,
680 },
681 expectedScore: 5, // origin (3) + upstream (2)
682 },
683 {
684 name: "unknown remote name",
685 host: detectedHost{
686 hostname: "gitlab.example.com",
687 remotes: []string{"fork"},
688 authenticated: false,
689 },
690 expectedScore: 0, // fork (0)
691 },
692 }
694 for _, tt := range tests {
695 t.Run(tt.name, func(t *testing.T) {
696 score := calculateHostScore(&tt.host)
697 assert.Equal(t, tt.expectedScore, score)
698 })
699 }
700}
702func Test_prioritizeHosts(t *testing.T) {
703 tests := []struct {
704 name string
705 hosts []detectedHost
706 expectedOrder []string // Expected order of hostnames
707 }{
708 {
709 name: "authenticated host prioritized",
710 hosts: []detectedHost{
711 {hostname: "gitlab.com", remotes: []string{"fork"}, authenticated: false},
712 {hostname: "gitlab.company.com", remotes: []string{"origin"}, authenticated: true},
713 },
714 expectedOrder: []string{"gitlab.company.com", "gitlab.com"},
715 },
716 {
717 name: "origin beats upstream",
718 hosts: []detectedHost{
719 {hostname: "gitlab.upstream.com", remotes: []string{"upstream"}, authenticated: false},
720 {hostname: "gitlab.origin.com", remotes: []string{"origin"}, authenticated: false},
721 },
722 expectedOrder: []string{"gitlab.origin.com", "gitlab.upstream.com"},
723 },
724 {
725 name: "gitlab.com gets boost",
726 hosts: []detectedHost{
727 {hostname: "gitlab.example.com", remotes: []string{"origin"}, authenticated: false},
728 {hostname: "gitlab.com", remotes: []string{"fork"}, authenticated: false},
729 },
730 expectedOrder: []string{"gitlab.com", "gitlab.example.com"}, // gitlab.com bonus (5) + fork (0) = 5 > origin (3)
731 },
732 {
733 name: "multiple remotes increase score",
734 hosts: []detectedHost{
735 {hostname: "gitlab.single.com", remotes: []string{"origin"}, authenticated: false},
736 {hostname: "gitlab.multi.com", remotes: []string{"origin", "upstream"}, authenticated: false},
737 },
738 expectedOrder: []string{"gitlab.multi.com", "gitlab.single.com"},
739 },
740 }
742 for _, tt := range tests {
743 t.Run(tt.name, func(t *testing.T) {
744 sorted := prioritizeHosts(tt.hosts)
745 var actualOrder []string
746 for _, host := range sorted {
747 actualOrder = append(actualOrder, host.hostname)
748 }
749 assert.Equal(t, tt.expectedOrder, actualOrder)
750 })
751 }
752}
754func Test_detectedHost_String(t *testing.T) {
755 tests := []struct {
756 name string
757 host detectedHost
758 expected string
759 }{
760 {
761 name: "single remote, not authenticated",
762 host: detectedHost{
763 hostname: "gitlab.com",
764 remotes: []string{"origin"},
765 authenticated: false,
766 },
767 expected: "gitlab.com (origin)",
768 },
769 {
770 name: "multiple remotes, authenticated",
771 host: detectedHost{
772 hostname: "gitlab.company.com",
773 remotes: []string{"origin", "upstream"},
774 authenticated: true,
775 },
776 expected: "gitlab.company.com (origin, upstream) [authenticated]",
777 },
778 {
779 name: "remotes sorted alphabetically",
780 host: detectedHost{
781 hostname: "gitlab.example.com",
782 remotes: []string{"upstream", "fork", "origin"},
783 authenticated: false,
784 },
785 expected: "gitlab.example.com (fork, origin, upstream)",
786 },
787 {
788 name: "nil remotes, not authenticated",
789 host: detectedHost{
790 hostname: "gitlab.example.com",
791 remotes: nil,
792 authenticated: false,
793 },
794 expected: "gitlab.example.com",
795 },
796 {
797 name: "empty remotes, authenticated",
798 host: detectedHost{
799 hostname: "gitlab.company.com",
800 remotes: []string{},
801 authenticated: true,
802 },
803 expected: "gitlab.company.com [authenticated]",
804 },
805 }
807 for _, tt := range tests {
808 t.Run(tt.name, func(t *testing.T) {
809 result := tt.host.String()
810 assert.Equal(t, tt.expected, result)
811 })
812 }
813}
Diagnostics8 git calls · 245 ms
CallStatusSizeTime0245 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 KiB3 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=3 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=44Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=5 git.response.bytes=4273 git.response.cache=HIT git.response.duration_ms=5 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200358 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=358 git.response.cache=HIT git.response.duration_ms=2 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=22a484e5ecad6d6e62b224e8a7f90cf5ff085938Open pack map
fetchtree:0200281 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=281 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=c0c82a025b3ed38528b387b0c264c6de5ea513c8 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=281 git.pkt.payload.max=254 git.sideband.band1.bytes=254 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=254 git.pack.trailer=f67b2cbb934192bc54c7c67883cb789a9f00fa4aOpen pack map
fetch2004.0 KiB229 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=229 git.response.bytes=4073 git.response.cache=MISS git.response.duration_ms=229 git.fetch.wants=36552f3e395f6831f219731a154dd8887ddd4581 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=4073 git.pkt.payload.max=4046 git.sideband.band1.bytes=4046 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
- a5e2e59d3c192947
- Request
- 938fcb5e…
- 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