MCPcopy Create free account
hub / github.com/cli/cli / TestAuthenticatingGitCredentials

Function TestAuthenticatingGitCredentials

pkg/cmd/auth/shared/login_flow_test.go:338–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

336}
337
338func TestAuthenticatingGitCredentials(t *testing.T) {
339 // Given we have no host or global credential helpers configured
340 // And given they have chosen https as their git protocol
341 // When they choose to authenticate git with their GitHub credentials
342 // Then gh is configured as their credential helper for that host
343 ios, _, _, _ := iostreams.Test()
344
345 reg := &httpmock.Registry{}
346 defer reg.Verify(t)
347 reg.Register(
348 httpmock.REST("GET", "api/v3/"),
349 httpmock.ScopesResponder("repo,read:org"))
350 reg.Register(
351 httpmock.GraphQL(`query UserCurrent\b`),
352 httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`))
353
354 opts := &LoginOptions{
355 IO: ios,
356 Config: tinyConfig{},
357 HTTPClient: &http.Client{Transport: reg},
358 Hostname: "example.com",
359 Interactive: true,
360 GitProtocol: "https",
361 Prompter: &prompter.PrompterMock{
362 SelectFunc: func(prompt, _ string, opts []string) (int, error) {
363 if prompt == "How would you like to authenticate GitHub CLI?" {
364 return prompter.IndexFor(opts, "Paste an authentication token")
365 }
366 return -1, prompter.NoSuchPromptErr(prompt)
367 },
368 AuthTokenFunc: func() (string, error) {
369 return "ATOKEN", nil
370 },
371 },
372 CredentialFlow: &GitCredentialFlow{
373 Prompter: &prompter.PrompterMock{
374 ConfirmFunc: func(prompt string, _ bool) (bool, error) {
375 return true, nil
376 },
377 },
378 HelperConfig: &gitcredentials.FakeHelperConfig{
379 SelfExecutablePath: "/path/to/gh",
380 Helpers: map[string]gitcredentials.Helper{},
381 },
382 // Updater not required for this test as we will be setting gh as the helper
383 },
384 }
385
386 require.NoError(t, Login(opts))
387
388 helper, err := opts.CredentialFlow.HelperConfig.ConfiguredHelper("example.com")
389 require.NoError(t, err)
390 require.True(t, helper.IsOurs(), "expected gh to be the configured helper")
391}
392
393func Test_scopesSentence(t *testing.T) {
394 type args struct {

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
RegisterMethod · 0.95
TestFunction · 0.92
RESTFunction · 0.92
ScopesResponderFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
IndexForFunction · 0.92
NoSuchPromptErrFunction · 0.92
LoginFunction · 0.85
IsOursMethod · 0.80
ConfiguredHelperMethod · 0.65

Tested by

no test coverage detected