MCPcopy
hub / github.com/cli/cli / TestAuthenticatingGitCredentials

Function TestAuthenticatingGitCredentials

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

Source from the content-addressed store, hash-verified

294}
295
296func TestAuthenticatingGitCredentials(t *testing.T) {
297 // Given we have no host or global credential helpers configured
298 // And given they have chosen https as their git protocol
299 // When they choose to authenticate git with their GitHub credentials
300 // Then gh is configured as their credential helper for that host
301 ios, _, _, _ := iostreams.Test()
302
303 reg := &httpmock.Registry{}
304 defer reg.Verify(t)
305 reg.Register(
306 httpmock.REST("GET", "api/v3/"),
307 httpmock.ScopesResponder("repo,read:org"))
308 reg.Register(
309 httpmock.GraphQL(`query UserCurrent\b`),
310 httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`))
311
312 opts := &LoginOptions{
313 IO: ios,
314 Config: tinyConfig{},
315 HTTPClient: &http.Client{Transport: reg},
316 Hostname: "example.com",
317 Interactive: true,
318 GitProtocol: "https",
319 Prompter: &prompter.PrompterMock{
320 SelectFunc: func(prompt, _ string, opts []string) (int, error) {
321 if prompt == "How would you like to authenticate GitHub CLI?" {
322 return prompter.IndexFor(opts, "Paste an authentication token")
323 }
324 return -1, prompter.NoSuchPromptErr(prompt)
325 },
326 AuthTokenFunc: func() (string, error) {
327 return "ATOKEN", nil
328 },
329 },
330 CredentialFlow: &GitCredentialFlow{
331 Prompter: &prompter.PrompterMock{
332 ConfirmFunc: func(prompt string, _ bool) (bool, error) {
333 return true, nil
334 },
335 },
336 HelperConfig: &gitcredentials.FakeHelperConfig{
337 SelfExecutablePath: "/path/to/gh",
338 Helpers: map[string]gitcredentials.Helper{},
339 },
340 // Updater not required for this test as we will be setting gh as the helper
341 },
342 }
343
344 require.NoError(t, Login(opts))
345
346 helper, err := opts.CredentialFlow.HelperConfig.ConfiguredHelper("example.com")
347 require.NoError(t, err)
348 require.True(t, helper.IsOurs(), "expected gh to be the configured helper")
349}
350
351func Test_scopesSentence(t *testing.T) {
352 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